Skip to content

Commit 6357c5b

Browse files
author
Tyler Garlick
committed
Initial Setup
1 parent 2158379 commit 6357c5b

File tree

5 files changed

+3278
-1
lines changed

5 files changed

+3278
-1
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["pundits"]
3+
}

package.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Simple UUID generation",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha test"
7+
"test": "mocha test",
8+
"build": "babel src -d build --source-maps inline"
89
},
910
"repository": {
1011
"type": "git",
@@ -21,8 +22,31 @@
2122
},
2223
"homepage": "https://github.com/TylerGarlick/simple-uuid",
2324
"devDependencies": {
25+
"ava": "^0.19.1",
26+
"babel-cli": "^6.24.1",
27+
"babel-polyfill": "^6.23.0",
28+
"babel-preset-pundits": "^2.0.3",
29+
"babel-register": "^6.24.1",
2430
"chai": "^1.10.0",
2531
"lodash": "^2.4.1",
2632
"mocha": "^2.1.0"
33+
},
34+
"ava": {
35+
"files": [
36+
"test/**/*.test.js"
37+
],
38+
"source": [
39+
"**/*.{js,jsx}",
40+
"!dist/**/*"
41+
],
42+
"concurrency": 5,
43+
"failFast": true,
44+
"failWithoutAssertions": false,
45+
"tap": true,
46+
"powerAssert": false,
47+
"require": [
48+
"babel-register"
49+
],
50+
"babel": "inherit"
2751
}
2852
}

src/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Generate a UUID
3+
* @returns {string}
4+
*/
5+
export default () => {
6+
const lut = [];
7+
for (let i = 0; i < 256; i++) {
8+
lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
9+
}
10+
11+
const d0 = Math.random() * 0xffffffff | 0;
12+
const d1 = Math.random() * 0xffffffff | 0;
13+
const d2 = Math.random() * 0xffffffff | 0;
14+
const d3 = Math.random() * 0xffffffff | 0;
15+
16+
return lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff] + '-' +
17+
lut[d1 & 0xff] + lut[d1 >> 8 & 0xff] + '-' + lut[d1 >> 16 & 0x0f | 0x40] + lut[d1 >> 24 & 0xff] + '-' +
18+
lut[d2 & 0x3f | 0x80] + lut[d2 >> 8 & 0xff] + '-' + lut[d2 >> 16 & 0xff] + lut[d2 >> 24 & 0xff] +
19+
lut[d3 & 0xff] + lut[d3 >> 8 & 0xff] + lut[d3 >> 16 & 0xff] + lut[d3 >> 24 & 0xff];
20+
};

test/uuid.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test from 'ava';
2+
3+
Test('generates', t => {
4+
t.truthy(true);
5+
});

0 commit comments

Comments
 (0)