1.0.0 • Published 8 years ago
monotonic-lexicographic-timestamp v1.0.0
monotonic-lexicographic-timestamp
Monotonically increasing timestamp with lexicographic order. Simply adds a suffix if time is the same as the last call. Hex-encoded.
example
const mlts = require('monotonic-lexicographic-timestamp')()
// You can provide your own date or timestamp
console.log(mlts(new Date(0))) // '00'
console.log(mlts(0)) // '00.01'
// Otherwise it'll use Date.now()
console.log(mlts())
console.log(mlts())
const custom = require('monotonic-lexicographic-timestamp')({
separator: '!'
})
console.log(custom(1508832007017)) // 'ff080afa6b2a9370'
console.log(custom(1508832007017)) // 'ff080afa6b2a9370!01'
console.log(custom(1508832007017)) // 'ff080afa6b2a9370!02'
console.log(custom(1508832007018)) // 'ff080afa6b2a9378'api
mlts = require('monotonic-lexicographic-timestamp')([options])
Options are passed to unique-lexicographic-integer:
options.separator(string): defaults to'.'options.strict(boolean): opt-in to type-checking input. If true,mlts()will throw:- A
TypeErrorif input is not a number or ifNaN - A
RangeErrorif input is < 0 or >Number.MAX_SAFE_INTEGER.
- A
see also
monotonic-timestamp: if you want floatsmonotonic-timestamp-base36: if you want to save byteslexicographic-integer: main encoding logiclexicographic-integer-encoding: encoding forlevel(up)unique-lexicographic-integer:lexicographic-integerplus a suffix if input is the same as the last call.
install
With npm do:
npm install monotonic-lexicographic-timestamplicense
MIT © Vincent Weevers
1.0.0
8 years ago