@evolu/common 6.0.1-preview.11 → 6.0.1-preview.12
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/dist/src/Type.js +5 -5
- package/package.json +1 -1
- package/src/Type.ts +5 -5
package/dist/src/Type.js
CHANGED
|
@@ -620,16 +620,16 @@ export const createId = (deps) => deps.nanoIdLib.nanoid();
|
|
|
620
620
|
* @category String
|
|
621
621
|
*/
|
|
622
622
|
export const createIdFromString = (value) => {
|
|
623
|
-
const hash = sha256(utf8ToBytes(value));
|
|
623
|
+
const hash = sha256(utf8ToBytes(value));
|
|
624
624
|
let output = "";
|
|
625
625
|
let buffer = 0;
|
|
626
626
|
let bits = 0;
|
|
627
|
-
for (
|
|
628
|
-
buffer = (buffer << 8) |
|
|
627
|
+
for (const byte of hash) {
|
|
628
|
+
buffer = (buffer << 8) | byte;
|
|
629
629
|
bits += 8;
|
|
630
|
-
while (bits >= 6 && output.length <
|
|
630
|
+
while (bits >= 6 && output.length < idTypeValueLength) {
|
|
631
631
|
bits -= 6;
|
|
632
|
-
const index = (buffer >> bits) & 0b111111;
|
|
632
|
+
const index = (buffer >> bits) & 0b111111;
|
|
633
633
|
output += base64UrlAlphabet[index];
|
|
634
634
|
}
|
|
635
635
|
}
|
package/package.json
CHANGED
package/src/Type.ts
CHANGED
|
@@ -1377,19 +1377,19 @@ export const createId = <B extends string = never>(
|
|
|
1377
1377
|
export const createIdFromString = <B extends string = never>(
|
|
1378
1378
|
value: string,
|
|
1379
1379
|
): [B] extends [never] ? Id : Id & Brand<B> => {
|
|
1380
|
-
const hash = sha256(utf8ToBytes(value));
|
|
1380
|
+
const hash = sha256(utf8ToBytes(value));
|
|
1381
1381
|
|
|
1382
1382
|
let output = "";
|
|
1383
1383
|
let buffer = 0;
|
|
1384
1384
|
let bits = 0;
|
|
1385
1385
|
|
|
1386
|
-
for (
|
|
1387
|
-
buffer = (buffer << 8) |
|
|
1386
|
+
for (const byte of hash) {
|
|
1387
|
+
buffer = (buffer << 8) | byte;
|
|
1388
1388
|
bits += 8;
|
|
1389
1389
|
|
|
1390
|
-
while (bits >= 6 && output.length <
|
|
1390
|
+
while (bits >= 6 && output.length < idTypeValueLength) {
|
|
1391
1391
|
bits -= 6;
|
|
1392
|
-
const index = (buffer >> bits) & 0b111111;
|
|
1392
|
+
const index = (buffer >> bits) & 0b111111;
|
|
1393
1393
|
output += base64UrlAlphabet[index];
|
|
1394
1394
|
}
|
|
1395
1395
|
}
|