@aia-irecruit/ui-library 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/index.js +21 -0
- package/package.json +16 -0
- package/scripts/postinstall.js +8 -0
- package/scripts/preinstall.js +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @aia-irecruit/ui-library
|
|
2
|
+
|
|
3
|
+
Generate short unique IDs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @aia-irecruit/ui-library
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const uid = require('@aia-irecruit/ui-library');
|
|
15
|
+
|
|
16
|
+
uid() // => 'a8xk2nHf9Lpq'
|
|
17
|
+
uid(6) // => 'k9Mx2a'
|
|
18
|
+
uid(21) // => 'a8xk2nHf9LpqZ3mNc7yRb'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate a short unique ID
|
|
7
|
+
* @param {number} length - Length of the ID (default: 12)
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
function uid(length) {
|
|
11
|
+
length = length || 12;
|
|
12
|
+
let id = '';
|
|
13
|
+
for (let i = 0; i < length; i++) {
|
|
14
|
+
id += ALPHABET[Math.floor(Math.random() * ALPHABET.length)];
|
|
15
|
+
}
|
|
16
|
+
return id;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = uid;
|
|
20
|
+
module.exports.uid = uid;
|
|
21
|
+
module.exports.default = uid;
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aia-irecruit/ui-library",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate short unique IDs",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"preinstall": "node scripts/preinstall.js",
|
|
8
|
+
"postinstall": "node scripts/postinstall.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": ["uid", "unique", "id", "generator"],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=10"
|
|
15
|
+
}
|
|
16
|
+
}
|