-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ctavan/master
Great fixes and modifications by ctavan
- Loading branch information
Showing
4 changed files
with
405 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SHELL := /bin/bash | ||
|
||
test: | ||
@node test/uuid.js | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,80 @@ | ||
# UUID-js | ||
|
||
A js library to generate and parse UUID's, TimeUUID's and generate empty TimeUUID's based on TimeStamp for range selections. | ||
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'); | ||
```javascript | ||
var UUID = require('uuid-js'); | ||
|
||
var aUUID = UUID.new(); // Generate a V4 UUID | ||
var aUUID = UUID.new(); // Generate a V4 UUID | ||
|
||
console.log( aUUID.toString() ); | ||
// Prints: 896b677f-fb14-11e0-b14d-d11ca798dbac | ||
console.log( aUUID.toString() ); | ||
// Prints: 896b677f-fb14-11e0-b14d-d11ca798dbac | ||
|
||
var aTimeUUID = UUID.newTS(); // Generate a V1 TimeUUID | ||
console.log( aTimeUUID.toString() ); | ||
var aTimeUUID = UUID.newTS(); // Generate a V1 TimeUUID | ||
console.log( aTimeUUID.toString() ); | ||
|
||
var today = new Date().getTime(); | ||
var last30days = (new Date().setDate( today.getDate() - 30 )).getTime(); | ||
var today = new Date().getTime(); | ||
var last30days = (new Date().setDate( today.getDate() - 30 )).getTime(); | ||
|
||
var rangeStart = UUID.firstUUIDForTime( last30days ); | ||
var rangeEnd = UUID.lastUUIDForTime( today ); | ||
var rangeStart = UUID.firstUUIDForTime( last30days ); | ||
var rangeEnd = UUID.lastUUIDForTime( today ); | ||
|
||
// Example using cassandra | ||
var query = ...( "select first 50 reversed ?..? from user_twits where key=?", [ rangeStart, rangeEnd, "patricknegri" ]); | ||
// Example using cassandra | ||
var query = ...( "select first 50 reversed ?..? from user_twits where key=?", [ rangeStart, rangeEnd, "patricknegri" ]); | ||
``` | ||
|
||
|
||
## Instalation | ||
|
||
$ npm install uuid-js | ||
``` | ||
$ npm install uuid-js | ||
``` | ||
|
||
## Functions List | ||
|
||
These are avaiable just with require | ||
These are available just with require and return an instance of the UUID object: | ||
|
||
UUID.new(); // Generate V4 UUID | ||
```javascript | ||
UUID.new(); // Generate V4 UUID | ||
|
||
UUID.newTS(); // Generate V1 TimeUUID | ||
UUID.newTS(); // Generate V1 TimeUUID | ||
|
||
UUID.fromTime( time, last ); // Generate a V1 empty TimeUUID from a Date object (Ex: new Date().getTime() ) | ||
UUID.fromTime( time, last ); // Generate a V1 empty TimeUUID from a Date object (Ex: new Date().getTime() ) | ||
|
||
UUID.firstUUIDForTime( time ); // Same as fromTime but first sequence | ||
UUID.firstUUIDForTime( time ); // Same as fromTime but first sequence | ||
|
||
UUID.lastUUIDForTime( time ); // Same as fromTime but last sequence | ||
UUID.lastUUIDForTime( time ); // Same as fromTime but last sequence | ||
|
||
UUID.fromURN( strId ); // Generate a UUID object from string | ||
UUID.fromURN( strId ); // Generate a UUID object from string | ||
|
||
UUID.fromBytes( ints ); // Generate a UUID object from bytes | ||
UUID.fromBytes( ints ); // Generate a UUID object from bytes | ||
|
||
UUID.fromBinary( binary ); // Generate a UUID object from binary | ||
UUID.fromBinary( binary ); // Generate a UUID object from binary | ||
``` | ||
|
||
## Methods List | ||
|
||
These must be called with a instanced object. | ||
These must be called on an instance of the UUID object: | ||
|
||
aUUID.fromParts( timeLow, timeMid, timeHiAndVersion, clockSeqHiAndReserved, clockSeqLow, node ); | ||
```javascript | ||
aUUID.fromParts( timeLow, timeMid, timeHiAndVersion, clockSeqHiAndReserved, clockSeqLow, node ); | ||
|
||
aUUID.toString(); // hex string version of UUID | ||
aUUID.toString(); // hex string version of UUID | ||
|
||
aUUID.toURN(); // same as hex, but with urn:uuid prefix | ||
aUUID.toURN(); // same as hex, but with urn:uuid prefix | ||
|
||
aUUID.toBytes(); // convert to bytes | ||
aUUID.toBytes(); // convert to bytes | ||
``` | ||
|
||
## Tests | ||
|
||
``` | ||
make test | ||
``` | ||
|
||
## Contributors | ||
|
||
This work was based RFC and by the work of these people. | ||
This work was based RFC and by the work of these people. | ||
|
||
* LiosK <contact@mail.liosk.net> | ||
* Gary Dusbabek <gdusbabek@gmail.com> |
Oops, something went wrong.