some-common-functions-js 1.0.8 → 1.0.9
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 -0
- package/README.md +26 -4
- package/index.js +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -29,3 +29,7 @@ Improve README.md documentation.
|
|
|
29
29
|
|
|
30
30
|
## Version 1.0.8 - 2025/11/21 - ITA
|
|
31
31
|
- Corrected test code and README documentation
|
|
32
|
+
|
|
33
|
+
## Version 1.0.9 - 2025/11/28 - ITA
|
|
34
|
+
- Provided more documentation in test.js to remind a developer how to symbolic-link (mimick as installed) the package and running the test code.
|
|
35
|
+
- Added new function, hasOnlyAll(), and updated the README.md documentation accordingly.
|
package/README.md
CHANGED
|
@@ -73,6 +73,28 @@ let result = hasAll(car, "make", "model");
|
|
|
73
73
|
|
|
74
74
|
let result = hasAll(car, "passengerCapacity", "year");
|
|
75
75
|
// false, because car does not have "passengerCapacity" field.
|
|
76
|
+
```
|
|
77
|
+
### `hasOnlyAll(anObject, ...fields)`
|
|
78
|
+
Return `true` if an object contains only all the specified fields, nothing more, nothing less
|
|
79
|
+
***Example***
|
|
80
|
+
```
|
|
81
|
+
const { hasOnlyAll } = require("some-common-functions-js");
|
|
82
|
+
let car = {
|
|
83
|
+
make: "Ford",
|
|
84
|
+
model: "Ranger",
|
|
85
|
+
year: "2015",
|
|
86
|
+
power: "1000kW",
|
|
87
|
+
type: "pickup truck"
|
|
88
|
+
};
|
|
89
|
+
let result = hasOnlyAll(car, "make", "model");
|
|
90
|
+
// false, because car has all the specified fields and extra fields.
|
|
91
|
+
|
|
92
|
+
let result = hasOnlyAll(car, "passengerCapacity", "year");
|
|
93
|
+
// false, because car does not have "passengerCapacity" field.
|
|
94
|
+
|
|
95
|
+
let result = hasOnlyAll(car, "make", "model", "power", "type");
|
|
96
|
+
// true, because car has all the specified fields, nothing less, nothing more.
|
|
97
|
+
|
|
76
98
|
```
|
|
77
99
|
---
|
|
78
100
|
|
|
@@ -109,13 +131,13 @@ Compares two values of the same primitive type, according to the sort direction.
|
|
|
109
131
|
```
|
|
110
132
|
const { compare } = require("some-common-functions-js");
|
|
111
133
|
|
|
112
|
-
let x = "
|
|
134
|
+
let x = "Jiāng Fāng";
|
|
113
135
|
let y = "Isaiah Tshabalala";
|
|
114
|
-
let result = compare(x, y); // -1 because "
|
|
136
|
+
let result = compare(x, y); // -1 because "Jiāng Fāng" is before "Isaiah Tshabalala" in ascending order.
|
|
115
137
|
result = compare(y, x);
|
|
116
|
-
console.log(result); // 1 because "Isaiah Tshabalala" is after "
|
|
138
|
+
console.log(result); // 1 because "Isaiah Tshabalala" is after "Jiāng Fāng" in ascending order.
|
|
117
139
|
result = compare(x, y, 'desc');
|
|
118
|
-
console.log(result); // 1 because "
|
|
140
|
+
console.log(result); // 1 because "Jiāng Fāng" is after "Isaiah Tshabalala" in descending order.
|
|
119
141
|
```
|
|
120
142
|
### `binarySearch(anArray, searchVal, startFrom = 0, arraySortDir = 'asc')`
|
|
121
143
|
Binary Searches a sorted primitive type array for a value and returns the index.
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Description: Common functions to be put here.
|
|
3
3
|
* Date Dev Version Description
|
|
4
4
|
* 2025/11/19 ITA 1.00 Genesis.
|
|
5
|
+
* 2025/11/28 ITA 1.01 Added function hasOnlyAll().
|
|
5
6
|
*/
|
|
6
7
|
const loDash = require('lodash');
|
|
7
8
|
|
|
@@ -157,6 +158,16 @@ function hasAll(anObject, ...fields) {
|
|
|
157
158
|
}
|
|
158
159
|
module.exports.hasAll = hasAll;
|
|
159
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Determine whether an object contains only all of the specified fields. Nothing more, nothing less.
|
|
163
|
+
* @param {*} anObject a Javascript object.
|
|
164
|
+
* @param {...string} fields one or field names.
|
|
165
|
+
* @returns boolean.
|
|
166
|
+
*/
|
|
167
|
+
function hasOnlyAll(anObject, ...fields) {
|
|
168
|
+
return hasOnly(anObject, ...fields) && hasAll(anObject, ...fields);
|
|
169
|
+
}
|
|
170
|
+
module.exports.hasOnlyAll = hasOnlyAll;
|
|
160
171
|
|
|
161
172
|
/**Binary Search the sorted primitive data array for a value and return the index.
|
|
162
173
|
* ArraySortDir specifies the direction in which the array is sorted (desc or asc).
|