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

randex

v0.21.0

Published

Generates random filename, username, email, name, full name, etc for test purposes.

Downloads

557

Readme

randex

Generates random filename, username, email, name, full name, etc for test purposes.

Usage

Installation:

npm i randex

Strings:

Numbers:

Generic Type:

Deeps:

random

Basic function to construct random things.

import { random } from "randex";

// 3 english chars
random({
  set: "english",
  length: 3,
});
// or short:
random(["english", 3]);
// EFd

// 3 lower english chars
random({
  set: ["english", "lower"],
  length: 3,
});
// or short:
random([["english", "lower"], 3]);
// yhl

// min 1 and max 3 english chars
random({
  set: "english",
  length: [1, 3],
});
// or short:
random(["english", [1, 3]]);
// eR

// 3 number chars
random({
  set: "number",
  length: 3,
});
// or short:
random(["number", 3]);
// 643

// 3 chars from custom range
random({
  range: "abc123",
  length: 3,
});
// a21

// 3 english or number chars
random({
  set: ["english", "number"],
  length: 3,
});
// or short:
random([["english", "number"], 3]);
// x4d

// 4 chars: 2 english and 2 english or number
random(
  {
    set: "english",
    length: 2,
  },
  {
    set: ["english", "number"],
    length: 2,
  }
);
// or short:
random(["english", 2], [["english", "number"], 2]);
// Kb3b

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |set|RandexSet | Defined chars| |range|string| Range or custom chars | |length|RandexLength | Length of chars |

randomFileName

Randoms file name.

import { randomFileName } from "randex";

// default
randomFileName({
  extension: "txt",
});
// td1TX31eOB.txt

// defined extension
randomFileName({
  extension: "txt",
});
// or short:
randomFileName("txt");
// HkmOjqHC6.txt

// defined file name length and extension length
randomFileName({
  fileNameLength: [7, 10],
  extensionLength: 5,
});
// or short:
randomFileName([7, 10], 5);
// 1SJVkHSBjq.tejuw

// defined file name length and extension
randomFileName({
  fileNameLength: 8,
  extension: "xml",
});
// or short:
randomFileName(8, "xml");
// JyCsuN5kD.xml

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |fileNameLength|RandexLength | Length of file name (not including extension). Default: [3,10] | |extensionLength|RandexLength | Length of extension (not including file name) chars. Default: [2,5] | |extension| string| File extension. |

randomUsername

Randoms username.

import { randomUsername } from "randex";

// default
randomUsername();
// icvv81d1j

// with length 5 chars
randomUsername({ length: 5 });
// or short:
randomUsername(5);
// okmle

// with 2 min and 5 max chars
randomName({ length: [2, 5] });
// or short:
randomUsername([2, 5]);
// lkhs

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |length|RandexLength | Length of chars. Default: [6,10] |

randomEmail

Randoms an email.

import { randomEmail } from "randex";

// default
randomEmail();
// [email protected]

// defined prefix length
randomEmail({
  prefixLength: 8,
});
// or shot:
randomEmail(8);
// [email protected]

// defined prefix, low domain and hight domain length
randomEmail({
  prefixLength: 8,
  lowDomainLength: 4,
  hightDomainLength: 2,
});
// or shot:
randomEmail(8, 4, 2);
// [email protected]

// defined domain
randomEmail({
  domain: "test.com",
});
// or shot:
randomEmail("test.com");
// [email protected]

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |prefixLength|RandexLength | Length of email prefix (chars before @). Default: [6, 10] | |hightDomainLength|RandexLength | Length of hight domain part (example: test.com). Default: [1,6] | |lowDomainLength|RandexLength | Length of low domain part (example: test.com). Default: [4,2] | |domain| string| Defined domain. |

randomName

Randoms a name of the person, city, place, restaurant, ect.

import { randomName } from "randex";

// default
randomName();
// Ijb

// with length 5 chars
randomName({ length: 5 });
// or short:
randomName(5);
// Okmpj

