OpaqueID
A basic opaque ID generator with support for types and metadata.
Install
Opaque ID runs on Node.js and is available as a NPM package. It can be installed as a normal NPM package:
$ npm install opaqueid
Or using yarn:
$ yarn add opaqueid
Usage
; // Encode an IDencodeId'46Juzcyx';// => "fDQ2SnV6Y3l4" // Encode an ID with a typeencodeId'45745c60-7b1a-11e8-9c9c-2d42b21b1a3e', 'User';// => "VXNlcnw0NTc0NWM2MC03YjFhLTExZTgtOWM5Yy0yZDQyYjIxYjFhM2U=" // Encode a numeric IDencodeId1234;// => "fDEyMzQ=" // Encode a numeric ID with a typeencodeId1234, 'Book';// => "Qm9va3wxMjM0" // Encode an ID with metadataencodeId2, 'Device', );// => "RGV2aWNlfDJ8eyJ0eXBlIjoiVEVMRVZJU0lPTiJ9" // Decode an ID// => 1234 // Decode an ID with an expected type;// Error: Expected Book ID, got Device ID // Get the ID's type;// => "User" // Get the ID's metadata;// => { type: 'TELEVISION' }
Testing
$ npm test
Licence
Copyright (c) 2020 Kirk Brauer.
Released under the MIT license.