best-globals 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 CHANGED
@@ -64,6 +64,12 @@ console.log(coalesce(undefined,coalesce.throwErrorIfUndefined('name'))); // = th
64
64
 
65
65
  Returns a new object like originalConfig with the changes reflected
66
66
 
67
+ Changes can be:
68
+ * any value,
69
+ * an object to apply the recursive changes (if the original is also an object)
70
+ * a call to `changes.trueByObject(changes)` that means that the change only applies to non falsy values
71
+
72
+
67
73
 
68
74
  ```js
69
75
  var changing = require('best-globals').changing;
package/best-globals.js CHANGED
@@ -117,8 +117,15 @@ function deepCopy(object){
117
117
 
118
118
  bestGlobals.deepCopy = deepCopy;
119
119
 
120
- bestGlobals.changing = function changing(original, changes){
121
- var opts = bestGlobals.changing.retreiveOptions(arguments);
120
+ function ChangingWithSpecial(change){
121
+ this.change = change;
122
+ }
123
+
124
+ function changing(original, changes){
125
+ var opts = changing.retreiveOptions(arguments);
126
+ if (changes instanceof ChangingWithSpecial) {
127
+ return changes.change(original);
128
+ }
122
129
  if(original===null ||
123
130
  !bestGlobals.isPlainObject(original) &&
124
131
  !(original instanceof Error) &&
@@ -144,7 +151,7 @@ bestGlobals.changing = function changing(original, changes){
144
151
  }else if('deletingValue' in opts && changes[name]===opts.deletingValue){
145
152
  // empty
146
153
  }else{
147
- result[name] = changing(original[name], changes[name], bestGlobals.changing.options(opts), true);
154
+ result[name] = changing(original[name], changes[name], changing.options(opts), true);
148
155
  }
149
156
  }
150
157
  for(name in changes){
@@ -158,6 +165,14 @@ bestGlobals.changing = function changing(original, changes){
158
165
  }
159
166
  };
160
167
 
168
+ changing.trueByObject = function trueByObject(object){
169
+ return new ChangingWithSpecial(function(original, opts){
170
+ if (original == true) return deepCopy(object);
171
+ if (original) return changing(original, object, changing.options(opts))
172
+ return original;
173
+ });
174
+ }
175
+
161
176
  bestGlobals.dig = function dig(description, wanted){
162
177
  if(arguments.length==1){
163
178
  wanted=description;
@@ -253,7 +268,9 @@ bestGlobals.dig.array = function array(description, wanted){
253
268
  bestGlobals.spec = bestGlobals.dig;
254
269
 
255
270
 
256
- bestGlobals.createOptionsToFunction(bestGlobals.changing);
271
+ bestGlobals.createOptionsToFunction(changing);
272
+
273
+ bestGlobals.changing = changing;
257
274
 
258
275
  function npad(num, width) {
259
276
  var n=num+''; // to string
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-globals",
3
- "description": "common global function and constants - i.e. coalesce",
4
- "version": "1.1.0",
3
+ "description": "common global function and constants - i.e. changes",
4
+ "version": "1.1.2",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/best-globals",
@@ -22,8 +22,8 @@
22
22
  "expect.js": "~0.3.1",
23
23
  "express": "^4.18.2",
24
24
  "express-session": "^1.17.3",
25
- "karma": "^6.4.1",
26
- "karma-chrome-launcher": "^3.1.1",
25
+ "karma": "^6.4.2",
26
+ "karma-chrome-launcher": "^3.2.0",
27
27
  "karma-coverage": "^2.2.0",
28
28
  "karma-coverage-html-index-reporter": "^1.0.2",
29
29
  "karma-expect": "^1.1.3",
@@ -31,10 +31,10 @@
31
31
  "karma-mocha": "^2.0.1",
32
32
  "nyc": "~15.1.0",
33
33
  "mocha": "~10.2.0",
34
- "require-bro": "^0.3.0",
35
- "sinon": "~15.0.1",
34
+ "require-bro": "^0.3.1",
35
+ "sinon": "~15.1.0",
36
36
  "audit-copy": "~0.1.0",
37
- "discrepances": "~0.2.6"
37
+ "discrepances": "~0.2.8"
38
38
  },
39
39
  "main": "best-globals.js",
40
40
  "types": "best-globals.d.ts",