zandaqo / objectid64 Goto Github PK
View Code? Open in Web Editor NEWThe fastest way to convert UUID, MongoDB ObjectID, and serial ids into shorter, URL-friendly base64 and vice versa.
License: MIT License
The fastest way to convert UUID, MongoDB ObjectID, and serial ids into shorter, URL-friendly base64 and vice versa.
License: MIT License
Maybe I'm doing something wrong but I can't get a UUID -> encrypt -> encode -> decode -> decrypt -> UUID flow working.
import crypto from 'crypto'
import {Encoder, Encrypter} from 'objectid64'
global.crypto = crypto.webcrypto
const encoder = new Encoder()
const key = await Encrypter.generateKey()
const encrypter = new Encrypter(key)
const uuid = crypto.randomUUID()
console.log(uuid) // 4874c42f-61e3-42c8-9a39-4007a81737e7
const binUuid = encoder.toBinUUID(uuid)
const encrypted = await encrypter.fromUUID(binUuid)
const encoded = encoder.fromBinUUID(encrypted)
console.log(encoded) // MxbKSQB-fuDtqUJayvuVCO
const decoded = encoder.toBinUUID(encoded)
const decrypted = await encrypter.toUUID(decoded)
const uuid2 = encoder.fromBinUUID(decrypted)
console.log(uuid2) // 4874c42f-61e3-42c8-9C3, uuid is not recovered in full
console.log(uuid === uuid2) // false
Node.js version: 16.17.1
objectid64 version: 3.2.1
Current test seems not comprehensive enough.
Maybe add a test to create 100,000 random objectid and test encode/decode with them.
I get this error attempting to use this package with Node.js v18.14.0.
node:internal/modules/cjs/loader:544
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/joe/repos/fieldzoo/libs/database/node_modules/objectid64/package.json
at new NodeError (node:internal/errors:399:5)
at exportsNotFound (node:internal/modules/esm/resolve:361:10)
at packageExportsResolve (node:internal/modules/esm/resolve:641:13)
at resolveExports (node:internal/modules/cjs/loader:538:36)
at Module._findPath (node:internal/modules/cjs/loader:607:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1033:27)
at Module._load (node:internal/modules/cjs/loader:893:27)
at Module.require (node:internal/modules/cjs/loader:1113:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/Users/joe/repos/fieldzoo/libs/database/dist/lib/id-encoder.js:27:33) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
This is the entire program:
import { Encoder } from "objectid64";
import { randomUUID } from "crypto";
export const idEncoder = new Encoder();
console.log(idEncoder.fromUUID(randomUUID()));
Hi Maga,
thanks for you great work! Unfortunately in some envs it is not possible to control the ES Version, so in my case i needed to comply with ES6. I have forked and adapted your lib (https://github.com/kaeferfreund/oid64) to work with ES6.
Maybe there is a way to incorporate my changes upstream to a version that is compatible with different ES versions?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.