https://github.com/vweevers/unique-lexicographic-integer
lexicographic-integer plus a suffix if input is the same as the last call.
https://github.com/vweevers/unique-lexicographic-integer
Last synced: about 1 year ago
JSON representation
lexicographic-integer plus a suffix if input is the same as the last call.
- Host: GitHub
- URL: https://github.com/vweevers/unique-lexicographic-integer
- Owner: vweevers
- License: mit
- Created: 2017-10-24T07:08:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-12-11T17:49:47.000Z (over 5 years ago)
- Last Synced: 2025-03-28T21:39:08.109Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1000 Bytes
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# unique-lexicographic-integer
**[`lexicographic-integer`] plus a suffix if input is the same as the last call. Hex-encoded.**
[](https://www.npmjs.org/package/unique-lexicographic-integer) [](https://www.npmjs.org/package/unique-lexicographic-integer) [](http://travis-ci.org/vweevers/unique-lexicographic-integer) [](https://ci.appveyor.com/project/vweevers/unique-lexicographic-integer) [](https://standardjs.com) [](https://david-dm.org/vweevers/unique-lexicographic-integer)
## example
```js
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 by [`lexicographic-integer-encoding`]. If true, encode will throw:
- A `TypeError` if input is not a number or if `NaN`
- A `RangeError` if input is < 0 or > `Number.MAX_SAFE_INTEGER`.
## see also
- [`lexicographic-integer`]: main encoding logic
- [`lexicographic-integer-encoding`]: encoding for `level(up)`
- [`monotonic-lexicographic-timestamp`]: `unique-lexicographic-integer` with `Date.now()` as input to get a monotonically increasing timestamp with lexicographic order.
## install
With [npm](https://npmjs.org) do:
```
npm install unique-lexicographic-integer
```
## license
[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers
[`lexicographic-integer`]: https://github.com/substack/lexicographic-integer
[`lexicographic-integer-encoding`]: https://github.com/vweevers/lexicographic-integer-encoding
[`monotonic-lexicographic-timestamp`]: https://github.com/vweevers/monotonic-lexicographic-timestamp