some-common-functions-js 1.0.5 → 1.0.7
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 +4 -2
- package/README.md +22 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -19,8 +19,10 @@ Improve README.md documentation.
|
|
|
19
19
|
## Version 1.0.4 - 2025/11/20 - ITA
|
|
20
20
|
- Improved the readability of README.me
|
|
21
21
|
|
|
22
|
-
## Version 1.
|
|
22
|
+
## Version 1.0.5 - 2025/11/21 - ITA
|
|
23
23
|
- Corrected README documentation.
|
|
24
24
|
|
|
25
|
-
## Version 1.
|
|
25
|
+
## Version 1.0.6 - 2025/11/21 - ITA
|
|
26
26
|
- Updated package.json version in lieu of changes. Otherwise the updated package won't be published on npm.
|
|
27
|
+
## Version 1.0.7 - 2025/11/21 - ITA
|
|
28
|
+
- Corrected README documentation.
|
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ Common functions used for working with JavaScript objects and validating field v
|
|
|
11
11
|
### `getPaths(anObject)`
|
|
12
12
|
Returns a string array of path/field names inside a JavaScript object.
|
|
13
13
|
***Example***
|
|
14
|
-
const { getPaths } = require("some-common-functions-js");
|
|
15
14
|
```
|
|
15
|
+
const { getPaths } = require("some-common-functions-js");
|
|
16
16
|
let client = {
|
|
17
17
|
name: "Jack",
|
|
18
18
|
surname: "Stober",
|
|
@@ -200,16 +200,16 @@ let anObject3 = {
|
|
|
200
200
|
let objArray = [anObject2, anObject, anObject3];
|
|
201
201
|
// Using objCompare to sort objects in objArray using multiple fields including nested fields.
|
|
202
202
|
objArray.sort((obj1, obj2)=> {
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
203
|
+
return objCompare(
|
|
204
|
+
obj1, obj2,
|
|
205
|
+
"address.country.name",
|
|
206
|
+
"address.city",
|
|
207
|
+
"adress.mainPlace",
|
|
208
|
+
"address.subPlace",
|
|
209
|
+
"lastName",
|
|
210
|
+
"firstName"
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
213
|
console.log(objArray);
|
|
214
214
|
/*
|
|
215
215
|
[
|
|
@@ -281,11 +281,11 @@ let teams = [
|
|
|
281
281
|
// Using objCompare to sort fields where there are mixed sort directions.
|
|
282
282
|
// Sort by score descending, then by numGames ascending.
|
|
283
283
|
teams.sort((team1, team2) => {
|
|
284
|
-
return
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
284
|
+
return objCompare(
|
|
285
|
+
team1, team2,
|
|
286
|
+
"score desc",
|
|
287
|
+
"numGames asc"
|
|
288
|
+
);
|
|
289
289
|
});
|
|
290
290
|
console.log(teams);
|
|
291
291
|
/*
|
|
@@ -310,6 +310,7 @@ Binary Search the sorted (ascending or descending order) array of objects for a
|
|
|
310
310
|
|
|
311
311
|
***Example***
|
|
312
312
|
```
|
|
313
|
+
const { objCompare, binarySearchObj } = require("some-common-functions-js");
|
|
313
314
|
let teamsArray = [
|
|
314
315
|
{ score: 90, numGames: 10 },
|
|
315
316
|
{ score: 90, numGames: 12 },
|
|
@@ -317,12 +318,12 @@ let teamsArray = [
|
|
|
317
318
|
{ score: 85, numGames: 10 }
|
|
318
319
|
]; // Sorted by "score desc", "numGames asc".
|
|
319
320
|
let searchObj = { score: 85, numGames: 8 };
|
|
320
|
-
let anIndex =
|
|
321
|
+
let anIndex = binarySearchObj(teamsArray, searchObj, "score desc", "numGames asc");
|
|
321
322
|
|
|
322
|
-
let result =
|
|
323
|
+
let result = objCompare(searchObj, teamsArray[anIndex], "score desc", "numGames asc"); // 0 -- an object with value { score: 85, numGames: 8} exists at teamsArray[anIndex];
|
|
323
324
|
```
|
|
324
325
|
## 4. `getObjArrayWithNoDuplicates(objArray, firstOfDuplicates, ...comparisonFields)`
|
|
325
|
-
Create an array of objects with duplicates eliminated. Taking only the first or last object from each duplicate set. The input array must be sorted according to the values comparisonFields.
|
|
326
|
+
Create an array of objects with duplicates eliminated. Taking only the first or last object from each duplicate set. The input array must be sorted according to the values of comparisonFields.
|
|
326
327
|
* If firstOfDuplicates === true, then the first element in each set of duplicates is taken.
|
|
327
328
|
* if firstOfDuplicates === false, then the last element is taken from each set of duplicates.
|
|
328
329
|
* Assumed field data types are Number, String and Date.
|
|
@@ -333,6 +334,7 @@ Create an array of objects with duplicates eliminated. Taking only the first or
|
|
|
333
334
|
|
|
334
335
|
***Example***
|
|
335
336
|
```
|
|
337
|
+
const { getObjArrayWithNoDuplicates } = require("some-common-functions-js");
|
|
336
338
|
let teamsArray = [
|
|
337
339
|
{ score: 90, numGames: 10 },
|
|
338
340
|
{ score: 90, numGames: 10 },
|
|
@@ -347,7 +349,7 @@ let teamsArray = [
|
|
|
347
349
|
{ score: 85, numGames: 10 }
|
|
348
350
|
]; // Sorted by "score desc", "numGames asc".
|
|
349
351
|
|
|
350
|
-
let noDuplicatesArray =
|
|
352
|
+
let noDuplicatesArray = getObjArrayWithNoDuplicates(teamsArray, true, "score desc", "numGames asc");
|
|
351
353
|
console.log(noDuplicatesArray); // Should contain only unique objects according to comparison fields.
|
|
352
354
|
/*
|
|
353
355
|
[
|