@js-random/string
v0.3.5
Published
A simple and lightweight string randomizer for JavaScript (TypeScript friendly)
Downloads
17
Maintainers
Readme
@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:
@js-random/all
- all the randomizers in one package - GitHub repo, NPM@js-random/number
GitHub repo, NPM@js-random/boolean
GitHub repo, NPM@js-random/date
GitHub repo, NPM