crypto-random-string
Advanced tools
Comparing version 1.0.0 to 2.0.0
'use strict'; | ||
const crypto = require('crypto'); | ||
module.exports = len => { | ||
if (!Number.isFinite(len)) { | ||
module.exports = length => { | ||
if (!Number.isFinite(length)) { | ||
throw new TypeError('Expected a finite number'); | ||
} | ||
return crypto.randomBytes(Math.ceil(len / 2)).toString('hex').slice(0, len); | ||
return crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length); | ||
}; |
{ | ||
"name": "crypto-random-string", | ||
"version": "1.0.0", | ||
"description": "Generate a cryptographically strong random string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/crypto-random-string", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"random", | ||
"string", | ||
"str", | ||
"rand", | ||
"text", | ||
"id", | ||
"identifier", | ||
"slug", | ||
"salt", | ||
"crypto", | ||
"strong", | ||
"secure", | ||
"hex" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "crypto-random-string", | ||
"version": "2.0.0", | ||
"description": "Generate a cryptographically strong random string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/crypto-random-string", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"random", | ||
"string", | ||
"text", | ||
"id", | ||
"identifier", | ||
"slug", | ||
"salt", | ||
"crypto", | ||
"strong", | ||
"secure", | ||
"hex" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # crypto-random-string [![Build Status](https://travis-ci.org/sindresorhus/crypto-random-string.svg?branch=master)](https://travis-ci.org/sindresorhus/crypto-random-string) | ||
``` | ||
$ npm install --save crypto-random-string | ||
$ npm install crypto-random-string | ||
``` | ||
@@ -30,2 +30,4 @@ | ||
Returns a [`hex`](https://en.wikipedia.org/wiki/Hexadecimal) string. | ||
#### length | ||
@@ -32,0 +34,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3929
5
21
52
0
3