Socket
Socket
Sign inDemoInstall

@sidoshi/random-string

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @sidoshi/random-string

Create cryptographically random strings.


Version published
Maintainers
1
Install size
65.8 kB
Created

Readme

Source

Cryptographic Random String

Build Status

Library to create cryptographically random strings.

Install

npm i @sidoshi/random-string

Usage

import { randomstring, charsets } from '@sidoshi/random-string';

// => Alphanumeric string of length 32
console.log(randomstring());

// => Alphanumeric string of length 10
console.log(randomstring(10));

// => Alphabetic string of length 32
console.log(randomstring({ characters: charsets.alphabetic }));

// => Numeric string of length 10
console.log(randomstring({ characters: charsets.numeric, length: 10 }));

// => String of length 50 with custom character set
console.log(
  randomstring({ characters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', length: 50 })
);

// => Composing predefined charsets
console.log(
  randomstring({ characters: charsets.numeric + charsets.symbols, length: 50 })
);

API

  • charsets - Predefined character sets
    • alphanumeric
    • alphabetic
    • loweralpha
    • upperalpha
    • numeric
    • hex
    • symbols
  • randomstring(size?) - Generate a random string of given size. (default: 30)
  • randomstring(options?) - Generate a random string using given options
    • length - Length of the specified string. (default: 30)
    • characters - Character set to use to generate string (default: charsets.alphanumeric). Can be one of the predifined charsets or a custom string. Throws if characters.length > 65536.

Licence

MIT © Siddharth Doshi

Keywords

FAQs

Last updated on 04 Jul 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