File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
packages-exp/auth-exp/src/core/util Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
1
18
import { expect } from 'chai' ;
2
19
import { _generateEventId } from './event_id' ;
3
20
@@ -13,4 +30,4 @@ describe('core/util/event_id', () => {
13
30
it ( 'above-15 digit id' , ( ) => {
14
31
expect ( _generateEventId ( '' , 20 ) ) . to . have . length ( 20 ) ;
15
32
} ) ;
16
- } ) ;
33
+ } ) ;
Original file line number Diff line number Diff line change @@ -20,11 +20,19 @@ const MAX_RANDOM_DIGITS = 15;
20
20
export function _generateEventId ( prefix = '' , digits = 10 ) : string {
21
21
// This array breaks down digits into a list of numbers, maxed at 15, that
22
22
// sums to digits. For example, 10 becomes [10] and 16 becomes [15, 1].
23
- const digitBreakdown = Array ( Math . floor ( digits / MAX_RANDOM_DIGITS ) ) . fill ( MAX_RANDOM_DIGITS ) ;
23
+ const digitBreakdown = Array ( Math . floor ( digits / MAX_RANDOM_DIGITS ) ) . fill (
24
+ MAX_RANDOM_DIGITS
25
+ ) ;
24
26
if ( digits % MAX_RANDOM_DIGITS ) {
25
27
digitBreakdown . push ( digits % MAX_RANDOM_DIGITS ) ;
26
28
}
27
29
28
- const random = digitBreakdown . map ( digits => Math . floor ( Math . random ( ) * Math . pow ( 10 , digits ) ) . toString ( ) . padStart ( digits , '0' ) ) . join ( '' ) ;
30
+ const random = digitBreakdown
31
+ . map ( digits =>
32
+ Math . floor ( Math . random ( ) * Math . pow ( 10 , digits ) )
33
+ . toString ( )
34
+ . padStart ( digits , '0' )
35
+ )
36
+ . join ( '' ) ;
29
37
return prefix + random ;
30
38
}
You can’t perform that action at this time.
0 commit comments