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

Commit c99b298

Browse files
authored
v1.2.4
A release cleaning up some code and updating JSDocs.
1 parent 316dc92 commit c99b298

18 files changed

Lines changed: 74 additions & 158 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.2.3",
3+
"version": "1.2.4",
44
"description": "Easy Script is a npm package which makes coding in JavaScript easy!",
55
"main": "src/index.js",
66
"scripts": {},

src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const modules = {
1+
module.exports = {
22
dns: {
33
a: require("./modules/dns/a"),
4-
cname: require("./modules/dns/cname"),
4+
cname: require("./modules/dns/cname")
55
},
66
flip: require("./modules/flip"),
77
id: require("./modules/id"),
@@ -19,5 +19,3 @@ const modules = {
1919
},
2020
uuid: require("./modules/uuid")
2121
}
22-
23-
module.exports = modules;

src/modules/dns/a.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/**
22
* @function `validateARecord` - Validate an A record
3+
* @param { String } [record] - *Required* The record to be validated.
34
* @returns { Boolean } - Returns true if valid, returns false if invalid
45
*/
56

6-
function validateARecord(record) {
7+
module.exports = function validateARecord(record) {
78
const regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
89

910
return regex.test(record);
1011
}
11-
12-
module.exports = validateARecord;

src/modules/dns/cname.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/**
22
* @function `validateCNAMERecord` - Validate a CNAME record
3+
* @param { String } [record] - *Required* The record to be validated.
34
* @returns { Boolean } - Returns true if valid, returns false if invalid
45
*/
56

6-
function validateCNAMERecord(record) {
7+
module.exports = function validateCNAMERecord(record) {
78
const regex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
89

910
return regex.test(record);
1011
}
11-
12-
module.exports = validateCNAMERecord;

src/modules/flip.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* @returns { Number } - Returns 1 for heads or 0 for tails
44
*/
55

6-
function flip() {
6+
module.exports = function flip() {
77
return Math.random() >= 0.5 ? 1 : 0;
88
}
9-
10-
module.exports = flip;

src/modules/id.js

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
1-
const { customAlphabet } = require("nanoid");
2-
31
/**
42
* @function `id` - Generate a unique ID composed of random characters and numbers.
53
* @param { Number } [length] - The length of each ID.
64
* @param { Number } [amount] - The amount of IDs to generate. Condition: **`1 < amount < 64`**
7-
* @returns { Array } - Returns an array if the amount inputted is above 1.
8-
* @returns { String } - Returns a string if the amount inputted is equal to 1.
5+
* @returns { string | string[] } - Returns an array if the amount inputted is above 1, else returns a string.
96
*/
107

11-
function generateId(length, amount) {
12-
let ids = [];
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 = [];
1322

1423
let i = 0;
1524

1625
do {
1726
const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", length );
1827
const id = nanoid();
1928

20-
ids.push(id);
29+
generatedIds.push(id);
2130

2231
i++;
2332
} while (i < amount);
2433

25-
if (ids.length === 1) ids = ids[0];
34+
if (generatedIds.length === 1) return generatedIds[0];
2635

27-
return ids;
36+
return generatedIds;
2837
}
29-
30-
function id(length, amount) {
31-
if (!length) throw new SyntaxError("No length specified");
32-
if (typeof length !== "number") throw new TypeError("Length must be Number type");
33-
34-
let ids = 1;
35-
36-
if (amount && !isFinite(amount)) throw new TypeError("Amount must be Number type");
37-
if ((amount && amount < 1) || (amount && amount >= 64)) throw new RangeError("Amount must be equal or higher than 1 and lower than 64");
38-
39-
if (amount) ids = amount;
40-
41-
return generateId(length, amount);
42-
}
43-
44-
module.exports = id;

src/modules/log.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/**
22
* @function `log` - Quickly log any data to the console.
3-
* @param { any } input - *Required* The data that will be passed on to the console.
4-
* @returns { Function } - An instance of console.log() that is executed using `input`
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`.
55
*/
66

7-
function log(input) {
7+
module.exports = function log(input) {
88
if (!input) throw new SyntaxError("No input specified");
99

1010
return console.log(input);
1111
}
12-
13-
module.exports = log;

src/modules/print.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/**
22
* @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 { Function } - An instance of console.log() that is executed using `input`
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`.
55
*/
66

7-
function print(input) {
7+
module.exports = function print(input) {
88
if (!input) throw new SyntaxError("No input specified");
99

1010
return console.log(input);
1111
}
12-
13-
module.exports = print;

src/modules/random.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @returns { Number } - A random number between 1 and max (*parameter*). If max is *undefined*, will return a random number between 1 and 100.
55
*/
66

7-
function random(max) {
7+
module.exports = function random(max) {
88
let highest = 100;
99

1010
if (max && !isFinite(max)) throw new TypeError("Max number must be a number");
@@ -16,5 +16,3 @@ function random(max) {
1616

1717
return result;
1818
}
19-
20-
module.exports = random;

0 commit comments

Comments
 (0)