jsfunx 1.1.0 → 1.1.2
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 +36 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ import { isType, number } from "jsfunx"; // ESM
|
|
|
13
13
|
|
|
14
14
|
// or
|
|
15
15
|
|
|
16
|
+
// "use strict"; // CJS
|
|
17
|
+
|
|
16
18
|
// const { isType, number } = require("jsfunx"); // CJS
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -21,6 +23,7 @@ import { isType, number } from "jsfunx"; // ESM
|
|
|
21
23
|
* @param {number} num1 - The first number.
|
|
22
24
|
* @param {number} num2 - The second number.
|
|
23
25
|
* @returns {number} The sum of `num1` and `num2`.
|
|
26
|
+
* @throws {TypeError} If one or both arguments are not numbers.
|
|
24
27
|
*/
|
|
25
28
|
|
|
26
29
|
function add(num1, num2) {
|
|
@@ -43,12 +46,15 @@ console.log(add(Number(1), Number(3)));
|
|
|
43
46
|
### in place of
|
|
44
47
|
|
|
45
48
|
```js
|
|
49
|
+
// "use strict"; // CJS
|
|
50
|
+
|
|
46
51
|
/**
|
|
47
52
|
* Adds two numbers together and returns the result.
|
|
48
53
|
*
|
|
49
54
|
* @param {number} num1 - The first number.
|
|
50
55
|
* @param {number} num2 - The second number.
|
|
51
56
|
* @returns {number} The sum of `num1` and `num2`.
|
|
57
|
+
* @throws {TypeError} If one or both arguments are not numbers.
|
|
52
58
|
*/
|
|
53
59
|
|
|
54
60
|
function add(num1, num2) {
|
|
@@ -75,6 +81,8 @@ import { isType, number, string } from "jsfunx"; // ESM
|
|
|
75
81
|
|
|
76
82
|
// or
|
|
77
83
|
|
|
84
|
+
// "use strict"; // CJS
|
|
85
|
+
|
|
78
86
|
// const { isType, number, string } = require("jsfunx"); // CJS
|
|
79
87
|
|
|
80
88
|
/**
|
|
@@ -83,6 +91,7 @@ import { isType, number, string } from "jsfunx"; // ESM
|
|
|
83
91
|
* @param {string} name - The person's name.
|
|
84
92
|
* @param {number} age - The person's age.
|
|
85
93
|
* @returns {void} This function does not return a value.
|
|
94
|
+
* @throws {TypeError} If `name` is not a string or `age` is not a number.
|
|
86
95
|
*/
|
|
87
96
|
|
|
88
97
|
function fun(name, age) {
|
|
@@ -106,12 +115,15 @@ fun(String("mohamed"), Number(23));
|
|
|
106
115
|
### in place of
|
|
107
116
|
|
|
108
117
|
```js
|
|
118
|
+
// "use strict"; // CJS
|
|
119
|
+
|
|
109
120
|
/**
|
|
110
121
|
* Prints a message with the given name and age.
|
|
111
122
|
*
|
|
112
123
|
* @param {string} name - The person's name.
|
|
113
124
|
* @param {number} age - The person's age.
|
|
114
125
|
* @returns {void} This function does not return a value.
|
|
126
|
+
* @throws {TypeError} If `name` is not a string or `age` is not a number.
|
|
115
127
|
*/
|
|
116
128
|
|
|
117
129
|
function fun(name, age) {
|
|
@@ -139,21 +151,24 @@ import { instancesof } from "jsfunx"; // ESM
|
|
|
139
151
|
|
|
140
152
|
// or
|
|
141
153
|
|
|
154
|
+
// "use strict"; // CJS
|
|
155
|
+
|
|
142
156
|
// const { instancesof } = require("jsfunx"); // CJS
|
|
143
157
|
|
|
144
158
|
/**
|
|
145
159
|
* Adds two numbers together and returns the result.
|
|
146
160
|
*
|
|
147
|
-
* @param {
|
|
148
|
-
* @param {
|
|
149
|
-
* @returns {
|
|
161
|
+
* @param {Number} num1 - The first number.
|
|
162
|
+
* @param {Number} num2 - The second number.
|
|
163
|
+
* @returns {Number} The sum of `num1` and `num2`.
|
|
164
|
+
* @throws {TypeError} If one or both arguments are not numbers objects.
|
|
150
165
|
*/
|
|
151
166
|
|
|
152
167
|
function add(num1, num2) {
|
|
153
168
|
// 40 char
|
|
154
169
|
|
|
155
170
|
if (instancesof([num1, num2], Number)) {
|
|
156
|
-
return num1 + num2;
|
|
171
|
+
return new Number(num1 + num2);
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
throw new TypeError("invalid arguments types");
|
|
@@ -165,19 +180,22 @@ console.log(add(new Number(1), new Number(3)));
|
|
|
165
180
|
### in place of
|
|
166
181
|
|
|
167
182
|
```js
|
|
183
|
+
// "use strict"; // CJS
|
|
184
|
+
|
|
168
185
|
/**
|
|
169
186
|
* Adds two numbers together and returns the result.
|
|
170
187
|
*
|
|
171
|
-
* @param {
|
|
172
|
-
* @param {
|
|
173
|
-
* @returns {
|
|
188
|
+
* @param {Number} num1 - The first number.
|
|
189
|
+
* @param {Number} num2 - The second number.
|
|
190
|
+
* @returns {Number} The sum of `num1` and `num2`.
|
|
191
|
+
* @throws {TypeError} If one or both arguments are not numbers objects.
|
|
174
192
|
*/
|
|
175
193
|
|
|
176
194
|
function add(num1, num2) {
|
|
177
195
|
// 55 char
|
|
178
196
|
|
|
179
197
|
if (num1 instanceof Number && num2 instanceof Number) {
|
|
180
|
-
return num1 + num2;
|
|
198
|
+
return new Number(num1 + num2);
|
|
181
199
|
}
|
|
182
200
|
|
|
183
201
|
throw new TypeError("invalid arguments types");
|
|
@@ -193,14 +211,17 @@ import { instancesof } from "jsfunx"; // ESM
|
|
|
193
211
|
|
|
194
212
|
// or
|
|
195
213
|
|
|
214
|
+
// "use strict"; // CJS
|
|
215
|
+
|
|
196
216
|
// const { instancesof } = require("jsfunx"); // CJS
|
|
197
217
|
|
|
198
218
|
/**
|
|
199
219
|
* Prints a message with the given name and age.
|
|
200
220
|
*
|
|
201
|
-
* @param {
|
|
202
|
-
* @param {
|
|
221
|
+
* @param {String} name - The person's name.
|
|
222
|
+
* @param {Number} age - The person's age.
|
|
203
223
|
* @returns {void} This function does not return a value.
|
|
224
|
+
* @throws {TypeError} If `name` is not a string object or `age` is not a number object.
|
|
204
225
|
*/
|
|
205
226
|
|
|
206
227
|
function fun(name, age) {
|
|
@@ -220,12 +241,15 @@ fun(new String("mohamed"), new Number(23));
|
|
|
220
241
|
### in place of
|
|
221
242
|
|
|
222
243
|
```js
|
|
244
|
+
// "use strict"; // CJS
|
|
245
|
+
|
|
223
246
|
/**
|
|
224
247
|
* Prints a message with the given name and age.
|
|
225
248
|
*
|
|
226
|
-
* @param {
|
|
227
|
-
* @param {
|
|
249
|
+
* @param {String} name - The person's name.
|
|
250
|
+
* @param {Number} age - The person's age.
|
|
228
251
|
* @returns {void} This function does not return a value.
|
|
252
|
+
* @throws {TypeError} If `name` is not a string object or `age` is not a number object.
|
|
229
253
|
*/
|
|
230
254
|
|
|
231
255
|
function fun(name, age) {
|