rnget v1.0.1
🔮 rnget
Useful JavaScript library for generating random data.
Installation
npm install rnget
Examples
const Random = require("rnget");
Random.characterSequence({
length: 30,
uCharacters: false,
lCharacters: true,
specialSymbols: true,
numbers: true
});
// k)$1[icoee00:c=z\e6olmznr@0g3o
Random.characterSequence({
length: 30,
uCharacters: false,
lCharacters: false,
specialSymbols: true,
numbers: true
});
// .45.23@05@04320>0;363:25-4+063
Random.color.HEX(); // #e38651
Random.color.CMYK(); // cmyk(71%, 43%, 26%, 70%)
Random.color.name(); // darkblue
Random.elementFromObject.objProp({
name: "John",
age: 22,
nationality: "French"
});
// { nationality: 'French' }
Random.elementFromObject.objKeyVal({
name: "Alex",
age: 37,
nationality: "Italian"
});
// Alex
Random.elementFromArray({
array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
startingFromIndex: 4,
endingWithIndex: 7
})
// 7
Documentation
.number([options])
Generates a random number in a specific range. Parameter | Type | Required | Description :----: | :----: | :----: | :----: range | Array | yes | The range of numbers in which the number will be generated.
Example:
Random.number({ range: [1, 100] });
.numbers([options])
Generates an array of random numbers in a specific range.
Parameter | Type | Required | Description |
---|---|---|---|
range | Array | yes | The range in which the numbers will be generated. |
quantity | Number | yes | The number of random numbers to be generated. |
Example:
Random.numbers({ range: [1, 100], quantity: 10 })
.elementFromArray([options])
Returns a random element from an array.
Parameter | Type | Required | Description |
---|---|---|---|
array | Array | yes | Array of elements. |
startingFromIndex | Number | no | - |
endingWithIndex | Number | no | - |
Example:
Random.elementFromArray({ array: [0, true, 2, false, 4, "str"], startingFromIndex: 2 })
.elementsFromArray([options])
Returns an array of random elements from an array.
Parameter | Type | Required | Description |
---|---|---|---|
array | Array | yes | Array of elements. |
quantity | Number | yes | The number of random elements from the array. |
startingFromIndex | Number | no | - |
endingWithIndex | Number | no | - |
Example:
Random.elementsFromArray({ array: [false, false, "str", 3, 4, 5], quantity: 3, endingWithIndex: 4 })
.elementFromObject.objKey(object)
Returns a random key from an object.
Example:
Random.elementFromObject.objKey({ one: 1, two: 2, three: 3 })
.elementFromObject.objKeyVal(object)
Returns the value of a random key from an object.
Example:
Random.elementFromObject.objKeyVal({ name: "John", age: 22, nationality: "Italian" })
.elementFromObject.objProp(object)
Returns a random property from an object.
Example:
Random.elementFromObject.objProp({ name: "Alex", age: "37", "favorite color": "yellow" })
.color.HEX()
Generates a random HEX color.
.color.RGB()
Generates a random RGB color.
.color.HSL()
Generates a random HSL color.
.color.HWB()
Generates a random HWB color.
.color.CMYK()
Generates a random CMYK color.
.color.name()
Generates a random color name.
.characterSequence([options])
Generates a random sequence of characters.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
length | Number | yes | - | Length of character sequence. |
lCharacters | Boolean | no | true | Can a character sequence contain lowercase letters? |
uCharacters | Boolean | no | true | Can a character sequence contain uppercase letters? |
numbers | Boolean | no | false | Can a character sequence contain numbers? |
specialSymbols | Boolean | no | false | Can a character sequence contain special symbols? |
Example:
Random.characterSequence({
length: 100,
lCharacters: false,
uCharacters: false,
numbers: true,
specialSymbols: true
})
Found a bug?
Contact me by email: alex30955@aol.com.