@almighty-shogun/prototype-extensions 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/array.d.ts +12 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/array.js +22 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/number.d.ts +8 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/number.js +7 -0
- package/dist/string.d.ts +12 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +22 -0
- package/package.json +38 -0
- package/src/array.ts +41 -0
- package/src/index.ts +5 -0
- package/src/number.ts +16 -0
- package/src/string.ts +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Prototype Extensions
|
|
2
|
+
|
|
3
|
+
A small package that adds extensions to existing prototypes like string, array, etc.
|
|
4
|
+
|
|
5
|
+
## 📃 Prerequisites
|
|
6
|
+
- **[Node.js](https://nodejs.org/en/)**: >= v23.11.1
|
|
7
|
+
|
|
8
|
+
## 💻 Installation
|
|
9
|
+
|
|
10
|
+
### Step 1
|
|
11
|
+
Install the package using your package manager of choice.
|
|
12
|
+
```shell
|
|
13
|
+
bun add @almighty-shogun/prototype-extensions
|
|
14
|
+
yarn add @almighty-shogun/prototype-extensions
|
|
15
|
+
npm install @almighty-shogun/prototype-extensions
|
|
16
|
+
pnpm install @almighty-shogun/prototype-extensions
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Step 2
|
|
20
|
+
Import the package in the main file of your project.
|
|
21
|
+
```ts
|
|
22
|
+
import '@almighty-shogun/prototype-extensions'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 📦 Building
|
|
26
|
+
- Use the command `bun install` in the root directory to install the required dependencies.
|
|
27
|
+
- Run `bun --cwd packages/prototype-extensions build` to build the package.
|
package/dist/array.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Array<T> {
|
|
3
|
+
first(): T;
|
|
4
|
+
last(): T;
|
|
5
|
+
delete(index: number): T[];
|
|
6
|
+
removeDuplicates(this: Array<string | number>): (string | number)[];
|
|
7
|
+
addOrRemove(this: Array<string | number>, value: string | number): (string | number)[];
|
|
8
|
+
isEmpty(): boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,KAAK,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,CAAC;QACX,IAAI,IAAI,CAAC,CAAC;QACV,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,CAAC;QAClE,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,CAAC;QAErF,OAAO,IAAI,OAAO,CAAC;KACtB;CACJ;AA8BD,OAAO,EAAE,CAAC"}
|
package/dist/array.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Array.prototype.first = function () {
|
|
2
|
+
return this[0];
|
|
3
|
+
};
|
|
4
|
+
Array.prototype.last = function () {
|
|
5
|
+
return this[this.length - 1];
|
|
6
|
+
};
|
|
7
|
+
Array.prototype.delete = function (index) {
|
|
8
|
+
return this.toSpliced(index, 1);
|
|
9
|
+
};
|
|
10
|
+
Array.prototype.removeDuplicates = function () {
|
|
11
|
+
return Array.from(new Set(this).values());
|
|
12
|
+
};
|
|
13
|
+
Array.prototype.addOrRemove = function (value) {
|
|
14
|
+
if (this.includes(value)) {
|
|
15
|
+
return this.delete(this.indexOf(value));
|
|
16
|
+
}
|
|
17
|
+
return [...this, value];
|
|
18
|
+
};
|
|
19
|
+
Array.prototype.isEmpty = function () {
|
|
20
|
+
return this.length === 0;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAA;AAChB,OAAO,UAAU,CAAA;AACjB,OAAO,UAAU,CAAA;AAEjB,OAAO,EAAE,CAAC"}
|
package/dist/index.js
ADDED
package/dist/number.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAC/B,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAChD;CACJ;AAUD,OAAO,EAAE,CAAC"}
|
package/dist/number.js
ADDED
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface String {
|
|
3
|
+
toSlug(): string;
|
|
4
|
+
append(value: string): string;
|
|
5
|
+
limit(length: number, appending: string | null): string;
|
|
6
|
+
toNumber(): number;
|
|
7
|
+
isEmpty(): boolean;
|
|
8
|
+
equals(value: string): boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,MAAM,IAAI,MAAM,CAAC;QACjB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QAC9B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAC,IAAI,GAAG,MAAM,CAAC;QAEtD,QAAQ,IAAI,MAAM,CAAC;QACnB,OAAO,IAAI,OAAO,CAAC;QACnB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;KAClC;CACJ;AA6BD,OAAO,EAAE,CAAC"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
String.prototype.toSlug = function () {
|
|
2
|
+
return this.trim().toLowerCase()
|
|
3
|
+
.replace(/[^\w\s-]+/g, "")
|
|
4
|
+
.replace(/[\s_-]+/g, "-")
|
|
5
|
+
.replace(/^-+|-+$/g, "");
|
|
6
|
+
};
|
|
7
|
+
String.prototype.toNumber = function () {
|
|
8
|
+
return Number(this);
|
|
9
|
+
};
|
|
10
|
+
String.prototype.isEmpty = function () {
|
|
11
|
+
return this.length === 0;
|
|
12
|
+
};
|
|
13
|
+
String.prototype.equals = function (value) {
|
|
14
|
+
return this === value;
|
|
15
|
+
};
|
|
16
|
+
String.prototype.append = function (value) {
|
|
17
|
+
return this + value;
|
|
18
|
+
};
|
|
19
|
+
String.prototype.limit = function (length, appending = null) {
|
|
20
|
+
return this.length > length ? this.substring(0, length) + appending : this;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@almighty-shogun/prototype-extensions",
|
|
3
|
+
"description": "A small package that adds extensions to existing prototypes like string, array, etc.",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"provenance": true
|
|
13
|
+
},
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "Almighty-Shogun",
|
|
16
|
+
"email": "alm1ghtyshogun1998@gmail.com",
|
|
17
|
+
"url": "https://shogun.ms"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Almighty-Shogun/packages.git",
|
|
22
|
+
"directory": "packages/prototype-extensions"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"typings": "./dist/index.d.ts",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"src",
|
|
36
|
+
"dist"
|
|
37
|
+
]
|
|
38
|
+
}
|
package/src/array.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Array<T> {
|
|
3
|
+
first(): T;
|
|
4
|
+
last(): T;
|
|
5
|
+
delete(index: number): T[];
|
|
6
|
+
removeDuplicates(this: Array<string | number>): (string|number)[];
|
|
7
|
+
addOrRemove(this: Array<string | number>, value: string | number): (string|number)[];
|
|
8
|
+
|
|
9
|
+
isEmpty(): boolean;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Array.prototype.first = function<T> (this: T[]): T {
|
|
14
|
+
return this[0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Array.prototype.last = function<T> (this: T[]): T {
|
|
18
|
+
return this[this.length - 1];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Array.prototype.delete = function<T> (this: T[], index: number): T[] {
|
|
22
|
+
return this.toSpliced(index, 1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Array.prototype.removeDuplicates = function (this: (string|number)[]): (string|number)[] {
|
|
26
|
+
return Array.from(new Set(this).values());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Array.prototype.addOrRemove = function (this: (string|number)[], value: string|number): (string|number)[] {
|
|
30
|
+
if (this.includes(value)) {
|
|
31
|
+
return this.delete(this.indexOf(value));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [...this, value];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Array.prototype.isEmpty = function<T> (this: T[]): boolean {
|
|
38
|
+
return this.length === 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {};
|
package/src/index.ts
ADDED
package/src/number.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Number {
|
|
3
|
+
equals(value: number): boolean;
|
|
4
|
+
isInRange(min: number, max: number): boolean;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
Number.prototype.equals = function (this: number, value: number): boolean {
|
|
9
|
+
return this === value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Number.prototype.isInRange = function (this: number, min: number, max: number): boolean {
|
|
13
|
+
return this >= min && this <= max;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {};
|
package/src/string.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface String {
|
|
3
|
+
toSlug(): string;
|
|
4
|
+
append(value: string): string;
|
|
5
|
+
limit(length: number, appending: string|null): string;
|
|
6
|
+
|
|
7
|
+
toNumber(): number;
|
|
8
|
+
isEmpty(): boolean;
|
|
9
|
+
equals(value: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
String.prototype.toSlug = function (this: string): string {
|
|
14
|
+
return this.trim().toLowerCase()
|
|
15
|
+
.replace(/[^\w\s-]+/g, "")
|
|
16
|
+
.replace(/[\s_-]+/g, "-")
|
|
17
|
+
.replace(/^-+|-+$/g, "");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
String.prototype.toNumber = function (this: string): number {
|
|
21
|
+
return Number(this);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
String.prototype.isEmpty = function (this: string): boolean {
|
|
25
|
+
return this.length === 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
String.prototype.equals = function (this: string, value: string): boolean {
|
|
29
|
+
return this === value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
String.prototype.append = function (this: string, value: string): string {
|
|
33
|
+
return this + value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
String.prototype.limit = function (this: string, length: number, appending: string|null = null): string {
|
|
37
|
+
return this.length > length ? this.substring(0, length) + appending : this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {};
|