Skip to content

Commit

Permalink
Merge pull request #2 from ctavan/master
Browse files Browse the repository at this point in the history
Great fixes and modifications by ctavan
  • Loading branch information
pnegri committed Nov 12, 2011
2 parents a552825 + 6134ecd commit 4c48b09
Show file tree
Hide file tree
Showing 4 changed files with 405 additions and 115 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SHELL := /bin/bash

test:
@node test/uuid.js

.PHONY: test
72 changes: 43 additions & 29 deletions README.md
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>
Loading

0 comments on commit 4c48b09

Please sign in to comment.