0.5.0 • Published 5 years ago

@fandridis/teeheo v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Teeheo

Teeheo is a small library for generating all kind of pseudo-random numbers and strings. With teeheo, you can easily generate integers, floats, alphanumerics and uuids.

INSTALL

There are 3 ways to install the library.

  1. With a script
<script src="https://cdn.jsdelivr.net/npm/@fandridis/teeheo@0.3.5/index.js"></script>
  1. As an npm package (TBA)

  2. (TBA)

METHODS

1. Integers

With teeheo.int(min, max) you can generate random integers between a desired range.

ParametersDescription
min(Optional) Number: The lower limit - inclusive
max(Optional) Number: The higher limit - inclusive

When two parameters are passed, they act as a range.

Example:

teeheo.int(5, 20) // Will return a integer between 5 and 20

If only one parameter is passed, it will return:

  • an integer from 0 to the parameter, if the parameter is positive
  • an integer from the parameter to 0, if the parameter is negative

Example:

teeheo.int(20) // Will return a integer between 0 and 20
teeheo.int(-10) // Will return a integer between -10 and 0

If no parameters are passed, it will act like a coinflip and return either 0 or 1 Example:

teeheo.int() // Will return 0 or 1

2. Floats

Similar to integers, with teeheo.float(min, max, options) you can generate random floats between a desired range. You can also limit the amount of decimal points returned.

ParametersDescription
min(Optional) Number: The lower limit - inclusive
max(Optional) Number: The higher limit - inclusive
options(Optional) Object: To specify the maximum amount of decimals

When two parameters are passed, they act as the range. Example:

teeheo.float(5, 20) // Will return a float between 5 and 20

If only one parameter is passed, it will return:

  • a float from 0 to the parameter, if the parameter is positive
  • a float from the parameter to 0, if the parameter is negative

Example:

teeheo.float(20) // Will return a float between 0 and 20
teeheo.float(-10) // Will return a float between -10 and 0

If no parameters are passed, it will return a random float from 0 to 1 Example:

teeheo.float() // Will return a float between 0 and 1 

You can pass an object as a third parameter to state how many decimals should be returned

teeheo.float(5, 10, { decimals: 3 }) // Will return a random float between 5 and 10 with 3 decimals. ex: 7.348

3. Strings

With teeheo.str(length, options) you can generate random floats between a desired range. You can also limit the amount of decimal points returned. By default, the generated string will include lowercase letters, uppercase letters and numbers.

ParametersDescription
lengthNumber: The character length of the generated string
options(Optional) Object: To configure the list of characters to be included

The options can be:

OptionDescription
excludeUpperBoolean: Excludes uppercase letters
excludeLowerBoolean: Excludes lowercase letters
excludeNumbersBoolean: Excludes numbers
excludeZeroBoolean: Excludes the number 0
customListString: To specify the exact characters to use

Examples:

teeheo.str(9) // ex: abcABC012
teeheo.str(9, { excludeUpper: true }) // ex: abcabc012
teeheo.str(9, { excludeLower: true }) // ex: ABCABC012
teeheo.str(9, { excludeNumbers: true }) // ex: abcABCabc
teeheo.str(9, { excludeZero: true }) // ex: abcABC123
teeheo.str(9, { customList: 'xy' }) // ex: xyxxyyxxx

4. UUID

With teeheo.uuid4() you can generate random uuid4 string

Example:

teeheo.uuid4() // ex: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
0.5.0

5 years ago

0.4.0

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago