0.7.5 • Published 10 years ago

uuid-js v0.7.5

Weekly downloads
104,359
License
-
Repository
github
Last release
10 years ago

UUID-js

A js library to generate and parse UUID's, TimeUUID's and generate empty TimeUUID's based on TimeStamp for range selections.

var UUID = require('uuid-js');


// Generate a V4 UUID
var uuid4 = UUID.create();
console.log(uuid4.toString());
// Prints: 896b677f-fb14-11e0-b14d-d11ca798dbac


// Generate a V1 TimeUUID
var uuid1 = UUID.create(1);
console.log(uuid1.toString());


// First and last possible v1 TimeUUID for a given timestamp:
var date = new Date().getTime();
var uuidFirst = UUID.fromTime(date, false);
var uuidLast = UUID.fromTime(date, true);
console.log(uuidFirst.toString(), uuidLast.toString());
// Prints: aa0f9af0-0e1f-11e1-0000-000000000000 aa0f9af0-0e1f-11e1-c0ff-ffffffffffff


// Use these TimeUUID's to perform range queries in cassandra:
var today = new Date().getTime();
var last30days = (new Date().setDate( today.getDate() - 30 )).getTime();

var rangeStart = UUID.firstFromTime(last30days);
var rangeEnd = UUID.lastFromTime(today);

var query = ...("select first 50 reversed ?..? from user_twits where key=?", [ rangeStart, rangeEnd, "patricknegri" ]);

Instalation

$ npm install uuid-js

Functions List

These are available just with require and return an instance of the UUID object:

UUID.create(4); // Generate V4 UUID

UUID.create(1); // Generate V1 TimeUUID

UUID.fromTime(time, last); // Generate a V1 empty TimeUUID from a Date object (Ex: new Date().getTime() )

UUID.firstFromTime(time); // Same as fromTime but first sequence

UUID.lastFromTime(time); // Same as fromTime but last sequence

UUID.fromURN(strId); // Generate a UUID object from string

UUID.fromBytes(ints); // Generate a UUID object from bytes

UUID.fromBinary(binary); // Generate a UUID object from binary

Methods List

These must be called on an instance of the UUID object:

uuid.fromParts(timeLow, timeMid, timeHiAndVersion, clockSeqHiAndReserved, clockSeqLow, node);

uuid.toString(); // hex string version of UUID

uuid.toURN(); // same as hex, but with urn:uuid prefix

uuid.toBytes(); // converted to an array of bytes

Tests

make test

Contributors

This work was based RFC and by the work of these people.

crcloud-components-webcrcloud-portal-framecrcloud-slb-webgc-http-client@netinsight/clearkey-serverwatch-copy@srag/pdf-wrap@wildanalytics/wild-analytics@wildanalytics/wild-analytics-betareact-draggable-tsrn-pdf-reader-offlineant-nodejs-kit@everything-registry/sub-chunk-3034jmshiink-jskronos-messagekuben-appium-ios-driverkuben-appium-xcuitest-driverlifetrackerdryduckfh-wfm-filefh-wfm-file-angularexpo-torqexponentexpo-domgateraidocpp-jspawpymyscriptnpm2archnode-bits-adminmx-appium-base-driverpush-rpcrb-sdkpsocket.iopsocket.io-clientreact-native-foragereact-native-forage-betarxfluxtrv-expotypescript-push-rpctumblr.rn.jssilver-bulletsimpatoaste@neuqsoft/commons-util@push-rpc/core@push-rpc/http@elie222/ex-navigation@expo/ex-navigation@exponent/ex-navigation@raincatcher/step-gallery@nsrd/neuq-request@nsrd/neuq-request-js@nsrd/nus@safeguard-apis/sg-device@resyin/mewvadr-core-vr@miriamjs/wml@londoner/appium-base-driver@ithinkdt/websocket-sdk@infinitebrahmanuniverse/nolb-uusilver-mousesimplerabbit.js@raydeck/wmlwatchwomanwatchwomenwcpwinston-simpledbwlinkwmlwmls@jsierles/ex-navigation@kfox/expo@hexxeh/appium@aibee/bmap@textback/notification-widget@aurelia-material-components/core@auto.pro/core@auto.pro/floaty@auto.pro/webviewamaranth-utilsbaqiappiumx-base-driverappium-youi-driverappium-base-driver-how-to-add-handlerappium-base-driver-plusappium-base-driver-testappium-base-driver-test-1appium-instruments-xcode-6appium-ios-driver-conanappium-ios-driver-multisimconnect-uuidconan-appium-ios-driverct-adc-popperdash-js
0.7.5

10 years ago

0.7.4

12 years ago

0.7.3

12 years ago

0.7.2

12 years ago

0.7.1

12 years ago

0.7.0

12 years ago

0.5.4

12 years ago

0.5.3

12 years ago

0.5.2

12 years ago

0.5.1

12 years ago

0.5.0

12 years ago