Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit d9e49d5

Browse files
authored
v1.3.1
1 parent 5b29b58 commit d9e49d5

17 files changed

Lines changed: 287 additions & 313 deletions

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easyscriptjs",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Easy Script is a npm package which makes coding in JavaScript easy!",
55
"main": "src/index.js",
66
"types": "src/index.d.ts",

src/index.d.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
export function flip(): 0 | 1;
22
export function id(length: number, amount?: 1): string;
33
export function id(length: number, amount?: number): string[];
4-
export function log(...input: any[]): void;
54
export function print(...input: any[]): void;
65
export function random(max?: number): number;
76
export function uuid(amount?: 1): string;
87
export function uuid(amount?: number): string[];
98

109
export declare const util: {
11-
boolToNum(boolean: boolean): 0 | 1;
12-
boolToStr(boolean: boolean): "true" | "false";
13-
numToBool(number: 0 | 1): boolean;
10+
boolToNum<B extends boolean>(boolean: B): B extends true ? 1 : 0;
11+
boolToStr<B extends boolean>(boolean: B): B extends true ? "true" : false;
12+
numToBool<N extends 0 | 1>(number: N): N extends 1 ? true : false;
1413
numToStr<N extends number>(number: N): `${N}`;
15-
removeDuplicates(
16-
arr: any[],
17-
multi_dim?: boolean,
18-
truthy_only?: boolean,
19-
sort_by?: "alphabetic" | "numeric" | "lengthwise" | "none"
20-
): any[];
21-
strToBool(string: string): boolean;
14+
removeDuplicates(arr: any[], multi_dim?: boolean, truthy_only?: boolean, sort_by?: "alphabetic" | "numeric" | "lengthwise" | "none"): any[];
15+
strToBool<S extends "true" | "false">(string: S): S extends "true" ? true : false;
2216
strToNum(string: string): number;
2317
};

src/index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
module.exports = {
2-
flip: require("./modules/flip"),
3-
id: require("./modules/id"),
4-
log: require("./modules/log"),
5-
print: require("./modules/print"),
6-
random: require("./modules/random"),
7-
util: {
8-
boolToNum: require("./modules/util/boolToNum"),
9-
boolToStr: require("./modules/util/boolToStr"),
10-
numToBool: require("./modules/util/numToBool"),
11-
numToStr: require("./modules/util/numToStr"),
12-
removeDuplicates: require("./modules/util/removeDuplicates"),
13-
strToBool: require("./modules/util/strToBool"),
14-
strToNum: require("./modules/util/strToNum")
15-
},
16-
uuid: require("./modules/uuid")
17-
}
1+
module.exports = {
2+
flip: require("./modules/flip"),
3+
id: require("./modules/id"),
4+
print: require("./modules/print"),
5+
random: require("./modules/random"),
6+
util: {
7+
boolToNum: require("./modules/util/boolToNum"),
8+
boolToStr: require("./modules/util/boolToStr"),
9+
numToBool: require("./modules/util/numToBool"),
10+
numToStr: require("./modules/util/numToStr"),
11+
removeDuplicates: require("./modules/util/removeDuplicates"),
12+
strToBool: require("./modules/util/strToBool"),
13+
strToNum: require("./modules/util/strToNum"),
14+
},
15+
uuid: require("./modules/uuid"),
16+
};

src/modules/flip.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/**
2-
* @function `flip` - Quickly execute a heads or tails decision randomly
3-
* @returns { Number } - Returns 1 for heads or 0 for tails
4-
*/
5-
6-
module.exports = function flip() {
7-
return Math.random() >= 0.5 ? 1 : 0;
8-
}
1+
/**
2+
* @function `flip` - Quickly execute a heads or tails decision randomly
3+
* @returns { Number } - Returns 1 for heads or 0 for tails
4+
*/
5+
6+
module.exports = function flip() {
7+
return Math.random() >= 0.5 ? 1 : 0;
8+
};

