Basic
This is a basic module, it contains integer, float, string, boolean, and date types.
Boolean
Section titled “Boolean”dunna.basic.boolean() returns a random boolean value.
// Use default likelihood = 50dunna.basic.boolean(); // truedunna.basic.boolean(); // falsedunna.basic.boolean(); // false
// Modify likelihooddunna.basic.boolean({ likelihood: 80 }); // The output has chance of 80% to be truedunna.basic.boolean({ likelihood: 20 }); // The output has chance of 20% to be true| Parameter | Type | Description | Default |
|---|---|---|---|
| likelihood | number | The likelihood of the output being true | 50 |
Integer
Section titled “Integer”dunna.basic.integer() returns a random integer between 0 (not inclusive) and 10 (inclusive)
dunna.basic.integer(); // 4dunna.basic.integer(); // 7dunna.basic.integer(); // 4
// Customize parametersdunna.integer({ min: 1, max: 100 });dunna.integer({ min: -10, max: 10 });| Parameter | Type | Description | Default |
|---|---|---|---|
| min | number | The minimum value of the output (inclusive) | 0 |
| max | number | The maximum value of the output (not inclusive) | 10 |
dunna.basic.float() returns a random float number between 0 (inclusive) and 10 (not inclusive)
dunna.basic.float(); // 4.364dunna.basic.float(); // 8.834
// Parametersdunna.float({ min: 3, max: 36, fixed: 5 });| Parameter | Type | Description | Default |
|---|---|---|---|
| min | number | The minimum value of the output (inclusive) | 0 |
| max | number | The maximum value of the output (not inclusive) | 10 |
| fixed | number | The number of decimal places | 3 |
Letter
Section titled “Letter”dunna.basic.letter() returns a random uppercase or lowercase letter
dunna.basic.letter(); // hdunna.basic.letter(); // E
// Parametersdunna.basic.letter({ casing: "upper" });| Parameter | Type | Description | Default |
|---|---|---|---|
| casing | string | The casing of the output letter (upper/lower/any) | “any” |
Choice
Section titled “Choice”dunna.basic.choice(array) returns a random element from an array
dunna.basic.choice(["Alice", "Bob", "Charlie"]); // Alicedunna.basic.choice(["Alice", "Bob", "Charlie"]); // Charlie| Parameter | Type | Description | Default |
|---|---|---|---|
| array | T[] | The array to be randomly selected | null |
dunna.basic.pick(count, array) returns a random subset of the given array with the given count
dunna.basic.pick(3, [2, 1, 6, 3, 4]); // [6, 4, 1]dunna.basic.pick(2, ["Alice", "Bob", "Charlie"]); // ['Bob', 'Charlie']| Parameter | Type | Description | Default |
|---|---|---|---|
| count | number | The number of elements to be picked | null |
| array | T[] | The array to be randomly selected | null |
dunna.basic.omit(count, array) returns a random subset of the given array by omitting elements based on the given count
dunna.basic.omit(2, [2, 1, 6, 3, 4]); // [1, 6 ,4]dunna.basic.omit(2, ["Alice", "Bob", "Charlie"]); // ['Bob']| Parameter | Type | Description | Default |
|---|---|---|---|
| count | number | The number of elements to be omitted | null |
| array | T[] | The array to be randomly selected | null |