Skip to content

Commit

Permalink
adding library
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxing committed Jul 3, 2018
1 parent 95e8d3c commit 4090583
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "simple-random-string",
"version": "1.0.0",
"description": "get a random string",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/yiliashaw/simple-random-string.git"
},
"keywords": [
"random",
"string"
],
"author": "yiliashaw <yilia.shaw@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/yiliashaw/simple-random-string/issues"
},
"homepage": "https://github.com/yiliashaw/simple-random-string#readme",
"dependencies": {
"unique-random-array": "1.0.1"
}
}
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var uniqueRandomArray = require('unique-random-array');

module.exports = function (len) {
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var optionArray = possible.split('');
var length = len && typeof len === 'number' && len > 0 ? len : 8;
var str = '';
var rand = uniqueRandomArray(optionArray);
for (var i = 0; i < length; i++) {
str += rand();
}
return str;
};

0 comments on commit 4090583

Please sign in to comment.