1 | import _typeof from 'babel-runtime/helpers/typeof';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export function randomId(prefix) {
|
10 | var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000000;
|
11 |
|
12 | var rand = Math.ceil(Math.random() * max);
|
13 |
|
14 | return prefix ? escapeForId(prefix) + '-' + rand : rand.toString(10);
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export function escapeForId(text) {
|
24 | if (!text) {
|
25 | return '';
|
26 | }
|
27 |
|
28 | if ((typeof text === 'undefined' ? 'undefined' : _typeof(text)) === 'object') {
|
29 | text = JSON.stringify(text);
|
30 | } else if (typeof text !== 'string') {
|
31 | text = String(text);
|
32 | }
|
33 |
|
34 | return text.replace(/['"]/gm, '').replace(/[\s'"]/gm, '-');
|
35 | } |
\ | No newline at end of file |