randomly v3.0.4
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
randomly.string(length) ⇒ string
Creates a random string.
Kind: static method of randomly
Returns: string - The random string.
Throws:
- TypeError Argument length must be a number
- RangeError Argument length must be greater than or equal to 0
| Param | Type | Description |
|---|---|---|
| length | number | The desired string length. |
randomly.int(min, max) ⇒ number
Creates a random number within a range.
Kind: static method of randomly
Returns: number - The random number.
Throws:
- TypeError Argument min must be a number
- TypeError Argument max must be a number
| Param | Type | Description |
|---|---|---|
| min | number | The lower bound. |
| max | number | The upper bound. |
randomly.getLowerInt(degree) ⇒ number
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 number
- RangeError Argument degree must be greater than or equal to 0
| Param | Type | Description |
|---|---|---|
| degree | number | The number of digits. |
randomly.getUpperInt(degree) ⇒ number
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 number
- RangeError Argument degree must be greater than or equal to 0
| Param | Type | Description |
|---|---|---|
| degree | number | The number of digits. |
randomly.create(type, length) ⇒ string | number | Object
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 number
- RangeError 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). |
randomly.collect(type, quantity, length) ⇒ Array.<string> | Array.<number> | Array.<Object>
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 number
- RangeError Argument quantity must be greater than 0
- TypeError Argument length must be a number
- RangeError 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). |
randomly.sort(array) ⇒ 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.