1.1.2 • Published 7 years ago

cuid-plus v1.1.2

Weekly downloads
30
License
ISC
Repository
github
Last release
7 years ago

cuid-plus

cuid add-on functions.

getTimestamp(id) Returns the timestamp portion of the cuid ids as a Date.

isValid(id) Returns true if the value is a valid cuid ids, return false otherwise.

The id param is considered valid if the following are met:

  • 25 characters long
  • Starts with the "c" prefix identifier

See the cuid breakdown for details.

Installing

$ npm install cuid-plus --save

Example

var cuid = require("cuid"),
    cuidplus = require("cuid-plus");

var ids = cuid();
console.log(ids);
// OUTPUT: ch72gsb320000udocl363eofy

// Get timestamp from id
var timestamp = cuidplus.getTimestamp(ids);
console.log(timestamp);
// OUTPUT: Fri Sep 14 2012 07:03:12 GMT+0800 (PHT)

// Check if ids is valid
if (!cuidplus.isValid(ids)) {
    console.log("Invalid IDs");
}
...

Test

$ cd cuid-plus
$ npm install
$ test

Credit

1.1.2

7 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago