Skip to content

Commit

Permalink
Merge pull request #4 from kibertoad/update-uuid
Browse files Browse the repository at this point in the history
chore: upgrade uuid to ^3.2.1
  • Loading branch information
djmitche authored May 7, 2018
2 parents a5279ba + fab49ff commit 892df99
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
package-lock.json
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "node"
- "10"
- "8"
- "6"
- "4"

# encrpyt channel name to get around issue
# https://github.com/travis-ci/travis-ci/issues/1094
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "slugid",
"version": "1.1.0",
"author": "Jonas Finnemann Jensen <jopsen@gmail.com>",
"description": "URL-safe base64 UUID encoder for generating 22 character slugs",
"license": "MIT",
"name": "slugid",
"version": "2.0.0",
"author": "Jonas Finnemann Jensen <jopsen@gmail.com>",
"description": "URL-safe base64 UUID encoder for generating 22 character slugs",
"license": "MIT",
"scripts": {
"test": "nodeunit slugid_test.js"
"test": "nodeunit slugid_test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/taskcluster/slugid.git"
"type": "git",
"url": "https://github.com/taskcluster/slugid.git"
},
"dependencies": {
"uuid": "^2.0.1"
"uuid": "^3.2.1",
"uuid-parse": "^1.0.0"
},
"devDependencies": {
"nodeunit": "0.8.6",
"browserify": "5.9.1"
"nodeunit": "^0.11.2",
"browserify": "5.9.1"
}
}
13 changes: 7 additions & 6 deletions slugid.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

var uuid = require('uuid');
var uuidv4 = require('uuid/v4');
var uuidParse = require('uuid-parse');

/**
* Returns the given uuid as a 22 character slug. This can be a regular v4
* slug or a "nice" slug.
*/
exports.encode = function(uuid_) {
var bytes = uuid.parse(uuid_);
var bytes = uuidParse.parse(uuid_);
var base64 = (new Buffer(bytes)).toString('base64');
var slug = base64
.replace(/\+/g, '-') // Replace + with - (see RFC 4648, sec. 5)
Expand All @@ -44,14 +45,14 @@ exports.decode = function(slug) {
.replace(/-/g, '+')
.replace(/_/g, '/')
+ '==';
return uuid.unparse(new Buffer(base64, 'base64'));
return uuidParse.unparse(new Buffer(base64, 'base64'));
};

/**
* Returns a randomly generated uuid v4 compliant slug
*/
exports.v4 = function() {
var bytes = uuid.v4(null, new Buffer(16));
var bytes = uuidv4(null, new Buffer(16));
var base64 = bytes.toString('base64');
var slug = base64
.replace(/\+/g, '-') // Replace + with - (see RFC 4648, sec. 5)
Expand All @@ -60,7 +61,7 @@ exports.v4 = function() {
return slug;
};

/**
/**
* Returns a randomly generated uuid v4 compliant slug which conforms to a set
* of "nice" properties, at the cost of some entropy. Currently this means one
* extra fixed bit (the first bit of the uuid is set to 0) which guarantees the
Expand All @@ -72,7 +73,7 @@ exports.v4 = function() {
* restrict the range of potential uuids that may be generated.
*/
exports.nice = function() {
var bytes = uuid.v4(null, new Buffer(16));
var bytes = uuidv4(null, new Buffer(16));
bytes[0] = bytes[0] & 0x7f; // unset first bit to ensure [A-Za-f] first char
var base64 = bytes.toString('base64');
var slug = base64
Expand Down
6 changes: 3 additions & 3 deletions slugid_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

var slugid = require('./slugid');
var uuid = require('uuid');
var slugid = require('./slugid');
var uuidv4 = require('uuid/v4');

/**
* Test that we can correctly encode a "non-nice" uuid (with first bit set) to
Expand Down Expand Up @@ -76,7 +76,7 @@ exports.uuidEncodeDecodeTest = function(test) {

for (i = 0; i < 100; i++) {
// Generate uuid
var uuid_ = uuid.v4();
var uuid_ = uuidv4();

// Encode
var slug = slugid.encode(uuid_);
Expand Down

0 comments on commit 892df99

Please sign in to comment.