Skip to content

Commit aba10c0

Browse files
committed
License/formatting
1 parent f4dea01 commit aba10c0

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages-exp/auth-exp/src/core/util/event_id.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
118
import { expect } from 'chai';
219
import { _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+
});

packages-exp/auth-exp/src/core/util/event_id.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ const MAX_RANDOM_DIGITS = 15;
2020
export 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
}

0 commit comments

Comments
 (0)