@cpmech/basic
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>""!==e&&"null"!==e,t=(e,o="__EMPTY__",r=!1)=>Object.keys(e).reduce((s,n)=>({...s,[n]:null===e[n]||void 0===e[n]?r?e[n]:o:Array.isArray(e[n])?e[n].map(e=>""===e?o:e):"object"==typeof e[n]?t(e[n],o):""===e[n]?o:e[n]}),{}),o=e=>Object.keys(e).reduce((t,r)=>({...t,[r]:Array.isArray(e[r])?e[r].slice(0):"object"==typeof e[r]?o(e[r]):e[r]}),{}),r=(e,t)=>{const o=Object.keys(e);for(const s of o){const o=t[s];Array.isArray(o)?e[s]=o.slice(0):"object"==typeof o?r(e[s],o):e[s]=o}},s=(e,t)=>{if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0},n=(e,t)=>{const o=Object.keys(e);for(const r of o){const o=t[r];if(Array.isArray(o)){if(!s(e[r],o))return!0}else if("object"==typeof o){if(n(e[r],o))return!0}else if(e[r]!==o)return!0}return!1},i=(e,t="__EMPTY__",o=!1)=>Object.keys(e).reduce((r,s)=>({...r,[s]:null===e[s]||void 0===e[s]?o?e[s]:"":Array.isArray(e[s])?e[s].map(e=>e===t?"":e):"object"==typeof e[s]?i(e[s],t):e[s]===t?"":e[s]}),{}),l=(e,t=!0)=>{const o=[];for(const r of Object.keys(e)){const s=e[r];o.push(r),"object"!=typeof s||Array.isArray(s)||(t&&o.push("{"),l(s,t).forEach(e=>o.push(e)),t&&o.push("}"))}return o},c=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let p=!0,a=!0,y="[ERROR]";const u=(e,t)=>{for(const o of Object.keys(e))if(c(t,o)){const r=t[o];null!=r&&(Array.isArray(r)?e[o]=r.slice(0):"object"==typeof r?u(e[o],r):e[o]=r)}};exports.Locales=class{constructor(e,t="en",o="us"){this.getLocale=()=>this.locale,this.setLocale=e=>this.locale=e,this.getCountry=()=>this.country,this.setCountry=e=>this.country=e,this.getIndexDay=()=>"us"===this.country?1:0,this.getIndexMonth=()=>"us"===this.country?0:1,this.getFirstFieldMax=()=>"us"===this.country?12:31,this.getSecondFieldMax=()=>"us"===this.country?31:12,this.getDateFormat=()=>"us"===this.country?"MM/DD/YYYY":"DD/MM/YYYY",this.translate=(e,t="")=>{if(!c(this.resources,this.locale))return`INTERNAL_ERROR: cannot find locale ${this.locale} in resources object`;const o=this.resources[this.locale];if(!e)return"INTERNAL_ERROR: path variable must not be empty";const r=e.split(".").reduce((e,t)=>c(e,t)?e[t]:"",o);return r||(t||`INTERNAL_ERROR: cannot find message with path = ${e}`)},this.resources=e,this.locale=t,this.country=o}},exports.allFilled=(t,o)=>{let r;r=o?Object.keys(t).filter(e=>!o.includes(e)):Object.keys(t);for(const o of r)if(!e(t[o]))return!1;return!0},exports.blank2empty=t,exports.camelize=(e,t=!1,o="_")=>t?e.split(o).map(e=>e.toLowerCase().replace(/./,e=>e.toUpperCase())).join(""):e.split(o).map((e,t)=>t>0?e.toLowerCase().replace(/./,e=>e.toUpperCase()):e.toLowerCase()).join(""),exports.cloneSimple=o,exports.copySimple=r,exports.diffSimple=n,exports.elog=e=>{let t="";return e.message&&"string"==typeof e.message?(e.message.replace(`${y} `,""),t=`${y} ${e.message}`):t="string"==typeof e||"number"==typeof e||"boolean"==typeof e?`${y} ${e}`:`${y}\n${JSON.stringify(e,void 0,2)}`,t=t.replace(`${y} ${y}`,y),a&&console.log(t),t},exports.email2key=e=>e.toLowerCase().replace(/[@\.]/g,"_"),exports.empty2blank=i,exports.filled=e,exports.formatCPF=e=>{const t=e.replace(/[\D\s._-]+/g,"");let o=4;const r=[];for(let e=0,s=t.length;e<s;e+=o)o=e<9?3:2,r.push(t.substr(e,o));return r.length>=4?r.slice(0,3).join(".")+"-"+r[3]:r.join(".")},exports.getObjectKeys=l,exports.hasProp=c,exports.limitNumDecimals=(e,t=2)=>Number(Number.parseFloat(String(e)).toFixed(t)),exports.makeGetField=(e,t)=>o=>{if(!Object.prototype.hasOwnProperty.call(e,o))throw new Error(`cannot find ${o}`);const r=e[o];if(typeof r!==t)throw new Error(`type of ${o} is incorrect`);return r},exports.makeSetField=(e,t,o)=>(r,s)=>{if(!Object.prototype.hasOwnProperty.call(e,r))throw new Error(`cannot find ${r}`);const n=e[r];if(typeof n!==o)throw new Error(`type of ${r} is incorrect`);n!==s&&(e[r]=s,t())},exports.maybeCopySimple=u,exports.mlog=e=>{p&&("string"==typeof e||"number"==typeof e||"boolean"==typeof e?console.log(e):console.log(JSON.stringify(e,void 0,2)))},exports.numOnly=e=>e.replace(/[\D\s\._\-]+/g,""),exports.setElog=e=>a=e,exports.setElogPrefix=e=>y=e,exports.setMlog=e=>p=e,exports.shallowCompareArrays=s,exports.sleep=e=>new Promise(t=>setTimeout(t,e)),exports.unixTimeNow=()=>Math.floor(Date.now()/1e3); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>""!==e&&"null"!==e,t=(e,o="__EMPTY__",r=!1)=>Object.keys(e).reduce((s,n)=>({...s,[n]:null===e[n]||void 0===e[n]?r?e[n]:o:Array.isArray(e[n])?e[n].map(e=>""===e?o:e):"object"==typeof e[n]?t(e[n],o):""===e[n]?o:e[n]}),{}),o=e=>Object.keys(e).reduce((t,r)=>({...t,[r]:Array.isArray(e[r])?e[r].slice(0):"object"==typeof e[r]?o(e[r]):e[r]}),{}),r=(e,t)=>{const o=Object.keys(e);for(const s of o){const o=t[s];Array.isArray(o)?e[s]=o.slice(0):"object"==typeof o?r(e[s],o):e[s]=o}},s=(e,t)=>{if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0},n=(e,t)=>{const o=Object.keys(e);for(const r of o){const o=t[r];if(Array.isArray(o)){if(!s(e[r],o))return!0}else if("object"==typeof e[r]&&null!==e[r]){if(n(e[r],o))return!0}else if(e[r]!==o)return!0}return!1},i=(e,t="__EMPTY__",o=!1)=>Object.keys(e).reduce((r,s)=>({...r,[s]:null===e[s]||void 0===e[s]?o?e[s]:"":Array.isArray(e[s])?e[s].map(e=>e===t?"":e):"object"==typeof e[s]?i(e[s],t):e[s]===t?"":e[s]}),{}),l=(e,t=!0)=>{const o=[];for(const r of Object.keys(e)){const s=e[r];o.push(r),"object"!=typeof s||Array.isArray(s)||(t&&o.push("{"),l(s,t).forEach(e=>o.push(e)),t&&o.push("}"))}return o},c=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let p=!0,a=!0,y="[ERROR]";const u=(e,t)=>{for(const o of Object.keys(e))if(c(t,o)){const r=t[o];null!=r&&(Array.isArray(r)?e[o]=r.slice(0):"object"==typeof r?u(e[o],r):e[o]=r)}};exports.Locales=class{constructor(e,t="en",o="us"){this.getLocale=()=>this.locale,this.setLocale=e=>this.locale=e,this.getCountry=()=>this.country,this.setCountry=e=>this.country=e,this.getIndexDay=()=>"us"===this.country?1:0,this.getIndexMonth=()=>"us"===this.country?0:1,this.getFirstFieldMax=()=>"us"===this.country?12:31,this.getSecondFieldMax=()=>"us"===this.country?31:12,this.getDateFormat=()=>"us"===this.country?"MM/DD/YYYY":"DD/MM/YYYY",this.translate=(e,t="")=>{if(!c(this.resources,this.locale))return`INTERNAL_ERROR: cannot find locale ${this.locale} in resources object`;const o=this.resources[this.locale];if(!e)return"INTERNAL_ERROR: path variable must not be empty";const r=e.split(".").reduce((e,t)=>c(e,t)?e[t]:"",o);return r||(t||`INTERNAL_ERROR: cannot find message with path = ${e}`)},this.resources=e,this.locale=t,this.country=o}},exports.allFilled=(t,o)=>{let r;r=o?Object.keys(t).filter(e=>!o.includes(e)):Object.keys(t);for(const o of r)if(!e(t[o]))return!1;return!0},exports.blank2empty=t,exports.camelize=(e,t=!1,o="_")=>t?e.split(o).map(e=>e.toLowerCase().replace(/./,e=>e.toUpperCase())).join(""):e.split(o).map((e,t)=>t>0?e.toLowerCase().replace(/./,e=>e.toUpperCase()):e.toLowerCase()).join(""),exports.cloneSimple=o,exports.copySimple=r,exports.diffSimple=n,exports.elog=e=>{let t="";return e.message&&"string"==typeof e.message?(e.message.replace(`${y} `,""),t=`${y} ${e.message}`):t="string"==typeof e||"number"==typeof e||"boolean"==typeof e?`${y} ${e}`:`${y}\n${JSON.stringify(e,void 0,2)}`,t=t.replace(`${y} ${y}`,y),a&&console.log(t),t},exports.email2key=e=>e.toLowerCase().replace(/[@\.]/g,"_"),exports.empty2blank=i,exports.filled=e,exports.formatCPF=e=>{const t=e.replace(/[\D\s._-]+/g,"");let o=4;const r=[];for(let e=0,s=t.length;e<s;e+=o)o=e<9?3:2,r.push(t.substr(e,o));return r.length>=4?r.slice(0,3).join(".")+"-"+r[3]:r.join(".")},exports.getObjectKeys=l,exports.hasProp=c,exports.limitNumDecimals=(e,t=2)=>Number(Number.parseFloat(String(e)).toFixed(t)),exports.makeGetField=(e,t)=>o=>{if(!Object.prototype.hasOwnProperty.call(e,o))throw new Error(`cannot find ${o}`);const r=e[o];if(typeof r!==t)throw new Error(`type of ${o} is incorrect`);return r},exports.makeSetField=(e,t,o)=>(r,s)=>{if(!Object.prototype.hasOwnProperty.call(e,r))throw new Error(`cannot find ${r}`);const n=e[r];if(typeof n!==o)throw new Error(`type of ${r} is incorrect`);n!==s&&(e[r]=s,t())},exports.maybeCopySimple=u,exports.mlog=e=>{p&&("string"==typeof e||"number"==typeof e||"boolean"==typeof e?console.log(e):console.log(JSON.stringify(e,void 0,2)))},exports.numOnly=e=>e.replace(/[\D\s\._\-]+/g,""),exports.setElog=e=>a=e,exports.setElogPrefix=e=>y=e,exports.setMlog=e=>p=e,exports.shallowCompareArrays=s,exports.sleep=e=>new Promise(t=>setTimeout(t,e)),exports.unixTimeNow=()=>Math.floor(Date.now()/1e3); |
@@ -1,1 +0,1 @@ | ||
const e=e=>""!==e&&"null"!==e,t=(t,r)=>{let o;o=r?Object.keys(t).filter(e=>!r.includes(e)):Object.keys(t);for(const r of o)if(!e(t[r]))return!1;return!0},r=(e,t="__EMPTY__",o=!1)=>Object.keys(e).reduce((s,n)=>({...s,[n]:null===e[n]||void 0===e[n]?o?e[n]:t:Array.isArray(e[n])?e[n].map(e=>""===e?t:e):"object"==typeof e[n]?r(e[n],t):""===e[n]?t:e[n]}),{}),o=(e,t=!1,r="_")=>t?e.split(r).map(e=>e.toLowerCase().replace(/./,e=>e.toUpperCase())).join(""):e.split(r).map((e,t)=>t>0?e.toLowerCase().replace(/./,e=>e.toUpperCase()):e.toLowerCase()).join(""),s=e=>Object.keys(e).reduce((t,r)=>({...t,[r]:Array.isArray(e[r])?e[r].slice(0):"object"==typeof e[r]?s(e[r]):e[r]}),{}),n=(e,t)=>{const r=Object.keys(e);for(const o of r){const r=t[o];Array.isArray(r)?e[o]=r.slice(0):"object"==typeof r?n(e[o],r):e[o]=r}},c=(e,t)=>{if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0},i=(e,t)=>{const r=Object.keys(e);for(const o of r){const r=t[o];if(Array.isArray(r)){if(!c(e[o],r))return!0}else if("object"==typeof r){if(i(e[o],r))return!0}else if(e[o]!==r)return!0}return!1},a=e=>e.toLowerCase().replace(/[@\.]/g,"_"),l=(e,t="__EMPTY__",r=!1)=>Object.keys(e).reduce((o,s)=>({...o,[s]:null===e[s]||void 0===e[s]?r?e[s]:"":Array.isArray(e[s])?e[s].map(e=>e===t?"":e):"object"==typeof e[s]?l(e[s],t):e[s]===t?"":e[s]}),{}),y=e=>{const t=e.replace(/[\D\s._-]+/g,"");let r=4;const o=[];for(let e=0,s=t.length;e<s;e+=r)r=e<9?3:2,o.push(t.substr(e,r));return o.length>=4?o.slice(0,3).join(".")+"-"+o[3]:o.join(".")},u=(e,t=!0)=>{const r=[];for(const o of Object.keys(e)){const s=e[o];r.push(o),"object"!=typeof s||Array.isArray(s)||(t&&r.push("{"),u(s,t).forEach(e=>r.push(e)),t&&r.push("}"))}return r},p=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),f=(e,t=2)=>Number(Number.parseFloat(String(e)).toFixed(t));class h{constructor(e,t="en",r="us"){this.getLocale=()=>this.locale,this.setLocale=e=>this.locale=e,this.getCountry=()=>this.country,this.setCountry=e=>this.country=e,this.getIndexDay=()=>"us"===this.country?1:0,this.getIndexMonth=()=>"us"===this.country?0:1,this.getFirstFieldMax=()=>"us"===this.country?12:31,this.getSecondFieldMax=()=>"us"===this.country?31:12,this.getDateFormat=()=>"us"===this.country?"MM/DD/YYYY":"DD/MM/YYYY",this.translate=(e,t="")=>{if(!p(this.resources,this.locale))return`INTERNAL_ERROR: cannot find locale ${this.locale} in resources object`;const r=this.resources[this.locale];if(!e)return"INTERNAL_ERROR: path variable must not be empty";const o=e.split(".").reduce((e,t)=>p(e,t)?e[t]:"",r);return o||(t||`INTERNAL_ERROR: cannot find message with path = ${e}`)},this.resources=e,this.locale=t,this.country=r}}let b=!0,g=!0,j="[ERROR]";const O=e=>b=e,d=e=>g=e,m=e=>j=e,w=e=>{b&&("string"==typeof e||"number"==typeof e||"boolean"==typeof e?console.log(e):console.log(JSON.stringify(e,void 0,2)))},A=e=>{let t="";return e.message&&"string"==typeof e.message?(e.message.replace(`${j} `,""),t=`${j} ${e.message}`):t="string"==typeof e||"number"==typeof e||"boolean"==typeof e?`${j} ${e}`:`${j}\n${JSON.stringify(e,void 0,2)}`,t=t.replace(`${j} ${j}`,j),g&&console.log(t),t},R=(e,t)=>r=>{if(!Object.prototype.hasOwnProperty.call(e,r))throw new Error(`cannot find ${r}`);const o=e[r];if(typeof o!==t)throw new Error(`type of ${r} is incorrect`);return o},$=(e,t,r)=>(o,s)=>{if(!Object.prototype.hasOwnProperty.call(e,o))throw new Error(`cannot find ${o}`);const n=e[o];if(typeof n!==r)throw new Error(`type of ${o} is incorrect`);n!==s&&(e[o]=s,t())},_=(e,t)=>{for(const r of Object.keys(e))if(p(t,r)){const o=t[r];null!=o&&(Array.isArray(o)?e[r]=o.slice(0):"object"==typeof o?_(e[r],o):e[r]=o)}},E=e=>e.replace(/[\D\s\._\-]+/g,""),M=e=>new Promise(t=>setTimeout(t,e)),N=()=>Math.floor(Date.now()/1e3);export{h as Locales,t as allFilled,r as blank2empty,o as camelize,s as cloneSimple,n as copySimple,i as diffSimple,A as elog,a as email2key,l as empty2blank,e as filled,y as formatCPF,u as getObjectKeys,p as hasProp,f as limitNumDecimals,R as makeGetField,$ as makeSetField,_ as maybeCopySimple,w as mlog,E as numOnly,d as setElog,m as setElogPrefix,O as setMlog,c as shallowCompareArrays,M as sleep,N as unixTimeNow}; | ||
const e=e=>""!==e&&"null"!==e,t=(t,r)=>{let o;o=r?Object.keys(t).filter(e=>!r.includes(e)):Object.keys(t);for(const r of o)if(!e(t[r]))return!1;return!0},r=(e,t="__EMPTY__",o=!1)=>Object.keys(e).reduce((s,n)=>({...s,[n]:null===e[n]||void 0===e[n]?o?e[n]:t:Array.isArray(e[n])?e[n].map(e=>""===e?t:e):"object"==typeof e[n]?r(e[n],t):""===e[n]?t:e[n]}),{}),o=(e,t=!1,r="_")=>t?e.split(r).map(e=>e.toLowerCase().replace(/./,e=>e.toUpperCase())).join(""):e.split(r).map((e,t)=>t>0?e.toLowerCase().replace(/./,e=>e.toUpperCase()):e.toLowerCase()).join(""),s=e=>Object.keys(e).reduce((t,r)=>({...t,[r]:Array.isArray(e[r])?e[r].slice(0):"object"==typeof e[r]?s(e[r]):e[r]}),{}),n=(e,t)=>{const r=Object.keys(e);for(const o of r){const r=t[o];Array.isArray(r)?e[o]=r.slice(0):"object"==typeof r?n(e[o],r):e[o]=r}},c=(e,t)=>{if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0},i=(e,t)=>{const r=Object.keys(e);for(const o of r){const r=t[o];if(Array.isArray(r)){if(!c(e[o],r))return!0}else if("object"==typeof e[o]&&null!==e[o]){if(i(e[o],r))return!0}else if(e[o]!==r)return!0}return!1},l=e=>e.toLowerCase().replace(/[@\.]/g,"_"),a=(e,t="__EMPTY__",r=!1)=>Object.keys(e).reduce((o,s)=>({...o,[s]:null===e[s]||void 0===e[s]?r?e[s]:"":Array.isArray(e[s])?e[s].map(e=>e===t?"":e):"object"==typeof e[s]?a(e[s],t):e[s]===t?"":e[s]}),{}),y=e=>{const t=e.replace(/[\D\s._-]+/g,"");let r=4;const o=[];for(let e=0,s=t.length;e<s;e+=r)r=e<9?3:2,o.push(t.substr(e,r));return o.length>=4?o.slice(0,3).join(".")+"-"+o[3]:o.join(".")},u=(e,t=!0)=>{const r=[];for(const o of Object.keys(e)){const s=e[o];r.push(o),"object"!=typeof s||Array.isArray(s)||(t&&r.push("{"),u(s,t).forEach(e=>r.push(e)),t&&r.push("}"))}return r},p=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),f=(e,t=2)=>Number(Number.parseFloat(String(e)).toFixed(t));class h{constructor(e,t="en",r="us"){this.getLocale=()=>this.locale,this.setLocale=e=>this.locale=e,this.getCountry=()=>this.country,this.setCountry=e=>this.country=e,this.getIndexDay=()=>"us"===this.country?1:0,this.getIndexMonth=()=>"us"===this.country?0:1,this.getFirstFieldMax=()=>"us"===this.country?12:31,this.getSecondFieldMax=()=>"us"===this.country?31:12,this.getDateFormat=()=>"us"===this.country?"MM/DD/YYYY":"DD/MM/YYYY",this.translate=(e,t="")=>{if(!p(this.resources,this.locale))return`INTERNAL_ERROR: cannot find locale ${this.locale} in resources object`;const r=this.resources[this.locale];if(!e)return"INTERNAL_ERROR: path variable must not be empty";const o=e.split(".").reduce((e,t)=>p(e,t)?e[t]:"",r);return o||(t||`INTERNAL_ERROR: cannot find message with path = ${e}`)},this.resources=e,this.locale=t,this.country=r}}let b=!0,g=!0,j="[ERROR]";const O=e=>b=e,d=e=>g=e,m=e=>j=e,w=e=>{b&&("string"==typeof e||"number"==typeof e||"boolean"==typeof e?console.log(e):console.log(JSON.stringify(e,void 0,2)))},A=e=>{let t="";return e.message&&"string"==typeof e.message?(e.message.replace(`${j} `,""),t=`${j} ${e.message}`):t="string"==typeof e||"number"==typeof e||"boolean"==typeof e?`${j} ${e}`:`${j}\n${JSON.stringify(e,void 0,2)}`,t=t.replace(`${j} ${j}`,j),g&&console.log(t),t},R=(e,t)=>r=>{if(!Object.prototype.hasOwnProperty.call(e,r))throw new Error(`cannot find ${r}`);const o=e[r];if(typeof o!==t)throw new Error(`type of ${r} is incorrect`);return o},$=(e,t,r)=>(o,s)=>{if(!Object.prototype.hasOwnProperty.call(e,o))throw new Error(`cannot find ${o}`);const n=e[o];if(typeof n!==r)throw new Error(`type of ${o} is incorrect`);n!==s&&(e[o]=s,t())},_=(e,t)=>{for(const r of Object.keys(e))if(p(t,r)){const o=t[r];null!=o&&(Array.isArray(o)?e[r]=o.slice(0):"object"==typeof o?_(e[r],o):e[r]=o)}},E=e=>e.replace(/[\D\s\._\-]+/g,""),M=e=>new Promise(t=>setTimeout(t,e)),N=()=>Math.floor(Date.now()/1e3);export{h as Locales,t as allFilled,r as blank2empty,o as camelize,s as cloneSimple,n as copySimple,i as diffSimple,A as elog,l as email2key,a as empty2blank,e as filled,y as formatCPF,u as getObjectKeys,p as hasProp,f as limitNumDecimals,R as makeGetField,$ as makeSetField,_ as maybeCopySimple,w as mlog,E as numOnly,d as setElog,m as setElogPrefix,O as setMlog,c as shallowCompareArrays,M as sleep,N as unixTimeNow}; |
{ | ||
"name": "@cpmech/basic", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"license": "MIT", | ||
@@ -37,3 +37,3 @@ "author": { | ||
"rollup-plugin-terser": "^5.2.0", | ||
"rollup-plugin-typescript2": "^0.25.3", | ||
"rollup-plugin-typescript2": "^0.26.0", | ||
"ts-jest": "^25.2.0", | ||
@@ -45,3 +45,3 @@ "ts-node": "^8.6.2", | ||
}, | ||
"gitHead": "9a1526c47bbfe9c4123d597f58eaf0984f5346a9" | ||
"gitHead": "f533b355c2a21b5c82a40dae4167afd1d2ccb22d" | ||
} |
14587