some-common-functions-js 1.0.3 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +24 -48
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -18,3 +18,11 @@ Improve README.md documentation.
18
18
 
19
19
  ## Version 1.0.4 - 2025/11/20 - ITA
20
20
  - Improved the readability of README.me
21
+
22
+ ## Version 1.0.5 - 2025/11/21 - ITA
23
+ - Corrected README documentation.
24
+
25
+ ## Version 1.0.6 - 2025/11/21 - ITA
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 commonFunctions.objCompare(
204
- obj1, obj2,
205
- "address.country.name",
206
- "address.city",
207
- "adress.mainPlace",
208
- "address.subPlace",
209
- "lastName",
210
- "firstName"
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
  [
@@ -278,42 +278,16 @@ let teams = [
278
278
  numGames: 10
279
279
  }
280
280
  ];
281
- // Using objCompare to sort fields where there
281
+ // Using objCompare to sort fields where there are mixed sort directions.
282
+ // Sort by score descending, then by numGames ascending.
282
283
  teams.sort((team1, team2) => {
283
- return commonFunctions.objCompare(
284
- team1, team2,
285
- "score desc",
286
- "numGames asc"
287
- );
284
+ return objCompare(
285
+ team1, team2,
286
+ "score desc",
287
+ "numGames asc"
288
+ );
288
289
  });
289
290
  console.log(teams);
290
- /*
291
- let teams = [
292
- {
293
- score: 85,
294
- numGames: 10
295
- },
296
- {
297
- score: 90,
298
- numGames: 12
299
- },
300
- {
301
- score: 85,
302
- numGames: 8
303
- },
304
- {
305
- score: 90,
306
- numGames: 10
307
- }
308
- ];
309
- // Sort by score descending, then by numGames ascending.
310
- objArray.sort((team1, team2) => {
311
- return commonFunctions.objCompare(
312
- team1, team2,
313
- "score desc",
314
- "numGames asc"
315
- );
316
- });
317
291
  /*
318
292
  [
319
293
  { score: 90, numGames: 10 },
@@ -336,6 +310,7 @@ Binary Search the sorted (ascending or descending order) array of objects for a
336
310
 
337
311
  ***Example***
338
312
  ```
313
+ const { objCompare, binarySearchObj } = require("some-common-functions-js");
339
314
  let teamsArray = [
340
315
  { score: 90, numGames: 10 },
341
316
  { score: 90, numGames: 12 },
@@ -343,12 +318,12 @@ let teamsArray = [
343
318
  { score: 85, numGames: 10 }
344
319
  ]; // Sorted by "score desc", "numGames asc".
345
320
  let searchObj = { score: 85, numGames: 8 };
346
- let anIndex = (commonFunctions.binarySearchObj(teamsArray, searchObj, "score desc", "numGames asc"));
321
+ let anIndex = binarySearchObj(teamsArray, searchObj, "score desc", "numGames asc");
347
322
 
348
- let result = commonFunctions.objCompare(searchObj, teamsArray[anIndex], "score desc", "numGames asc"); // 0 -- an object with value { score: 85, numGames: 8} exists at teamsArray[anIndex];
323
+ let result = objCompare(searchObj, teamsArray[anIndex], "score desc", "numGames asc"); // 0 -- an object with value { score: 85, numGames: 8} exists at teamsArray[anIndex];
349
324
  ```
350
325
  ## 4. `getObjArrayWithNoDuplicates(objArray, firstOfDuplicates, ...comparisonFields)`
351
- 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.
352
327
  * If firstOfDuplicates === true, then the first element in each set of duplicates is taken.
353
328
  * if firstOfDuplicates === false, then the last element is taken from each set of duplicates.
354
329
  * Assumed field data types are Number, String and Date.
@@ -359,6 +334,7 @@ Create an array of objects with duplicates eliminated. Taking only the first or
359
334
 
360
335
  ***Example***
361
336
  ```
337
+ const { getObjArrayWithNoDuplicates } = require("some-common-functions-js");
362
338
  let teamsArray = [
363
339
  { score: 90, numGames: 10 },
364
340
  { score: 90, numGames: 10 },
@@ -373,7 +349,7 @@ let teamsArray = [
373
349
  { score: 85, numGames: 10 }
374
350
  ]; // Sorted by "score desc", "numGames asc".
375
351
 
376
- let noDuplicatesArray = commonFunctions.getObjArrayWithNoDuplicates(teamsArray, true, "score desc", "numGames asc");
352
+ let noDuplicatesArray = getObjArrayWithNoDuplicates(teamsArray, true, "score desc", "numGames asc");
377
353
  console.log(noDuplicatesArray); // Should contain only unique objects according to comparison fields.
378
354
  /*
379
355
  [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "some-common-functions-js",
3
- "version": "1.0.3",
3
+ "version": "1.0.7",
4
4
  "description": "Common functions used with Javascript objects, and field validation functions.",
5
5
  "keywords": [
6
6
  "validation",