Randomly
Randomly generate and sort data.
Installation
Run npm install --save randomly
to add randomly
to your project.
API Reference
- randomly
- .string(length) ⇒
string
- .int(min, max) ⇒
number
- .getLowerInt(degree) ⇒
number
- .getUpperInt(degree) ⇒
number
- .create(type, length) ⇒
string
|number
|Object
- .collect(type, quantity, length) ⇒
Array.<string>
|Array.<number>
|Array.<Object>
- .sort(array) ⇒
Array
- .string(length) ⇒
string
randomly.string(length) ⇒ Creates a random string.
Kind: static method of randomly
Returns: string
- The random string.
Throws:
TypeError
Argument length must be a numberRangeError
Argument length must be greater than or equal to 0
Param | Type | Description |
---|---|---|
length | number |
The desired string length. |
number
randomly.int(min, max) ⇒ Creates a random number within a range.
Kind: static method of randomly
Returns: number
- The random number.
Throws:
TypeError
Argument min must be a numberTypeError
Argument max must be a number
Param | Type | Description |
---|---|---|
min | number |
The lower bound. |
max | number |
The upper bound. |
number
randomly.getLowerInt(degree) ⇒ Calculates the smallest n-digit number.
Kind: static method of randomly
Returns: number
- The smallest n-digit number.
Throws:
TypeError
Argument degree must be a numberRangeError
Argument degree must be greater than or equal to 0
Param | Type | Description |
---|---|---|
degree | number |
The number of digits. |
number
randomly.getUpperInt(degree) ⇒ Calculates the largest n-digit number.
Kind: static method of randomly
Returns: number
- The largest n-digit number.
Throws:
TypeError
Argument degree must be a numberRangeError
Argument degree must be greater than or equal to 0
Param | Type | Description |
---|---|---|
degree | number |
The number of digits. |
string
| number
| Object
randomly.create(type, length) ⇒ Creates a random string, number or object.
Kind: static method of randomly
Returns: string
| number
| Object
- The random string, number or object.
Throws:
TypeError
Argument length must be a numberRangeError
Argument length must be greater than or equal to 0
Param | Type | Description |
---|---|---|
type | function |
The type to create (e.g. String, Number or Object). |
length | number |
The length (for strings and Objects) or boundary degree (for numbers). |
Array.<string>
| Array.<number>
| Array.<Object>
randomly.collect(type, quantity, length) ⇒ Creates an array of random strings, numbers or objects.
Kind: static method of randomly
Returns: Array.<string>
| Array.<number>
| Array.<Object>
- The array of random strings, numbers or objects.
Throws:
TypeError
Argument quantity must be a numberRangeError
Argument quantity must be greater than 0TypeError
Argument length must be a numberRangeError
Argument length must be greater than or equal to 0
Param | Type | Description |
---|---|---|
type | function |
The type to create (e.g. String, Number or Object). |
quantity | number |
The quantity to create. |
length | number |
The length (for strings and Objects) or boundary degree (for numbers). |
Array
randomly.sort(array) ⇒ Sorts an array in random order.
Kind: static method of randomly
Returns: Array
- The sorted array.
Param | Type | Description |
---|---|---|
array | Array |
The array to sort. |
Testing
randomly
includes several unit tests. After cloning the randomly
repo locally, run npm install
in the project folder to install dependencies. Run npm run build
to update the built library, then npm test
to execute the tests.