pax_global_header00006660000000000000000000000064130122350600014502gustar00rootroot0000000000000052 comment=21960c996c3f77cf5f7bf6765e837e7c8a07e200 crypto-random-string-1.0.0/000077500000000000000000000000001301223506000156025ustar00rootroot00000000000000crypto-random-string-1.0.0/.editorconfig000066400000000000000000000002761301223506000202640ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 crypto-random-string-1.0.0/.gitattributes000066400000000000000000000000351301223506000204730ustar00rootroot00000000000000* text=auto *.js text eol=lf crypto-random-string-1.0.0/.gitignore000066400000000000000000000000151301223506000175660ustar00rootroot00000000000000node_modules crypto-random-string-1.0.0/.travis.yml000066400000000000000000000000531301223506000177110ustar00rootroot00000000000000language: node_js node_js: - '6' - '4' crypto-random-string-1.0.0/index.js000066400000000000000000000003611301223506000172470ustar00rootroot00000000000000'use strict'; const crypto = require('crypto'); module.exports = len => { if (!Number.isFinite(len)) { throw new TypeError('Expected a finite number'); } return crypto.randomBytes(Math.ceil(len / 2)).toString('hex').slice(0, len); }; crypto-random-string-1.0.0/license000066400000000000000000000021371301223506000171520ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. crypto-random-string-1.0.0/package.json000066400000000000000000000013121301223506000200650ustar00rootroot00000000000000{ "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 } } crypto-random-string-1.0.0/readme.md000066400000000000000000000025751301223506000173720ustar00rootroot00000000000000# crypto-random-string [![Build Status](https://travis-ci.org/sindresorhus/crypto-random-string.svg?branch=master)](https://travis-ci.org/sindresorhus/crypto-random-string) > Generate a [cryptographically strong](https://en.m.wikipedia.org/wiki/Strong_cryptography) random string Can be useful for creating an identifier, slug, salt, fixture, etc. ## Install ``` $ npm install --save crypto-random-string ``` ## Usage ```js const cryptoRandomString = require('crypto-random-string'); cryptoRandomString(10); //=> '2cf05d94db' ``` ## API ### cryptoRandomString(length) #### length Type: `number` Length of the returned string. ## Related - [random-int](https://github.com/sindresorhus/random-int) - Generate a random integer - [random-float](https://github.com/sindresorhus/random-float) - Generate a random float - [random-item](https://github.com/sindresorhus/random-item) - Get a random item from an array - [random-boolean](https://github.com/arthurvr/random-boolean) - Get a random boolean - [random-obj-key](https://github.com/sindresorhus/random-obj-key) - Get a random key from an object - [random-obj-prop](https://github.com/sindresorhus/random-obj-prop) - Get a random property from an object - [unique-random](https://github.com/sindresorhus/unique-random) - Generate random numbers that are consecutively unique ## License MIT © [Sindre Sorhus](https://sindresorhus.com) crypto-random-string-1.0.0/test.js000066400000000000000000000002101301223506000171100ustar00rootroot00000000000000import test from 'ava'; import m from './'; test(t => { t.is(m(0).length, 0); t.is(m(10).length, 10); t.is(m(100).length, 100); });