Socket
Socket
Sign inDemoInstall

crypto-random-string

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    crypto-random-string

Generate a cryptographically strong random string


Version published
Weekly downloads
16M
decreased by-0.26%
Maintainers
1
Install size
34.1 kB
Created
Weekly downloads
 

Package description

What is crypto-random-string?

The crypto-random-string package is a utility for generating cryptographically strong random strings of a specified length, using Node.js's crypto module. It can be used for creating unique identifiers, tokens, or any other use cases where random strings are needed.

What are crypto-random-string's main functionalities?

Generating a random string of a specified length

This feature allows you to generate a random string with a specified length. The length is provided as an option in an object passed to the function.

const cryptoRandomString = require('crypto-random-string');

const randomString = cryptoRandomString({length: 10});
console.log(randomString);

Generating a random string with a specific type

This feature allows you to generate a random string with a specific character set, such as alphanumeric, numeric, or 'url-safe' characters.

const cryptoRandomString = require('crypto-random-string');

const alphanumericString = cryptoRandomString({length: 10, type: 'alphanumeric'});
console.log(alphanumericString);

Generating a random string with custom characters

This feature allows you to generate a random string using a custom set of characters provided by the user.

const cryptoRandomString = require('crypto-random-string');

const customString = cryptoRandomString({length: 10, characters: 'abc123'});
console.log(customString);

Other packages similar to crypto-random-string

Readme

Source

crypto-random-string Build Status

Generate a cryptographically strong random string

Can be useful for creating an identifier, slug, salt, fixture, etc.

Install

$ npm install crypto-random-string

Usage

const cryptoRandomString = require('crypto-random-string');

cryptoRandomString({length: 10});
//=> '2cf05d94db'

cryptoRandomString({length: 10, type: 'base64'});
//=> 'YMiMbaQl6I'

cryptoRandomString({length: 10, type: 'url-safe'});
//=> 'YN-tqc8pOw'

cryptoRandomString({length: 10, characters: '1234567890'});
//=> '1791935639'

API

cryptoRandomString(options)

Returns a randomized string. Hex by default.

options

Type: object

length

Required
Type: number

Length of the returned string.

type

Type: string
Default: 'hex'
Values: 'hex' 'base64' 'url-safe'

Use only characters from a predefined set of allowed characters.

Cannot be set at the same time as the characters option.

characters

Type: string
Minimum length: 1
Maximum length: 65536

Use only characters from a custom set of allowed characters.

Cannot be set at the same time as the type option.

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 08 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc