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

Commit b8c7a62

Browse files
authored
v1.2.3
A release adding new modules and features.
1 parent 9c2e59a commit b8c7a62

6 files changed

Lines changed: 63 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<img src="https://images.easyscript.dev/banner.png">
33
</p>
44

5+
<h1 align="center">✨ Easy Script</h1>
6+
57
<p align="center">
68
<img alt="Lastest Release" src="https://img.shields.io/github/v/release/easyscriptjs/easyscript?style=for-the-badge">
79
<img alt="GitHub Issues" src="https://img.shields.io/github/issues-raw/easyscriptjs/easyscript?label=Issues&style=for-the-badge">
810
<img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr-raw/easyscriptjs/easyscript?label=Pull%20Requests&style=for-the-badge">
911
</p>
1012

11-
<h1 align="center">✨ Easy Script</h1>
12-
1313
<p align="center">Easy Script is a npm package which makes coding in JavaScript easy!</p>
1414

1515
## 📊 Installation

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
const modules = {
2+
dns: {
3+
a: require("./modules/dns/a"),
4+
cname: require("./modules/dns/cname"),
5+
},
26
flip: require("./modules/flip"),
37
id: require("./modules/id"),
48
log: require("./modules/log"),

src/modules/dns/a.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @function `validateARecord` - Validate an A record
3+
* @returns { Boolean } - Returns true if valid, returns false if invalid
4+
*/
5+
6+
function validateARecord(record) {
7+
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]?)$/;
8+
9+
return regex.test(record);
10+
}
11+
12+
module.exports = validateARecord;

src/modules/dns/cname.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @function `validateCNAMERecord` - Validate a CNAME record
3+
* @returns { Boolean } - Returns true if valid, returns false if invalid
4+
*/
5+
6+
function validateCNAMERecord(record) {
7+
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])$/;
8+
9+
return regex.test(record);
10+
}
11+
12+
module.exports = validateCNAMERecord;

src/modules/id.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@ const { customAlphabet } = require("nanoid");
22

33
/**
44
* @function `id` - Generate a unique ID composed of random characters and numbers.
5-
* @param { Number } length - *Required* The length of the ID.
6-
* @returns { String } - A unique ID string of a specified length (e.g. abthvmyt3h1j3it)
5+
* @param { Number } [length] - The length of each ID.
6+
* @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.
79
*/
810

9-
function id(length) {
11+
function generateId(length, amount) {
12+
let ids = [];
13+
14+
let i = 0;
15+
16+
do {
17+
const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", length );
18+
const id = nanoid();
19+
20+
ids.push(id);
21+
22+
i++;
23+
} while (i < amount);
24+
25+
if (ids.length === 1) ids = ids[0];
26+
27+
return ids;
28+
}
29+
30+
function id(length, amount) {
1031
if (!length) throw new SyntaxError("No length specified");
11-
if (typeof length !== "number") throw new TypeError("Invalid type 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");
1238

13-
const nanoid = customAlphabet(
14-
"1234567890abcdefghijklmnopqrstuvwxyz",
15-
length
16-
);
17-
const id = nanoid();
39+
if (amount) ids = amount;
1840

19-
return id;
41+
return generateId(length, amount);
2042
}
2143

2244
module.exports = id;

src/modules/uuid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @function `uuid` - Generate a unique UUID composed of random characters and numbers. UUIDs follow this rule: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
3-
* @param { Number } [number] - The amount of UUID's to generate. Condition: **`1 < amount < 64`**
3+
* @param { Number } [number] - The amount of UUIDs to generate. Condition: **`1 < amount < 64`**
44
* @returns { Array } - Returns an array if the amount inputted is above 1.
55
* @returns { String } - Returns a string if the amount inputted is equal to 1.
66
*/

0 commit comments

Comments
 (0)