best-globals 1.0.3 → 1.1.0

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/best-globals.d.ts CHANGED
@@ -118,12 +118,13 @@ declare module "best-globals"{
118
118
  function serie(first:number, length:number):number[]
119
119
  function serie(spec:{from?:number, step?:number, to:number}):number[]
120
120
  function serie(spec:{from?:number, step?:number, length:number}):number[]
121
- function sameValues(x:any, y:any):boolean
121
+ function sameValue<T>(x:T, y:T):boolean
122
+ function sameValues<T>(x:T, y:T):boolean
122
123
  function isLowerIdent(text:string):boolean
123
124
  function deepFreeze<T extends {}>(o:T):Readonly<T>
124
125
  function simplifyText(text:string):string
125
126
  function hyperSimplifyText(text:string, spaceReplacer?:string):string
126
- var simplifiedLetters={[letter in string]:string}
127
+ var simplifiedLetters:Record<string,string>
127
128
  }
128
129
  export = bestGlobals
129
130
  }
package/best-globals.js CHANGED
@@ -461,7 +461,7 @@ bestGlobals.Datetime.prototype.getTime = function getTime() {
461
461
  ).getTime();
462
462
  };
463
463
 
464
- bestGlobals.Datetime.prototype.toPlainString = function toPlainString(){
464
+ bestGlobals.Datetime.prototype.toPlainString = function toPlainString(preserveHm){
465
465
  var str=this.toYmdHmsMm();
466
466
  var prune = function(what){
467
467
  if(str.substr(str.length-what.length)==what){
@@ -471,7 +471,7 @@ bestGlobals.Datetime.prototype.toPlainString = function toPlainString(){
471
471
  return false;
472
472
  }
473
473
  /* eslint no-unused-expressions: 0 */
474
- prune('000') && prune('.000') && prune(':00') && prune(' 00:00');
474
+ prune('000') && prune('.000') && prune(':00') && (preserveHm || prune(' 00:00'));
475
475
  return str;
476
476
  }
477
477
  // bestGlobals.Datetime.prototype.toUTCString = function toUTCString(){ return this.iso; }
@@ -855,12 +855,26 @@ bestGlobals.registerJson4All = function registerJson4All(JSON4all){
855
855
  }else{
856
856
  return date.getTime();
857
857
  }
858
- }
858
+ },
859
+ serialize: function serialize(date){
860
+ return date.isRealDate ? date.toYmd() : date.toISOString();
861
+ },
862
+ deserialize: JSON4all.DateFunctions.deserialize,
863
+ valueLike:true
859
864
  });
860
865
  JSON4all.addType('date', {
861
866
  construct: function construct(value){
862
867
  return bestGlobals.date.iso(value);
863
868
  },
869
+ serialize: function serialize(o){
870
+ return o.toYmd();
871
+ },
872
+ deserialize: function deserialize(plainValue){
873
+ var ok = /^\d{4}-\d\d-\d\d$/.test(plainValue);
874
+ var value = ok && bestGlobals.date.iso(plainValue) || null;
875
+ return {ok, value};
876
+ },
877
+ valueLike:true
864
878
  });
865
879
  JSON4all.addType(bestGlobals.Datetime, {
866
880
  construct: function construct(value){
@@ -869,6 +883,15 @@ bestGlobals.registerJson4All = function registerJson4All(JSON4all){
869
883
  deconstruct: function construct(datetime){
870
884
  return datetime.toPlainString();
871
885
  },
886
+ serialize: function serialize(datetime){
887
+ return datetime.toPlainString(true);
888
+ },
889
+ deserialize: function deserialize(plainValue){
890
+ var ok = /^\d{4}-\d\d-\d\d \d\d:\d\d(:\d\d(.\d+)?)?$/.test(plainValue);
891
+ var value = ok && bestGlobals.datetime.iso(plainValue) || null;
892
+ return {ok, value};
893
+ },
894
+ valueLike:true
872
895
  });
873
896
  };
874
897
 
@@ -963,11 +986,13 @@ bestGlobals.sameValue = function sameValue(a,b){
963
986
  return a==b ||
964
987
  a instanceof Date && b instanceof Date && a.getTime() == b.getTime() ||
965
988
  typeof a === 'number' && (a>MAX_SAFE_INTEGER || a< -MAX_SAFE_INTEGER) && Math.abs(a/b)<1.00000000000001 && Math.abs(a/b)>0.99999999999999 ||
966
- a && !!a.sameValue && a.sameValue(b);
989
+ a !=null && !!a.sameValue && a.sameValue(b);
967
990
  }
968
991
 
969
992
  bestGlobals.sameValues = function sameValues(a,b, sideOfBigger){
970
993
  if(a===b) return true;
994
+ if(bestGlobals.sameValue(a,b)) return true;
995
+ if(!(a instanceof Object) || !(b instanceof Object)) return false;
971
996
  if(sideOfBigger=="left"){
972
997
  return bestGlobals.sameValues(b,a,"right");
973
998
  }else if(sideOfBigger=="right"){
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "best-globals",
3
3
  "description": "common global function and constants - i.e. coalesce",
4
- "version": "1.0.3",
4
+ "version": "1.1.0",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/best-globals",
@@ -20,19 +20,19 @@
20
20
  "colors": "~1.4.0",
21
21
  "cookie-parser": "^1.4.6",
22
22
  "expect.js": "~0.3.1",
23
- "express": "^4.17.2",
24
- "express-session": "^1.17.2",
25
- "karma": "^6.3.11",
26
- "karma-chrome-launcher": "^3.1.0",
27
- "karma-coverage": "^2.1.0",
23
+ "express": "^4.18.2",
24
+ "express-session": "^1.17.3",
25
+ "karma": "^6.4.1",
26
+ "karma-chrome-launcher": "^3.1.1",
27
+ "karma-coverage": "^2.2.0",
28
28
  "karma-coverage-html-index-reporter": "^1.0.2",
29
29
  "karma-expect": "^1.1.3",
30
30
  "karma-firefox-launcher": "^2.1.2",
31
31
  "karma-mocha": "^2.0.1",
32
32
  "nyc": "~15.1.0",
33
- "mocha": "~9.1.3",
33
+ "mocha": "~10.2.0",
34
34
  "require-bro": "^0.3.0",
35
- "sinon": "~12.0.1",
35
+ "sinon": "~15.0.1",
36
36
  "audit-copy": "~0.1.0",
37
37
  "discrepances": "~0.2.6"
38
38
  },