some-common-functions-js 1.1.9 → 1.2.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/CHANGELOG.md +7 -1
- package/index.js +26 -19
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -68,4 +68,10 @@ Changed an additional recursive function to an iterative function.
|
|
|
68
68
|
|
|
69
69
|
## Version 1.1.9 - 2026/01/03 - ITA
|
|
70
70
|
- During object assignment, deepClone() function uses object spread to remove references to the original object.
|
|
71
|
-
- get() function replaces falsy-value evaluation (!obj) with 'in' operator for field existence checks. Because the falsy-value evaluation also evaluates to true with existent fields with values that are empty strings or null, which is not desirable.
|
|
71
|
+
- get() function replaces falsy-value evaluation (!obj) with 'in' operator for field existence checks. Because the falsy-value evaluation also evaluates to true with existent fields with values that are empty strings or null, which is not desirable.
|
|
72
|
+
|
|
73
|
+
## Version 1.2.0 - 2026/01/10 to 2026/01/10 - ITA
|
|
74
|
+
get() and unset() functions: for field existence checks, switched from the use of 'in' operator to checking whether the field value is undefined. This prevents from crashes when a non-existent field value is encountered.
|
|
75
|
+
|
|
76
|
+
## Version 1.2.1 - 2026/01/10 to 2026/01/10 - ITA
|
|
77
|
+
Added more robustness in dealing with non-existent fields in the get() and unset() functions.
|
package/index.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
/** File: ./backend/utilityFunctions/commonFunctions.js
|
|
2
2
|
* Description: Common functions to be put here.
|
|
3
|
-
* Date Dev Version Description
|
|
4
|
-
* 2025/11/19
|
|
5
|
-
* 2025/11/28
|
|
6
|
-
* 2025/12/22
|
|
7
|
-
* 2025/12/26
|
|
8
|
-
*
|
|
9
|
-
* 2025/12/27
|
|
10
|
-
*
|
|
11
|
-
* 2025/12/28
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* 2025/12/29
|
|
16
|
-
* 2026/01/01
|
|
17
|
-
* 2026/01/01
|
|
18
|
-
* 2026/01/03
|
|
19
|
-
*
|
|
3
|
+
* Start Date End Date Dev Version Description
|
|
4
|
+
* 2025/11/19 ITA 1.00 Genesis.
|
|
5
|
+
* 2025/11/28 ITA 1.01 Added function hasOnlyAll().
|
|
6
|
+
* 2025/12/22 ITA 1.02 Improved documentation of the functions and moved in more functions.
|
|
7
|
+
* 2025/12/26 ITA 1.03 Removed lodash dependency by re-implementing get() and set() object functions, significantly reducing this package size.
|
|
8
|
+
* Added function getNextDifferent() to deal better with duplicate removal from arrays of objects.
|
|
9
|
+
* 2025/12/27 ITA 1.04 Improved the functions getNoDuplicatesArray() and getNextDifferent() to handle more test cases.
|
|
10
|
+
* Added function unset().
|
|
11
|
+
* 2025/12/28 ITA 1.05 Improved documentation of functions to show better on the tooltip in IDEs.
|
|
12
|
+
* Improved deepClone() function to handle Date objects and arrays.
|
|
13
|
+
* Updated get() function to return undefined or supplied default value for paths that do not exist.
|
|
14
|
+
* Updated test.js file accordingly.
|
|
15
|
+
* 2025/12/29 ITA 1.06 Removed unnecessary use of the getPaths() function in the get() function to improve effieciency.
|
|
16
|
+
* 2026/01/01 ITA 1.07 Changed recursive functions to iterative functions, so as to overcome stack limits when functions are used in the front-end (browsers).
|
|
17
|
+
* 2026/01/01 ITA 1.08 Changed an additional recursive function to an iterative function.
|
|
18
|
+
* 2026/01/03 ITA 1.09 deepClone(): Used object spread to prevent reference sharing during object assignment.
|
|
19
|
+
* unset(): Replaced falsy-value evaluation with the `in` operator to correctly detect existing fields.
|
|
20
|
+
* 2026/01/10 2026/10/10 ITA 1.10 get() and unset() functions: For field existence check, replaced the use of 'in' operator with checking whether the field value of the object is undefined.
|
|
21
|
+
* This prevents crashes resulting from using 'in' operator on undefined fields and objects.
|
|
22
|
+
* 2026/01/10 2026/10/10 ITA 1.11 Added more robustness in dealing with non-existent fields in get() and unset() functions.
|
|
20
23
|
|
|
21
24
|
*/
|
|
22
25
|
|
|
@@ -288,10 +291,12 @@ function get(anObject, path, defaultVal = undefined) {
|
|
|
288
291
|
let tempObj = anObject;
|
|
289
292
|
for (let idx in paths) {
|
|
290
293
|
let key = paths[idx];
|
|
291
|
-
if (
|
|
294
|
+
if (tempObj[key] === undefined) // key not found.
|
|
292
295
|
return defaultVal;
|
|
293
296
|
|
|
294
297
|
tempObj = tempObj[key];
|
|
298
|
+
if (tempObj === undefined)
|
|
299
|
+
return defaultVal;
|
|
295
300
|
}
|
|
296
301
|
return tempObj;
|
|
297
302
|
}
|
|
@@ -329,7 +334,9 @@ function unset(anObject, path) {
|
|
|
329
334
|
let tempObj = anObject;
|
|
330
335
|
for (let idx in paths) {
|
|
331
336
|
let key = paths[idx];
|
|
332
|
-
if (
|
|
337
|
+
if (Object.prototype.toString.call(tempObj) !== '[object Object]')
|
|
338
|
+
return;
|
|
339
|
+
if (tempObj[key] === undefined)
|
|
333
340
|
return;
|
|
334
341
|
if (idx < paths.length - 1)
|
|
335
342
|
tempObj = tempObj[key];
|