@js-random/string
TypeScript icon, indicating that this package has built-in type declarations

0.3.5 • Public • Published

@js-random/string

A simple and lightweight string randomizer for JavaScript (TypeScript friendly)

Installation

npm i -S @js-random/string

Usage

commonjs:

var randomString = require('@js-random/string').default;

TS/ES6+:

import randomString from '@js-random/string';

<script> tag:

<script src="https://unpkg.com/@js-random/string"></script>
// All parameters are optional

// A random 10-symbol string. Probably something like "2P*D:4[T9="
var string = randomString();

// Random string of length 4, with a seed of 'Hello, World!' filtered by /[HW,erld]/ for each symbol
var hell_comma_wrld = randomString(4, 'Hello, World!', /[HW,erld]/);

// Object-style parameter is also available:
hell_comma_wrld = randomString({
  length: 4,
  seed: 'Hello, World!',
  filter: /[HW,erld]/
});

Global version

This package also has a global version, which introduces side-effects by exposing the api as String.random() function.

Import

commonjs:

require('@js-random/string/lib/global');

ES6+:

import '@js-random/string/module/global';

TS:

import '@js-random/string/module/global';

<script> tag

<script src="https://unpkg.com/@js-random/string/unpkg/global"></script>

Usage

// A random 10-symbol string. Probably something like "2P*D:4[T9="
var string = String.random();

// Random string of length 4, with a seed of 'Hello, World!' filtered by /[HW,erld]/ for each symbol
var hell_comma_wrld = String.random(4, 'Hello, World!', /[HW,erld]/);

// Object-style parameter is also available:
hell_comma_wrld = String.random({
  length: 4,
  seed: 'Hello, World!',
  filter: /[HW,erld]/
});

Other packages

Please, have a look at other packages from @js-random series:

Package Sidebar

Install

npm i @js-random/string

Weekly Downloads

5

Version

0.3.5

License

MIT

Unpacked Size

19.2 kB

Total Files

21

Last publish

Collaborators

  • raiondesu