jsfunx 1.0.0
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/LICENSE +20 -0
- package/README.md +256 -0
- package/jsfunx.cjs +1641 -0
- package/jsfunx.mjs +1646 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2025 Khiat Mohammed Abderrezzak
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# jsfunx
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/jsfunx)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.npmjs.com/package/jsfunx)
|
|
6
|
+
|
|
7
|
+
The main reason why this library was created is to:
|
|
8
|
+
|
|
9
|
+
### use
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { isType, number } from "jsfunx"; // ESM
|
|
13
|
+
|
|
14
|
+
// or
|
|
15
|
+
|
|
16
|
+
// const { isType, number } = require("jsfunx"); // CJS
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Adds two numbers together and returns the result.
|
|
20
|
+
*
|
|
21
|
+
* @param {number} num1 - The first number.
|
|
22
|
+
* @param {number} num2 - The second number.
|
|
23
|
+
* @returns {number} The sum of `num1` and `num2`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function add(num1, num2) {
|
|
27
|
+
// 35 char
|
|
28
|
+
|
|
29
|
+
if (isType([num1, num2], number)) {
|
|
30
|
+
return num1 + num2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw TypeError("invalid arguments");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(add(1, 3));
|
|
37
|
+
|
|
38
|
+
// or
|
|
39
|
+
|
|
40
|
+
console.log(add(Number(1), Number(3)));
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### in place of
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
/**
|
|
47
|
+
* Adds two numbers together and returns the result.
|
|
48
|
+
*
|
|
49
|
+
* @param {number} num1 - The first number.
|
|
50
|
+
* @param {number} num2 - The second number.
|
|
51
|
+
* @returns {number} The sum of `num1` and `num2`.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
function add(num1, num2) {
|
|
55
|
+
// 59 char
|
|
56
|
+
|
|
57
|
+
if (typeof num1 === "number" && typeof num2 === "number") {
|
|
58
|
+
return num1 + num2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw new TypeError("invalid arguments");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log(add(1, 3));
|
|
65
|
+
|
|
66
|
+
// or
|
|
67
|
+
|
|
68
|
+
console.log(add(Number(1), Number(3)));
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### and
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { isType, number, string } from "jsfunx"; // ESM
|
|
75
|
+
|
|
76
|
+
// or
|
|
77
|
+
|
|
78
|
+
// const { isType, number, string } = require("jsfunx"); // CJS
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Prints a message with the given name and age.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} name - The person's name.
|
|
84
|
+
* @param {number} age - The person's age.
|
|
85
|
+
* @returns {void} This function does not return a value.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
function fun(name, age) {
|
|
89
|
+
// 44 char
|
|
90
|
+
|
|
91
|
+
if (isType([name, age], [string, number])) {
|
|
92
|
+
console.log(`your name is ${name} and your age is ${age}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
throw new TypeError("invalid arguments");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fun("mohamed", 23);
|
|
100
|
+
|
|
101
|
+
// or
|
|
102
|
+
|
|
103
|
+
fun(String("mohamed"), Number(23));
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### in place of
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
/**
|
|
110
|
+
* Prints a message with the given name and age.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} name - The person's name.
|
|
113
|
+
* @param {number} age - The person's age.
|
|
114
|
+
* @returns {void} This function does not return a value.
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
function fun(name, age) {
|
|
118
|
+
// 58 char
|
|
119
|
+
|
|
120
|
+
if (typeof name === "string" && typeof age === "number") {
|
|
121
|
+
console.log(`your name is ${name} and your age is ${age}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
throw new TypeError("invalid arguments");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fun("mohamed", 23);
|
|
129
|
+
|
|
130
|
+
// or
|
|
131
|
+
|
|
132
|
+
fun(String("mohamed"), Number(23));
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### and
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import { instancesof } from "jsfunx"; // ESM
|
|
139
|
+
|
|
140
|
+
// or
|
|
141
|
+
|
|
142
|
+
// const { instancesof } = require("jsfunx"); // CJS
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Adds two numbers together and returns the result.
|
|
146
|
+
*
|
|
147
|
+
* @param {number} num1 - The first number.
|
|
148
|
+
* @param {number} num2 - The second number.
|
|
149
|
+
* @returns {number} The sum of `num1` and `num2`.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
function add(num1, num2) {
|
|
153
|
+
// 40 char
|
|
154
|
+
|
|
155
|
+
if (instancesof([num1, num2], Number)) {
|
|
156
|
+
return num1 + num2;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
throw TypeError("invalid arguments");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(add(new Number(1), new Number(3)));
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### in place of
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
/**
|
|
169
|
+
* Adds two numbers together and returns the result.
|
|
170
|
+
*
|
|
171
|
+
* @param {number} num1 - The first number.
|
|
172
|
+
* @param {number} num2 - The second number.
|
|
173
|
+
* @returns {number} The sum of `num1` and `num2`.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
function add(num1, num2) {
|
|
177
|
+
// 55 char
|
|
178
|
+
|
|
179
|
+
if (num1 instanceof Number && num2 instanceof Number) {
|
|
180
|
+
return num1 + num2;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
throw new TypeError("invalid arguments");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log(add(new Number(1), new Number(3)));
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### and
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
import { instancesof } from "jsfunx"; // ESM
|
|
193
|
+
|
|
194
|
+
// or
|
|
195
|
+
|
|
196
|
+
// const { instancesof } = require("jsfunx"); // CJS
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Prints a message with the given name and age.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} name - The person's name.
|
|
202
|
+
* @param {number} age - The person's age.
|
|
203
|
+
* @returns {void} This function does not return a value.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
function fun(name, age) {
|
|
207
|
+
// 49 char
|
|
208
|
+
|
|
209
|
+
if (instancesof([name, age], [String, Number])) {
|
|
210
|
+
console.log(`your name is ${name} and your age is ${age}`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
throw new TypeError("invalid arguments");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
fun(new String("mohamed"), new Number(23));
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### in place of
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
/**
|
|
223
|
+
* Prints a message with the given name and age.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} name - The person's name.
|
|
226
|
+
* @param {number} age - The person's age.
|
|
227
|
+
* @returns {void} This function does not return a value.
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
function fun(name, age) {
|
|
231
|
+
// 54 char
|
|
232
|
+
|
|
233
|
+
if (name instanceof String && age instanceof Number) {
|
|
234
|
+
console.log(`your name is ${name} and your age is ${age}`);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
throw new TypeError("invalid arguments");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
fun(new String("mohamed"), new Number(23));
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
but not just this there is other funcs you can see the source code and check all the tests in the main fun.
|
|
245
|
+
|
|
246
|
+
## Installation
|
|
247
|
+
|
|
248
|
+
You can install `jsfunx` via npm:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
npm install jsfunx
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
This project is licensed under the MIT LICENSE - see the [LICENSE](https://opensource.org/licenses/MIT) for more details.
|