node-unique

1.1.0 • Public • Published

unique

Unique generates IDs, that is all. The IDs that are generated have the following properties.

  • Portable - Unique generates String IDs so they can be used anywhere.
  • Compact - Unique Base64 encodes IDs to minimize wasted space.
  • Timely - Unique includes a timestamp to the millisecond in its IDs.
  • Orderly - Unique IDs are lexicographically ordered by time.
  • Random - Unique includes 122 random bits in its IDs.

Definition: base64(bin(hex(now()) + uuidV4()))

Where:

  • now() returns an integer representing milliseconds since epoch
  • uuidV4() returns a 32 character hex string (no dashes)

API

unique([ts]) - Generates a new id.

ts: Date (Optional)

  • Description: A date representing the timestamp you want encoded into your ID.
  • Default: Now.

unique.getTimestamp(id) - Returns the timestamp encoded in the given id.

id: String

  • Description: An id to extract the timestamp from.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    83
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    83
  • 1.0.0
    0

Package Sidebar

Install

npm i node-unique

Weekly Downloads

70

Version

1.1.0

License

ISC

Last publish

Collaborators

  • tleef