random
number​
Description​
Method that generates a random number based on Lagged Fibonacci PRNG implementation in JS. If you want more info about this you can check this repo
Parameters​
| Name | Type | Description |
|---|---|---|
| options | <Object> | You can pass parameters as this object properties |
| options.min | <Number> | Min number to be generated. Default value is 0 |
| options.max | <Number> | Max number to be generated. Default value is 99999 |
| options.precision | <Number> | Floating point precision to be used, if value is 0 then no floating point is generated. Default value is 0 |
Returns​
- <Number>
Usage​
Without passing parameters
- code
console.log(pure.random.number());- result
33235Random number between 5 and 10 and i wish the result with precision of 4 numbers after floating point
- code
console.log(pure.random.number({ min: 5, max: 10, precision: 4 }));- result
7.6555
float​
Description​
Method that generates a random float number.
Parameters​
| Name | Type | Description |
|---|---|---|
| options | <Object> | You can pass parameters as this object properties |
| options.min | <Number> | Min number to be generated. Default value is 0 |
| options.max | <Number> | Max number to be generated. Default value is 99999 |
| options.precision | <Number> | Floating point precision to be used, if value is 0 then no floating point is generated. Default value is 0 |
Returns​
- <Number>
Usage​
Without passing parameters
- code
console.log(pure.random.float());- result
38684.5Random float between 5 and 10 and i wish the result with precision of 4 numbers after floating point
- code
console.log(pure.random.float({ min: 5, max: 10, precision: 4 }));- result
9.461
arrayElement​
Description​
Method that will pick a random item based on provided list as a parameter.
Parameters​
| Name | Type | Description |
|---|---|---|
| array | <Array> | Array list that will be randomized and picked one entry. Default value is randomized from this list: 'a', 'b', 'c' |
Returns​
- If you provided an number list, it will return a number and so on.
Usage​
Without passing parameters
- code
console.log(pure.random.arrayElement());- result
'c'Passing an array as parameter
- code
console.log(pure.random.arrayElement([ 'apple', 'banana', 'watermelon' ]));- result
'apple'
arrayElements​
Description​
Method that will randomly excludes some entries and generate a subset of given list.
Parameters​
| Name | Type | Description |
|---|---|---|
| array | <Array> | Array list that will be randomized and created a subset. Default value is randomized from this list: 'a', 'b', 'c' |
| count | <Number> | Number of elements that will last in result list. Default value is randomized |
Returns​
- <Array>
Usage​
Without passing parameters
- code
console.log(pure.random.arrayElements());- result
[ 'a', 'b' ]Passing an array as parameter and specifying that the subset has to had 3 entries
- code
console.log(pure.random.arrayElements([ 'apple', 'banana', 'watermelon', 1, 2, 5 ], 3));- result
[ 'apple', 1, 5 ]
objectElement​
Description​
Method that receives an object and will randomly pick a value or a key.
Parameters​
| Name | Type | Description |
|---|---|---|
| object | <Array> | Object that will be randomized and picked a value or key. Default value is randomized from this object: { foo: 'bar', too: 'car' } |
| field | <String> | Field that will be returned, you can choose if you want a value or key. Default field is 'value' |
Returns​
- Randomized value from provided object. If you provided an number, it will return a number and so on. But if you ask to return only key field, it will always be a string as a result.
Usage​
Without passing parameters
- code
console.log(pure.random.objectElement());- result
'bar'Passing an object as parameter and specifying that the value i want to be returned is a key
- code
console.log(pure.random.objectElement({ test: 'result', prop: 1 }, 'key'));- result
'prop'
generateObj​
Description​
Method that can generate an object with random keys and values.
Parameters​
| Name | Type | Description |
|---|---|---|
| length | <Number> | What length object generated will have. Default value is 2 |
Returns​
- <Object>
Usage​
Without passing parameters
- code
console.log(pure.random.generateObj());- result
{
Baby: 'card',
Liaison: 'empower'
}Passing 5 as a length to object
- code
console.log(pure.random.generateObj(5));- result
{
payment: 'Avon',
Chicken: 'Bike',
Incredible: 'Soap',
Kenya: 'olive',
neural: 'override'
}
uuid​
Description​
This method can generate a random valid uuid. It is based on uuid package for node, if you want more details consult UUID. Note: if you pass v5 as a version to generate and always give the same name and namespace it will generate the same uuid.
Parameters​
| Name | Type | Description |
|---|---|---|
| version | <String> | What version of uuid you want, can be: 'v1', 'v4' or 'v5'. Default value is 'v1' |
| opts | <Object> | You can pass parameters as this object properties |
| opts.name | <String> | String to use in v5 uuid generation. Default value is 'uuid' |
| opts.namespace | <String> | String with uuid namespace to use in v5 generation. Default value is a random v1 uuid |
Returns​
- <String>
Usage​
Without passing parameters
- code
console.log(pure.random.uuid());- result
'7a3c7de0-22c1-11ec-a3ea-c7f4a0fdd1fc'Passing v5 as a version to uuid and specifying that the string to use in uuid generation has to be
https://www.w3.org/- code
console.log(pure.random.uuid('v5', { name: 'https://www.w3.org/' }));- result
'ad349628-05b3-5419-9633-82c22c136baa'
boolean​
Description​
Method that generates random boolean
Parameters​
| Name | Type | Description |
|---|---|---|
| N/A | N/A | This method doesn't receive any parameters |
Returns​
- <Boolean>
Usage​
- Without passing parameters
- code
console.log(pure.random.boolean());- result
true
word​
Description​
Method that generates random word based on multiple pure methods. Possible word methods:
- Department
- Product Name
- Product Adjective
- Product Material
- Product
- Color
- Catch Phrase Adjective
- Catch Phrase Descriptor
- Catch Phrase Noun
- Bs Adjective
- Bs Buzz
- Bs Noun
- Street Suffix
- County
- Country
- State
- Account Name
- Transaction Type
- Currency Name
- Noun
- Verb
- Adjective
- Ing Verb
- Abbreviation
- Job Descriptor
- Job Area
- Job Type
Parameters​
| Name | Type | Description |
|---|---|---|
| N/A | N/A | This method doesn't receive any parameters |
Returns​
- <String>
Usage​
- Without passing parameters
- code
console.log(pure.random.word());- result
'transmit'
words​
Description​
Method that generates random multiple words. All the possibilities are the same as Word but this method generates more then one.
Parameters​
| Name | Type | Description |
|---|---|---|
| count | <Number> | How many words that will be returned. Default value is a random value between 1 and 3 |
Returns​
- <String>
Usage​
Without passing parameters
- code
console.log(pure.random.words());- result
'Berkshire'Specifying that i want 7 random words as result
- code
console.log(pure.random.words(7));- result
'Research Avenue e-markets payment Investment Orchestrator transmitting'
locale​
Description​
Method that returns random possible locale to use in pure. All possibilities:
- af_ZA
- ar
- az
- cz
- de
- de_AT
- de_CH
- el
- en
- en_AU
- en_BORK
- en_CA
- en_GB
- en_IE
- en_IND
- en_NG
- en_US
- en_ZA
- en_au_ocker
- es
- es_MX
- fa
- fr
- fr_CA
- fr_CH
- ge
- id_ID
- it
- ja
- ko
- lv
- nb_NO
- nep
- nl
- nl_BE
- pl
- pt_BR
- pt_PT
- ro
- ru
- sk
- sv
- tr
- uk
- vi
- zh_CN
- zh_TW
- zu_ZA
Parameters​
| Name | Type | Description |
|---|---|---|
| N/A | N/A | This method doesn't receive any parameters |
Returns​
- <String>
Usage​
- Without passing parameters
- code
console.log(pure.random.locale());- result
'it'
alpha​
Description​
Method that generates a string with random letters.
Parameters​
| Name | Type | Description |
|---|---|---|
| options | <Object> | You can pass parameters as this object properties |
| options.count | <Number> | How many letters to return. Default value is 1 |
| options.upcase | <Boolean> | If letters returned will be uppercase or not. Default value is false |
Returns​
- <String>
Usage​
Without passing parameters
- code
console.log(pure.random.alpha());- result
'v'Describing that i want the string to feature 6 chars in upper case
- code
console.log(pure.random.alpha({ count: 6, upcase: true }));- result
'ZDVPFX'
alphaNumeric​
Description​
Method that generates a string with random alpha numeric chars.
Parameters​
| Name | Type | Description |
|---|---|---|
| count | <Number> | How many chars that will be returned. Default value is 1 |
Returns​
- <String>
Usage​
Without passing parameters
- code
console.log(pure.random.alphaNumeric());- result
'e'Describing that i want the string to feature 9 chars
- code
console.log(pure.random.alphaNumeric(9));- result
'kqmlaj282'
hexaDecimal​
Description​
Method that generates a string with random hexa decimal chars.
Parameters​
| Name | Type | Description |
|---|---|---|
| count | <Number> | How many chars that will be returned. Default value is 1 |
Returns​
- <String>
Usage​
Without passing parameters
- code
console.log(pure.random.hexaDecimal());- result
'6'Describing that i want the string to feature 3 chars
- code
console.log(pure.random.hexaDecimal(3));- result
'e24'