@stackone/utils 0.3.0 → 0.4.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/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as e from"date-fns";const r=e=>null!=e,t=e=>null==e||""===e,n=e=>"string"==typeof e,s=e=>"number"==typeof e,a=e=>"boolean"==typeof e,o=e=>e instanceof Date,u=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),i="yyyy-MM-dd",l=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],y=({value:e})=>n(e)?e:o(e)?e.toISOString():u(e)?JSON.stringify(e):String(e),c=({value:e})=>{if(s(e))return e;if(o(e))return null;const r=Number(e);return isNaN(r)?null:r},d=({value:e})=>a(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e),f=({value:r,format:t=i})=>{if(o(r))return r;if(!n(r))return null;try{const n=e.parse(r,t,new Date);return e.isValid(n)?n:p({value:r})}catch{return null}},p=({value:r})=>{const t=e.parseISO(r);if(e.isValid(t))return t;const n=new Date;for(const t of l){const s=e.parse(r,t,n);if(e.isValid(s))return s.setUTCHours(0,0,0,0),s}return null},h=({value:e,format:r=i})=>{const t=f({value:e,format:r});return t?t.toISOString():null};function m(e,r,t,n){if("a"===t&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof r?e!==r||!n:!r.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?n:"a"===t?n.call(e):n?n.value:r.get(e)}var M,g,v,w;"function"==typeof SuppressedError&&SuppressedError;class S extends Map{constructor(){super(...arguments),M.add(this)}set(e,r){const t=m(this,M,"m",g).call(this,e);return super.set(t,r)}get(e){const r=m(this,M,"m",g).call(this,e),t=super.get(r);return super.has(r)?t:super.get(m(this,M,"m",w).call(this,r))}has(e){const r=m(this,M,"m",g).call(this,e);return super.has(r)}delete(e){const r=m(this,M,"m",g).call(this,e);return super.delete(r)}}M=new WeakSet,g=function(e){if("string"!=typeof e)throw new Error("NormalizedKeyMap: Key must be a string");return m(this,M,"m",v).call(this,e)},v=function(e){return e.toUpperCase().replace(/[ -]/g,"_").replace(/[^A-Z0-9_]/g,"")},w=function(e){return Array.from(this.keys()).find((r=>r.includes(e)))??""};export{S as NormalizedKeyMap,a as isBoolean,o as isDate,t as isMissing,s as isNumber,u as isObject,n as isString,r as notMissing,d as safeParseToBoolean,f as safeParseToDateTime,h as safeParseToDateTimeString,c as safeParseToNumber,y as safeParseToString};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var
|
|
1
|
+
"use strict";function e(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,s.get?s:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var r=e(require("date-fns"));const t=e=>"string"==typeof e,s=e=>"number"==typeof e,n=e=>"boolean"==typeof e,a=e=>e instanceof Date,o=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),i="yyyy-MM-dd",u=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],l=({value:e,format:s=i})=>{if(a(e))return e;if(!t(e))return null;try{const t=r.parse(e,s,new Date);return r.isValid(t)?t:y({value:e})}catch{return null}},y=({value:e})=>{const t=r.parseISO(e);if(r.isValid(t))return t;const s=new Date;for(const t of u){const n=r.parse(e,t,s);if(r.isValid(n))return n.setUTCHours(0,0,0,0),n}return null};function c(e,r,t,s){if("a"===t&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof r?e!==r||!s:!r.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?s:"a"===t?s.call(e):s?s.value:r.get(e)}var f,p,d,h;"function"==typeof SuppressedError&&SuppressedError;class m extends Map{constructor(){super(...arguments),f.add(this)}set(e,r){const t=c(this,f,"m",p).call(this,e);return super.set(t,r)}get(e){const r=c(this,f,"m",p).call(this,e),t=super.get(r);return super.has(r)?t:super.get(c(this,f,"m",h).call(this,r))}has(e){const r=c(this,f,"m",p).call(this,e);return super.has(r)}delete(e){const r=c(this,f,"m",p).call(this,e);return super.delete(r)}}f=new WeakSet,p=function(e){if("string"!=typeof e)throw new Error("NormalizedKeyMap: Key must be a string");return c(this,f,"m",d).call(this,e)},d=function(e){return e.toUpperCase().replace(/[ -]/g,"_").replace(/[^A-Z0-9_]/g,"")},h=function(e){return Array.from(this.keys()).find((r=>r.includes(e)))??""},exports.NormalizedKeyMap=m,exports.isBoolean=n,exports.isDate=a,exports.isMissing=e=>null==e||""===e,exports.isNumber=s,exports.isObject=o,exports.isString=t,exports.notMissing=e=>null!=e,exports.safeParseToBoolean=({value:e})=>n(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e),exports.safeParseToDateTime=l,exports.safeParseToDateTimeString=({value:e,format:r=i})=>{const t=l({value:e,format:r});return t?t.toISOString():null},exports.safeParseToNumber=({value:e})=>{if(s(e))return e;if(a(e))return null;const r=Number(e);return isNaN(r)?null:r},exports.safeParseToString=({value:e})=>t(e)?e:a(e)?e.toISOString():o(e)?JSON.stringify(e):String(e);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { notMissing, isMissing, isString, isNumber, isBoolean, isDate, isObject, } from './typeguards';
|
|
2
2
|
export { safeParseToString, safeParseToNumber, safeParseToBoolean, safeParseToDateTime, safeParseToDateTimeString, } from './parsers';
|
|
3
|
+
export { NormalizedKeyMap } from './dataStructures/normalizedKeyMap';
|