unique-lexicographic-integer
v1.0.0
Published
lexicographic-integer plus a suffix if input is the same as the last call
Downloads
19
Readme
unique-lexicographic-integer
lexicographic-integer
plus a suffix if input is the same as the last call. Hex-encoded.
example
const uli = require('unique-lexicographic-integer')
const encode = uli()
console.log(encode(0)) // '00'
console.log(encode(0)) // '00.01'
console.log(encode(1)) // '01'
console.log(encode(300)) // 'fb31'
console.log(encode(300)) // 'fb31.01'
console.log(encode(300)) // 'fb31.02'
const strict = uli({ strict: true })
try {
strict('1')
} catch (err) {
console.log(err.message) // 'Argument must be a valid number'
}
api
encode = require('unique-lexicographic-integer')([options])
options.separator
(string): defaults to'.'
options.strict
(boolean): opt-in to type-checking input. Handled bylexicographic-integer-encoding
. If true, encode will throw:- A
TypeError
if input is not a number or ifNaN
- A
RangeError
if input is < 0 or >Number.MAX_SAFE_INTEGER
.
- A
see also
lexicographic-integer
: main encoding logiclexicographic-integer-encoding
: encoding forlevel(up)
monotonic-lexicographic-timestamp
:unique-lexicographic-integer
withDate.now()
as input to get a monotonically increasing timestamp with lexicographic order.
install
With npm do:
npm install unique-lexicographic-integer
license
MIT © Vincent Weevers