b64id 1.0.0 → 1.1.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/.claude/settings.local.json +7 -0
- package/index.js +14 -8
- package/package.json +2 -6
package/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
const base64 = require('base64-url');
|
|
2
|
-
const uuidv4 = require('uuid/v4');
|
|
3
|
-
|
|
4
1
|
function uuidToB64(uuidStr) {
|
|
5
|
-
const
|
|
6
|
-
|
|
2
|
+
const hex = uuidStr.replace(/-/g, '');
|
|
3
|
+
const bytes = new Uint8Array(16);
|
|
4
|
+
for (let i = 0; i < 16; i++) {
|
|
5
|
+
bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
6
|
+
}
|
|
7
|
+
return btoa(String.fromCharCode(...bytes))
|
|
8
|
+
.replace(/\+/g, '-')
|
|
9
|
+
.replace(/\//g, '_')
|
|
10
|
+
.replace(/=+$/, '');
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
function b64ToUuid(b64Str) {
|
|
10
|
-
const
|
|
11
|
-
|
|
14
|
+
const base64 = b64Str.replace(/-/g, '+').replace(/_/g, '/');
|
|
15
|
+
const binary = atob(base64);
|
|
16
|
+
const hex = [...binary].map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join('');
|
|
17
|
+
return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
function generateId() {
|
|
15
|
-
return uuidToB64(
|
|
21
|
+
return uuidToB64(crypto.randomUUID());
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "b64id",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "url-safe 128-bit UUID strings expressed in base-64 encoding",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,13 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"author": "Luis Montes",
|
|
21
21
|
"license": "ISC",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"base64-url": "^2.2.0",
|
|
24
|
-
"uuid": "^3.3.2"
|
|
25
|
-
},
|
|
26
22
|
"devDependencies": {
|
|
27
23
|
"chai": "^4.2.0",
|
|
28
24
|
"istanbul": "^0.4.5",
|
|
29
|
-
"mocha": "^
|
|
25
|
+
"mocha": "^10.2.0"
|
|
30
26
|
}
|
|
31
27
|
}
|