<|start_filename|>index.js<|end_filename|>
'use strict';

var uuid = require('uuid');

module.exports = {
  generate: function() {
    var unordered = uuid.v1();
    return unordered.substr(14, 4) + unordered.substr(9, 4) + unordered.substr(0, 8) + unordered.substr(19, 4) + unordered.substr(24, unordered.length);
  },

  toBinary16: function(orderedUuid) {
    return new Buffer(orderedUuid, 'hex');
  },

  fromBinary16: function(binaryOrderedUuid) {
    return binaryOrderedUuid.toString('hex');
  }
};


<|start_filename|>package.json<|end_filename|>
{
  "name": "ordered-uuid",
  "version": "1.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "coverage": "istanbul cover --report html node_modules/.bin/_mocha -- -R spec",
    "test": "mocha test"
  },
  "author": "<NAME>",
  "license": "MIT",
  "dependencies": {
    "uuid": "^3.0.1"
  },
  "bugs": {
    "url": "https://github.com/peterkingsbury/ordered-uuid/issues",
    "email": "<EMAIL>"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/peterkingsbury/ordered-uuid"
  },
  "devDependencies": {
    "istanbul": "^0.4.5",
    "mocha": "^3.2.0",
    "should": "^11.2.0"
  }
}


<|start_filename|>test/orderedUuid.js<|end_filename|>
'use strict';

const should = require('should');

describe('Ordered UUID Tests', function() {
	before(function() {});
	after(function() {});

	it('should be able to load the Ordered UUID library', function() {
		const OrderedUuid = require('../index');
	});

	it('should be able to generate an ordered UUID', function() {
		const OrderedUuid = require('../index');
		let uuid = OrderedUuid.generate();
		should(uuid.length).equal(32);
	});

	it('should be able to convert a UUID string to a Binary buffer', function() {
		const OrderedUuid = require('../index');
                let uuid = OrderedUuid.generate();
		let buffer = OrderedUuid.toBinary16(uuid);
		should(typeof buffer).equal('object');
		should(buffer.toString('hex')).equal(uuid);
	});

        it('should be able to convert a Binary-buffer UUID to a string', function() {
                const OrderedUuid = require('../index');
                let uuid = OrderedUuid.generate();
                let buffer = OrderedUuid.toBinary16(uuid);
		let str = OrderedUuid.fromBinary16(buffer);
                should(str).equal(uuid);
        });


});

