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+
118import { expect } from 'chai' ;
219import { _generateEventId } from './event_id' ;
320
@@ -13,4 +30,4 @@ describe('core/util/event_id', () => {
1330 it ( 'above-15 digit id' , ( ) => {
1431 expect ( _generateEventId ( '' , 20 ) ) . to . have . length ( 20 ) ;
1532 } ) ;
16- } ) ;
33+ } ) ;
Original file line number Diff line number Diff line change @@ -20,11 +20,19 @@ const MAX_RANDOM_DIGITS = 15;
2020export function _generateEventId ( prefix = '' , digits = 10 ) : string {
2121 // This array breaks down digits into a list of numbers, maxed at 15, that
2222 // 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+ ) ;
2426 if ( digits % MAX_RANDOM_DIGITS ) {
2527 digitBreakdown . push ( digits % MAX_RANDOM_DIGITS ) ;
2628 }
2729
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 ( '' ) ;
2937 return prefix + random ;
3038}
You can’t perform that action at this time.
0 commit comments