@chronark/prefixed-id
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -7,4 +7,2 @@ # Changelog | ||
# [0.3.0](https://github.com/chronark/libs/compare/prefixed-id-0.2.0...prefixed-id-0.3.0) (2021-11-24) | ||
@@ -11,0 +9,0 @@ |
{ | ||
"name": "@chronark/prefixed-id", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts" | ||
"typings": "./src/index.d.ts", | ||
"dependencies": { | ||
"base-x": "^3.0.9" | ||
}, | ||
"peerDependencies": {} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encodeBase58 = void 0; | ||
const tslib_1 = require("tslib"); | ||
const base_x_1 = tslib_1.__importDefault(require("base-x")); | ||
function encodeBase58(buf) { | ||
const alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; | ||
let encoding = false; | ||
let zeroCounter = 0; | ||
const bytes = []; | ||
let carry = 0; | ||
for (let i = 0; i < buf.length; i++) { | ||
if (i > 0 && carry === 0) { | ||
break; | ||
} | ||
const byte = buf[i]; | ||
if (!encoding && byte === 0) { | ||
zeroCounter++; | ||
} | ||
if (byte !== 0) { | ||
encoding = true; | ||
} | ||
if (encoding) { | ||
carry += byte * 256; | ||
} | ||
bytes.push(carry % 58); | ||
carry = Math.floor(carry / 58); | ||
} | ||
return [ | ||
...new Array(zeroCounter).fill('1'), | ||
...bytes.map((byte) => alphabet[byte]), | ||
].join(''); | ||
return base_x_1.default(alphabet).encode(buf); | ||
} | ||
exports.encodeBase58 = encodeBase58; | ||
// export function encodeBase58(buf: Buffer): string { | ||
// const alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; | ||
// let encoding = false; | ||
// let zeroCounter = 0; | ||
// const bytes: number[] = []; | ||
// let carry = 0; | ||
// for (let i = 0; i < buf.length; i++) { | ||
// if (i > 0 && carry === 0) { | ||
// break; | ||
// } | ||
// const byte = buf[i]; | ||
// if (!encoding && byte === 0) { | ||
// zeroCounter++; | ||
// } | ||
// if (byte !== 0) { | ||
// encoding = true; | ||
// } | ||
// if (encoding) { | ||
// carry += byte * 256; | ||
// } | ||
// bytes.push(carry % 58); | ||
// carry = Math.floor(carry / 58); | ||
// } | ||
// return [ | ||
// ...new Array(zeroCounter).fill('1'), | ||
// ...bytes.map((byte) => alphabet[byte]), | ||
// ].join(''); | ||
// } | ||
//# sourceMappingURL=encoding.js.map |
@@ -38,2 +38,3 @@ "use strict"; | ||
exports.IdGenerator = IdGenerator; | ||
new IdGenerator({ user: 'u' }).id('user'); | ||
//# sourceMappingURL=prefixed-id.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6588
106
1
+ Addedbase-x@^3.0.9
+ Addedbase-x@3.0.10(transitive)
+ Addedsafe-buffer@5.2.1(transitive)