src/modules/id.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
/**
2-
* @function `id` - Generate a unique ID composed of random characters and numbers.
3-
* @param { Number } [length] - The length of each ID.
4-
* @param { Number } [amount] - The amount of IDs to generate. Condition: **`1 < amount < 64`**
5-
* @returns { string | string[] } - Returns an array if the amount inputted is above 1, else returns a string.
6-
*/
7-
8-
const { customAlphabet } = require("nanoid");
9-
10-
module.exports = function id(length, amount) {
11-
if (!length) throw new SyntaxError("No length specified");
12-
if (typeof length !== "number") throw new TypeError("Length must be Number type");
13-
14-
let ids = 1;
15-
16-
if (amount && !isFinite(amount)) throw new TypeError("Amount must be Number type");
17-
if ((amount && amount < 1) || (amount && amount >= 64)) throw new RangeError("Amount must be equal or higher than 1 and lower than 64");
18-
19-
if (amount) ids = amount;
20-
21-
let generatedIds = [];
22-
23-
let i = 0;
24-
25-
do {
26-
const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", length );
27-
const id = nanoid();
28-
29-
generatedIds.push(id);
30-
31-
i++;
32-
} while (i < amount);
33-
34-
if (generatedIds.length === 1) return generatedIds[0];
35-
36-
return generatedIds;
37-
}
1+
/**
2+
* @function `id` - Generate a unique ID composed of random characters and numbers.
3+
* @param { Number } [length] - The length of each ID.
4+
* @param { Number } [amount] - The amount of IDs to generate. Condition: **`1 < amount < 64`**
5+
* @returns { string | string[] } - Returns an array if the amount inputted is above 1, else returns a string.
6+
*/
7+
8+
const { customAlphabet } = require("nanoid");
9+
10+
module.exports = function id(length, amount) {
11+
if (!length) throw new SyntaxError("No length specified");
12+
if (typeof length !== "number") throw new TypeError("Length must be Number type");
13+
14+
let ids = 1;
15+
16+
if (amount && !isFinite(amount)) throw new TypeError("Amount must be Number type");
17+
if ((amount && amount < 1) || (amount && amount >= 64)) throw new RangeError("Amount must be equal or higher than 1 and lower than 64");
18+
19+
if (amount) ids = amount;
20+
21+
let generatedIds = [];
22+
23+
let i = 0;
24+
25+
do {
26+
const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", length);
27+
const id = nanoid();
28+
29+
generatedIds.push(id);
30+
31+
i++;
32+
} while (i < amount);
33+
34+
if (generatedIds.length === 1) return generatedIds[0];
35+
36+
return generatedIds;
37+
};

src/modules/log.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/modules/print.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* @function `print` - Quickly log any data to the console.
3-
* @param { any } [input] - *Required* The data that will be passed on to the console.
4-
* @returns { void } - An instance of console.log() that is executed using `input`.
5-
*/
6-
7-
module.exports = function print(input) {
8-
if (!input) throw new SyntaxError("No input specified");
9-
10-
return console.log(input);
11-
}
1+
/**
2+
* @function `print` - Quickly log any data to the console.
3+
* @param { any } [input] - *Required* The data that will be passed on to the console.
4+
* @returns { void } - An instance of console.log() that is executed using `input`.
5+
*/
6+
7+
module.exports = function print(input) {
8+
if (!input) throw new SyntaxError("No input specified");
9+
10+
return console.log(input);
11+
};

src/modules/random.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
/**
2-
* @function `random` - Used to generate a random number between 1 and a max value.
3-
* @param { Number } [min] - The min value used.
4-
* @param { Number } [max] - The max value used.
5-
* @returns { Number } - A random number between 1 and max (*parameter*). If max is *undefined*, will return a random number between 1 and 100.
6-
*/
7-
8-
module.exports = function random(min, max) {
9-
if (max && !isFinite(max) || min && !isFinite(min)) throw new TypeError("Parameter number must be a number");
10-
if (min >= max) throw new RangeError("Parameter min must be less than max");
11-
else if (min <= 0 && min >= max) throw new RangeError("Parameter max must be greater than min");
12-
13-
return Math.floor(Math.random() * (max - min + 1) + min);
14-
}
1+
/**
2+
* @function `random` - Used to generate a random number between 1 and a max value.
3+
* @param { Number } [min] - The min value used.
4+
* @param { Number } [max] - The max value used.
5+
* @returns { Number } - A random number between 1 and max (*parameter*). If max is *undefined*, will return a random number between 1 and 100.
6+
*/
7+
8+
module.exports = function random(min, max) {
9+
if ((max && !isFinite(max)) || (min && !isFinite(min))) throw new TypeError("Parameter number must be a number");
10+
if (min >= max) throw new RangeError("Parameter min must be less than max");
11+
if (min <= 0 && min >= max) throw new RangeError("Parameter max must be greater than min");
12+
13+
return Math.floor(Math.random() * (max - min + 1) + min);
14+
};

src/modules/util/boolToNum.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* @function `boolToNum` - Convert a boolean to a number.
3-
* @param { Boolean } [boolean] - *Required* The boolean to be converted.
4-
* @returns { Number } - The output of the conversion.
5-
*/
6-
7-
module.exports = function boolToNum(boolean) {
8-
if (typeof boolean !== "boolean") throw new TypeError("No boolean provided");
9-
10-
return boolean === true ? 1 : 0;
11-
}
1+
/**
2+
* @function `boolToNum` - Convert a boolean to a number.
3+
* @param { Boolean } [boolean] - *Required* The boolean to be converted.
4+
* @returns { Number } - The output of the conversion.
5+
*/
6+
7+
module.exports = function boolToNum(boolean) {
8+
if (typeof boolean !== "boolean") throw new TypeError("No boolean provided");
9+
10+
return boolean === true ? 1 : 0;
11+
};

0 commit comments

Comments
 (0)