@cpmech/basic
Advanced tools
Comparing version 3.9.0 to 3.10.0
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const filled=e=>""!==e&&"null"!==e,allFilled=(e,t)=>{let r;r=t?Object.keys(e).filter(e=>!t.includes(e)):Object.keys(e);for(const t of r)if(!filled(e[t]))return!1;return!0},camelize=(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(""),cloneSimple=e=>{const t={};for(const r of Object.keys(e)){const o=e[r];Array.isArray(o)?t[r]=o.slice(0):t[r]="object"==typeof o?cloneSimple(o):o}return t},copySimple=(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?copySimple(e[o],r):e[o]=r}},email2key=e=>e.toLowerCase().replace(/[@\.]/g,"_"),ext2type=e=>{switch(e){case"jpeg":case"jpg":return"image/jpeg";case"png":return"image/png";case"pdf":return"application/pdf"}throw new Error(`cannot handle file extension = ${e} at this time`)},type2ext=e=>{switch(e){case"image/jpeg":return"jpeg";case"image/png":return"png";case"application/pdf":return"pdf"}throw new Error(`cannot handle content-type = ${e} at this time`)},formatCPF=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(".")},getObjectKeys=(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("{"),getObjectKeys(s,t).forEach(e=>r.push(e)),t&&r.push("}"))}return r},hasProp=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);class Locales{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(!hasProp(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)=>hasProp(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}}const makeGetField=(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},makeSetField=(e,t,r)=>(o,s)=>{if(!Object.prototype.hasOwnProperty.call(e,o))throw new Error(`cannot find ${o}`);const l=e[o];if(typeof l!==r)throw new Error(`type of ${o} is incorrect`);l!==s&&(e[o]=s,t())},maybeCopySimple=(e,t)=>{for(const r of Object.keys(e))if(hasProp(t,r)){const o=t[r];null!=o&&(Array.isArray(o)?e[r]=o.slice(0):"object"==typeof o?maybeCopySimple(e[r],o):e[r]=o)}},numOnly=e=>e.replace(/[\D\s\._\-]+/g,""),sleep=e=>new Promise(t=>setTimeout(t,e)),shallowCompareArrays=(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};exports.Locales=Locales,exports.allFilled=allFilled,exports.camelize=camelize,exports.cloneSimple=cloneSimple,exports.copySimple=copySimple,exports.email2key=email2key,exports.ext2type=ext2type,exports.filled=filled,exports.formatCPF=formatCPF,exports.getObjectKeys=getObjectKeys,exports.hasProp=hasProp,exports.makeGetField=makeGetField,exports.makeSetField=makeSetField,exports.maybeCopySimple=maybeCopySimple,exports.numOnly=numOnly,exports.shallowCompareArrays=shallowCompareArrays,exports.sleep=sleep,exports.type2ext=type2ext; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const filled=e=>""!==e&&"null"!==e,allFilled=(e,t)=>{let o;o=t?Object.keys(e).filter(e=>!t.includes(e)):Object.keys(e);for(const t of o)if(!filled(e[t]))return!1;return!0},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(""),cloneSimple=e=>Object.keys(e).reduce((t,o)=>({...t,[o]:Array.isArray(e[o])?e[o].slice(0):"object"==typeof e[o]?cloneSimple(e[o]):e[o]}),{}),copySimple=(e,t)=>{const o=Object.keys(e);for(const r of o){const o=t[r];Array.isArray(o)?e[r]=o.slice(0):"object"==typeof o?copySimple(e[r],o):e[r]=o}},email2key=e=>e.toLowerCase().replace(/[@\.]/g,"_"),fileExtensions=["jpeg","jpg","png","pdf"],fileExtensionEnums=["JPEG","JPG","PNG","PDF"],ext2type=e=>{switch(e){case"jpeg":case"jpg":return"image/jpeg";case"png":return"image/png";case"pdf":return"application/pdf"}throw new Error(`cannot handle file extension = ${e} at this time`)},type2ext=e=>{switch(e){case"image/jpeg":return"jpeg";case"image/png":return"png";case"application/pdf":return"pdf"}throw new Error(`cannot handle content-type = ${e} at this time`)},file2ext=e=>{const t=e.split(".");if(t.length<2)throw new Error("filename does not have extension");const o=t.pop();if(!o)throw new Error("filename does not have extension");const r=o.trim();if(!r)throw new Error("filename does not have extension");return r.toLowerCase()},ext2enum=e=>{const t=e.trim().toUpperCase();if(!fileExtensionEnums.includes(t))throw new Error(`file extension must be in: ${fileExtensions.join(",")}`);return t},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(".")},getObjectKeys=(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("{"),getObjectKeys(s,t).forEach(e=>o.push(e)),t&&o.push("}"))}return o},hasProp=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);class Locales{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(!hasProp(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)=>hasProp(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}}const 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},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())},maybeCopySimple=(e,t)=>{for(const o of Object.keys(e))if(hasProp(t,o)){const r=t[o];null!=r&&(Array.isArray(r)?e[o]=r.slice(0):"object"==typeof r?maybeCopySimple(e[o],r):e[o]=r)}},numOnly=e=>e.replace(/[\D\s\._\-]+/g,""),sleep=e=>new Promise(t=>setTimeout(t,e)),shallowCompareArrays=(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};exports.Locales=Locales,exports.allFilled=allFilled,exports.camelize=camelize,exports.cloneSimple=cloneSimple,exports.copySimple=copySimple,exports.email2key=email2key,exports.ext2enum=ext2enum,exports.ext2type=ext2type,exports.file2ext=file2ext,exports.fileExtensionEnums=fileExtensionEnums,exports.fileExtensions=fileExtensions,exports.filled=filled,exports.formatCPF=formatCPF,exports.getObjectKeys=getObjectKeys,exports.hasProp=hasProp,exports.makeGetField=makeGetField,exports.makeSetField=makeSetField,exports.maybeCopySimple=maybeCopySimple,exports.numOnly=numOnly,exports.shallowCompareArrays=shallowCompareArrays,exports.sleep=sleep,exports.type2ext=type2ext; |
import { Iany } from './types'; | ||
export declare const cloneSimple: (obj: Iany) => Iany; | ||
export declare const cloneSimple: <T extends Iany>(obj: T) => T; |
export declare type FileContentType = 'image/jpeg' | 'image/png' | 'application/pdf'; | ||
export declare type FileExtension = 'jpg' | 'jpeg' | 'png' | 'pdf'; | ||
export declare type FileExtension = 'jpeg' | 'jpg' | 'png' | 'pdf'; | ||
export declare type FileExtensionEnum = 'JPEG' | 'JPG' | 'PNG' | 'PDF'; | ||
export declare const fileExtensions: FileExtension[]; | ||
export declare const fileExtensionEnums: FileExtensionEnum[]; | ||
export declare const ext2type: (ext: FileExtension) => FileContentType; | ||
export declare const type2ext: (ctype: FileContentType) => FileExtension; |
@@ -6,2 +6,3 @@ export * from './allFilled'; | ||
export * from './email2key'; | ||
export * from './file2extension'; | ||
export * from './fileTypeAndExt'; | ||
@@ -8,0 +9,0 @@ export * from './filled'; |
@@ -1,1 +0,1 @@ | ||
const t=t=>""!==t&&"null"!==t,e=(e,r)=>{let o;o=r?Object.keys(e).filter(t=>!r.includes(t)):Object.keys(e);for(const r of o)if(!t(e[r]))return!1;return!0},r=(t,e=!1,r="_")=>e?t.split(r).map(t=>t.toLowerCase().replace(/./,t=>t.toUpperCase())).join(""):t.split(r).map((t,e)=>e>0?t.toLowerCase().replace(/./,t=>t.toUpperCase()):t.toLowerCase()).join(""),o=t=>{const e={};for(const r of Object.keys(t)){const s=t[r];Array.isArray(s)?e[r]=s.slice(0):e[r]="object"==typeof s?o(s):s}return e},s=(t,e)=>{const r=Object.keys(t);for(const o of r){const r=e[o];Array.isArray(r)?t[o]=r.slice(0):"object"==typeof r?s(t[o],r):t[o]=r}},n=t=>t.toLowerCase().replace(/[@\.]/g,"_"),c=t=>{switch(t){case"jpeg":case"jpg":return"image/jpeg";case"png":return"image/png";case"pdf":return"application/pdf"}throw new Error(`cannot handle file extension = ${t} at this time`)},i=t=>{switch(t){case"image/jpeg":return"jpeg";case"image/png":return"png";case"application/pdf":return"pdf"}throw new Error(`cannot handle content-type = ${t} at this time`)},a=t=>{const e=t.replace(/[\D\s._-]+/g,"");let r=4;const o=[];for(let t=0,s=e.length;t<s;t+=r)r=t<9?3:2,o.push(e.substr(t,r));return o.length>=4?o.slice(0,3).join(".")+"-"+o[3]:o.join(".")},l=(t,e=!0)=>{const r=[];for(const o of Object.keys(t)){const s=t[o];r.push(o),"object"!=typeof s||Array.isArray(s)||(e&&r.push("{"),l(s,e).forEach(t=>r.push(t)),e&&r.push("}"))}return r},p=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class h{constructor(t,e="en",r="us"){this.getLocale=()=>this.locale,this.setLocale=t=>this.locale=t,this.getCountry=()=>this.country,this.setCountry=t=>this.country=t,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=(t,e="")=>{if(!p(this.resources,this.locale))return`INTERNAL_ERROR: cannot find locale ${this.locale} in resources object`;const r=this.resources[this.locale];if(!t)return"INTERNAL_ERROR: path variable must not be empty";const o=t.split(".").reduce((t,e)=>p(t,e)?t[e]:"",r);return o||(e||`INTERNAL_ERROR: cannot find message with path = ${t}`)},this.resources=t,this.locale=e,this.country=r}}const u=(t,e)=>r=>{if(!Object.prototype.hasOwnProperty.call(t,r))throw new Error(`cannot find ${r}`);const o=t[r];if(typeof o!==e)throw new Error(`type of ${r} is incorrect`);return o},f=(t,e,r)=>(o,s)=>{if(!Object.prototype.hasOwnProperty.call(t,o))throw new Error(`cannot find ${o}`);const n=t[o];if(typeof n!==r)throw new Error(`type of ${o} is incorrect`);n!==s&&(t[o]=s,e())},y=(t,e)=>{for(const r of Object.keys(t))if(p(e,r)){const o=e[r];null!=o&&(Array.isArray(o)?t[r]=o.slice(0):"object"==typeof o?y(t[r],o):t[r]=o)}},g=t=>t.replace(/[\D\s\._\-]+/g,""),j=t=>new Promise(e=>setTimeout(e,t)),w=(t,e)=>{if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0};export{h as Locales,e as allFilled,r as camelize,o as cloneSimple,s as copySimple,n as email2key,c as ext2type,t as filled,a as formatCPF,l as getObjectKeys,p as hasProp,u as makeGetField,f as makeSetField,y as maybeCopySimple,g as numOnly,w as shallowCompareArrays,j as sleep,i as type2ext}; | ||
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=!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(""),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]}),{}),s=(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?s(e[o],r):e[o]=r}},n=e=>e.toLowerCase().replace(/[@\.]/g,"_"),i=["jpeg","jpg","png","pdf"],c=["JPEG","JPG","PNG","PDF"],a=e=>{switch(e){case"jpeg":case"jpg":return"image/jpeg";case"png":return"image/png";case"pdf":return"application/pdf"}throw new Error(`cannot handle file extension = ${e} at this time`)},p=e=>{switch(e){case"image/jpeg":return"jpeg";case"image/png":return"png";case"application/pdf":return"pdf"}throw new Error(`cannot handle content-type = ${e} at this time`)},l=e=>{const t=e.split(".");if(t.length<2)throw new Error("filename does not have extension");const r=t.pop();if(!r)throw new Error("filename does not have extension");const o=r.trim();if(!o)throw new Error("filename does not have extension");return o.toLowerCase()},h=e=>{const t=e.trim().toUpperCase();if(!c.includes(t))throw new Error(`file extension must be in: ${i.join(",")}`);return t},u=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(".")},f=(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("{"),f(s,t).forEach(e=>r.push(e)),t&&r.push("}"))}return r},y=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);class g{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(!y(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)=>y(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}}const w=(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},j=(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())},d=(e,t)=>{for(const r of Object.keys(e))if(y(t,r)){const o=t[r];null!=o&&(Array.isArray(o)?e[r]=o.slice(0):"object"==typeof o?d(e[r],o):e[r]=o)}},m=e=>e.replace(/[\D\s\._\-]+/g,""),b=e=>new Promise(t=>setTimeout(t,e)),E=(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};export{g as Locales,t as allFilled,r as camelize,o as cloneSimple,s as copySimple,n as email2key,h as ext2enum,a as ext2type,l as file2ext,c as fileExtensionEnums,i as fileExtensions,e as filled,u as formatCPF,f as getObjectKeys,y as hasProp,w as makeGetField,j as makeSetField,d as maybeCopySimple,m as numOnly,E as shallowCompareArrays,b as sleep,p as type2ext}; |
{ | ||
"name": "@cpmech/basic", | ||
"version": "3.9.0", | ||
"version": "3.10.0", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "author": { | ||
}, | ||
"gitHead": "5d1ad851ae7ed38eaec7780532fc919494b83106" | ||
"gitHead": "ae7a5c919184803ee8cb19511407c23523238808" | ||
} |
14348
28
106