// with 2 min and 5 max chars
randomName({ length: [2, 5] });
// or short:
randomName([2, 5]);
// Wslg

// name from french alphabet
randomName({ alphabet: "french" });
// or short:
randomName("french");
// Dbïœ

// name from french alphabet with length
randomName({ alphabet: "french", length: 10 });
// or short:
randomName("french", 10);
// Rsîrjhjôôw

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |length|RandexLength | Length of chars. Default: [2,10] | |alphabet|RandexAlphabet | Defined alphabet. Default: english |

randomFullName

Randoms a full name of the person.

import { randomFullName } from "randex";

// default
randomFullName();
// Eqaa Bfmotnq

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |firstLength|RandexLength | First name length of chars. Default: [2, 10] | |secondLength|RandexLength | Second name length of chars. Default: [2,10] | |alphabet|RandexAlphabet | Defined alphabet. Default: english |

randomNumber

Generates random number from a range of numbers.

import { randomNumber } from "randex";

// Generates a number from a range: [0, 3] (includes 0 and 3).
randomNumber(3);

// Generates a number from a specified range: [3, 7].
randomNumber([3, 7]);

Options: | Name | Type| Description| | ------------------------ | ---- |------------ | |decimals| number | Number of decimal digits |

randomNumberArray

Generates random array with values from a range.

import { randomNumberArray } from "randex";

// Generates an array (with length equals 2) with unique numbers from a range: [0, 3].
randomNumberArray(3, 2);

// Generates an array (with length equals 3) with unique numbers from a range: [3, 7].
randomNumber([3, 7], 3);

randomArray

Generates random array with values from defined array.

import { randomArray } from "randex";

// Generates an array (with length equals 2) with values picked from defined array as the first parameter.
randomArray([1, 2, 3, 4], 2);
// [2, 4]
randomArray(["1", "2", "3", "4"], 2);
// ["1", "3"]

Customization

random function is very flexible, there are many custom functions can be created.

There are examples how to create custom function for most common cases:

randomFileName

random([
  ["english", "number"],
  [3, 10],
]) +
  "." +
  random([
    ["english", "l"],
    [2, 5],
  ]);

randomUsername

random(
  ["english", "l"],
  [
    [["english", "l"], "number"],
    [5, 10],
  ]
);

randomEmail

random([
  [["english", "l"], "number"],
  [6, 10],
]) +
  "@" +
  random([
    ["english", "l"],
    [2, 4],
  ]) +
  "." +
  random([
    ["english", "l"],
    [1, 6],
  ]);

randomName

random(
  ["english", "u"],
  [
    ["english", "l"],
    [1, 10],
  ]
);

randomFullName

random(
  ["english", "u"],
  [
    ["english", "l"],
    [1, 10],
  ]
) +
  " " +
  random(
    ["english", "u"],
    [
      ["english", "l"],
      [1, 10],
    ]
  );

Types

RandexLength

Possible types:

number: strict length

[number, number]: an array of min and max length.

Example:

random({ set: "bit", length: 5 });
random({ set: "bit", length: [5, 10] });
// or short:
random(["bit", 5]);
random(["bit", [5, 10]]);

RandexSet

Possible types:

string: an alphabet - RandexAlphabet or a set of chars - RandexKit

[string, string]: the first item is - RandexAlphabet, the second item is - RandexCase

Example:

random({ set: "bit" });
random({ set: "spanish" });
random({ set: ["spanish", "lower"] });
// or short:
random("bit");
random("spanish");
random(["spanish", "l"]);

RandexAlphabet

An alphabet of chars

string values: english, french, spanish, russian.

Example:

random({ set: "spanish" });
// or short:
random("spanish");

RandexKit

A kit of chars

string values: hex, symbol, number, binary.

Example:

random({ set: "hex" });
// or short:
random("hex");

RandexCase

A case of alphabet

string values: upper, u,lower, l.

Example:

random({ set: ["spanish", "lower"] });
// or short:
random(["spanish", "l"]);