Skip to content

Commit

Permalink
Switch to using math-random
Browse files Browse the repository at this point in the history
  • Loading branch information
chilts committed Jul 19, 2018
1 parent 66992b7 commit 4fef760
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const mathRandom = require('math-random')

function yid() {
let id = Date.now() + '-' + String(Math.random()).substr(2, 13)
while ( id.length < 27 )
let id = Date.now() + '-' + String(mathRandom()).substr(2, 13)

while ( id.length < 27 ) {
id += '0'
}

return id
}

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"scripts": {
"test": "node test.js"
},
"dependencies": {
"math-random": "^1.0.1"
},
"homepage": "https://github.com/chilts/yid",
"bugs": {
"url": "https://github.com/chilts/yid/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/chilts/yid.git"
Expand All @@ -14,9 +21,5 @@
"id"
],
"author": "Andrew Chilton",
"license": "ISC",
"bugs": {
"url": "https://github.com/chilts/yid/issues"
},
"homepage": "https://github.com/chilts/yid#readme"
"license": "ISC"
}

0 comments on commit 4fef760

Please sign in to comment.