npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

randomstring-promise

v0.0.2

Published

Random string generator with Promise interface

Downloads

140

Readme

randomstring-promise

wercker status

Random string generator inspired by node-randomstring with consistent promise interface for Nodejs, web browsers, and ReactNative.

This library uses following RNGs to generate cryptographically secure random value.

(react-native-randombytes only provides asynchronous function and that's why this library focuses on asynchronous interface only.)

If you need only web-browser implementation, also check randomstring-browserify.

Installation

$ npm install randomstring-promise

Usage

import randomstringPromise from 'randomstring-promise';  // NodeJS
// import randomstringPromise from 'randomstring-promise/browser';  // Browsers
// import randomstringPromise from 'randomstring-promise/react-native';  // React Native

randomstringPromise()
.then(function(result) {
    console.log(result);  // u8KNs7aAw0DCOKO1MdEgVIcF2asajrdd
});

Options

randomstringPromise(length, charset)

  • length: Integer (default: 32)
  • charset: String (default: 'alphanumeric')
    • alphanumeric [0-9a-zA-Z]
    • alphabetic [a-zA-Z]
    • numeric [0-9]
    • hex [0-9a-f]
    • your own (specify your own character set as a string like abcxyz)
randomstringPromise(16)  // length=16, charset='alphanumeric' (default)
.then(function(result) {
    console.log(result);  // 4BfHIF0s697EOW9Y
});

randomstringPromise(16, 'numeric') // length=16, charset='numeric'
.then(function(result) {
    console.log(result);  // 3122428966440165
});

randomstringPromise(8, 'abc') // length=8, customized charset 'a', 'b', and 'c'
.then(function(result) {
    console.log(result);  // ccbcacbc
});

React Native

React Native implementation depends on a react-native-randombytes's native code so it must be installed (Follow its instruction). But this library does not use its original JavaScript implementation and omits its synchronous function which has more wide and deeper dependencies such as react-native-crypto.