diff --git a/.gitignore b/.gitignore index c2658d7..504afef 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +package-lock.json diff --git a/.travis.yml b/.travis.yml index 23d5b26..226ee1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package.json b/package.json index 679e9e9..062d709 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,22 @@ { - "name": "slugid", - "version": "1.1.0", - "author": "Jonas Finnemann Jensen ", - "description": "URL-safe base64 UUID encoder for generating 22 character slugs", - "license": "MIT", + "name": "slugid", + "version": "2.0.0", + "author": "Jonas Finnemann Jensen ", + "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" } } diff --git a/slugid.js b/slugid.js index 1705c89..e7dbc49 100644 --- a/slugid.js +++ b/slugid.js @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/slugid_test.js b/slugid_test.js index 735eef0..196f8fd 100644 --- a/slugid_test.js +++ b/slugid_test.js @@ -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 @@ -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_);