package
The idea of this project is make your details route easier 🥰 ..
npm install short-objectidGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
13.0 kB
Includes dependencies.
The idea of this module is make your route easier ⚡ when you work with mongodb object-ids 🗜🚀 ..
Warning ⚠️: Previous versions are deprecated. For that the first release is 5.0.0-rc 👻.
Installation# npm ..
$ npm install short-objectid
# yarn ..
$ yarn add short-objectidAPICaution 🚨: Be careful when you use
shortObjectIdCache. All cache hooks are not stable outside the function.
shortObjectId — helps you to compress your ObjectId and make it short.shortObjectIdCache — A predictable cache container instance, helps you When you pass
cache: trueinside the options object, you don't need to use
shortObjectIdCachebecause it works on the background.
UsageThis is a practical example of how to use.
// you can also use the desctructure way ..
const shortObjectId = require ('short-objectid');
// objectId <required> ..
let mongodbObjectId = { "$oid" : "507f191e810c19729de860ea" };
// config object <optional> ..
let config = { Timestamp: 57, MachineId: 65, ProcessId: 48, Counter: 47 };
// options object <optional> ..
// you can pass one of these options [cache, keepOriginal] ..
// cache option, informs the shortObjectId function that you
// should subscribe to each call and then store all data ..
let opts = { cache: true };
// Now you have access to 2 hooks (only with cache opts)
// + getShortObjectId(fullObjectId: string): number
// + getFullObjectId(shortObjectId: number): string
You can play around with it on this sandbox example codesandbox.io/short-objectid using
Express JSandMongoose🙌🏻.