@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 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)); // 32 bytes = 256 bits
623
+ const hash = sha256(utf8ToBytes(value));
624
624
  let output = "";
625
625
  let buffer = 0;
626
626
  let bits = 0;
627
- for (let i = 0; i < hash.length && output.length < 21; i++) {
628
- buffer = (buffer << 8) | hash[i]; // push 8 bits
627
+ for (const byte of hash) {
628
+ buffer = (buffer << 8) | byte;
629
629
  bits += 8;
630
- while (bits >= 6 && output.length < 21) {
630
+ while (bits >= 6 && output.length < idTypeValueLength) {
631
631
  bits -= 6;
632
- const index = (buffer >> bits) & 0b111111; // extract top 6 bits
632
+ const index = (buffer >> bits) & 0b111111;
633
633
  output += base64UrlAlphabet[index];
634
634
  }
635
635
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evolu/common",
3
- "version": "6.0.1-preview.11",
3
+ "version": "6.0.1-preview.12",
4
4
  "description": "TypeScript library and local-first framework",
5
5
  "keywords": [
6
6
  "evolu",
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)); // 32 bytes = 256 bits
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 (let i = 0; i < hash.length && output.length < 21; i++) {
1387
- buffer = (buffer << 8) | hash[i]; // push 8 bits
1386
+ for (const byte of hash) {
1387
+ buffer = (buffer << 8) | byte;
1388
1388
  bits += 8;
1389
1389
 
1390
- while (bits >= 6 && output.length < 21) {
1390
+ while (bits >= 6 && output.length < idTypeValueLength) {
1391
1391
  bits -= 6;
1392
- const index = (buffer >> bits) & 0b111111; // extract top 6 bits
1392
+ const index = (buffer >> bits) & 0b111111;
1393
1393
  output += base64UrlAlphabet[index];
1394
1394
  }
1395
1395
  }