diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index f8220ce..3713b23 100755 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - node_version: [14.x, 15.x, 16.x, 17.x] + node_version: [14.x, 15.x, 16.x, 17.x, 18.x] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..2124bd6 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '33 18 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/README.md b/README.md index d261ad2..e25b968 100755 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Lightweight util for handling data type, string... in your Node.js and browser a [![NPM](https://badge.fury.io/js/bellajs.svg)](https://badge.fury.io/js/bellajs) ![CI test](https://github.com/ndaidong/bellajs/workflows/ci-test/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/ndaidong/bellajs/badge.svg)](https://coveralls.io/github/ndaidong/bellajs) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ndaidong_bellajs&metric=alert_status)](https://sonarcloud.io/dashboard?id=ndaidong_bellajs) +![CodeQL](https://github.com/ndaidong/bellajs/workflows/CodeQL/badge.svg) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) You may be interested in [BellaPy](https://github.com/ndaidong/bellapy) too. diff --git a/dist/bella.esm.js b/dist/bella.esm.js index f56bd8f..2acbecd 100644 --- a/dist/bella.esm.js +++ b/dist/bella.esm.js @@ -1,2 +1,2 @@ -// bellajs@11.0.2, by @ndaidong - built with esbuild at 2022-02-19T05:03:20.038Z - published under MIT license +// bellajs@11.0.3, by @ndaidong - built with esbuild at 2022-06-03T15:04:16.581Z - published under MIT license var h=t=>({}).toString.call(t),F=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,R=t=>Boolean(t)===t,N=t=>h(t)==="[object Null]",_=t=>h(t)==="[object Undefined]",T=t=>_(t)||N(t),z=t=>h(t)==="[object Function]",l=t=>h(t)==="[object Object]"&&!u(t),m=t=>t instanceof Date&&!isNaN(t.valueOf()),B=t=>h(t).match(/^\[object HTML\w*Element]$/)!==null,H=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},$=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},w=t=>!t||T(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var S=(t,e)=>{if(w(t)&&w(e))return!0;if(m(t)&&m(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=D),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},K=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Z=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),v=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),k=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},tt=t=>g(t).split(" ").map(e=>k(e)).join(" "),j=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=j(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=j(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},et=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthI(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var O={dateStyle:"medium",timeStyle:"long"},d={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},L=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},st=(...t)=>{let e=t[0],r=L(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?O:l(t[1])?t[1]:O;return new Intl.DateTimeFormat(r,n).format(new Date(e))},ct=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=d.second)return r;let s="second";for(let c in d){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var pt=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var at=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),m(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},P=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=P(s,e[o],r,n):e[o]=M(s)}return e},dt=(t=[])=>[...new Set(t)],C=(t,e)=>t>e?1:t{let r=[...t],n=e||C;return r.sort(n),r},wt=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:U(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},jt=(t=[],e=1)=>{let r=q(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};export{M as clone,pt as compose,P as copies,ut as curry,S as equals,Z as escapeHTML,st as formatDateString,ct as formatTimeAgo,et as genid,a as hasProperty,u as isArray,R as isBoolean,m as isDate,B as isElement,$ as isEmail,w as isEmpty,z as isFunction,F as isInteger,H as isLetter,T as isNil,N as isNull,y as isNumber,l as isObject,p as isString,_ as isUndefined,b as maybe,jt as pick,at as pipe,A as randint,j as replaceAll,q as shuffle,rt as slugify,U as sort,wt as sortBy,I as stripAccent,Q as stripTags,K as truncate,k as ucfirst,tt as ucwords,v as unescapeHTML,dt as unique}; diff --git a/dist/bella.iife.js b/dist/bella.iife.js index 8a6f44b..d039588 100644 --- a/dist/bella.iife.js +++ b/dist/bella.iife.js @@ -1,2 +1,2 @@ -// bellajs@11.0.2, by @ndaidong - built with esbuild at 2022-02-19T05:03:20.038Z - published under MIT license -var bella=(()=>{var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=t=>S(t,"__esModule",{value:!0});var z=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!F.call(t,o)&&(r||o!=="default")&&S(t,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return t};var H=(t=>(e,r)=>t&&t.get(e)||(r=B(R({}),e,1),t&&t.set(e,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var gt={};z(gt,{clone:()=>M,compose:()=>it,copies:()=>I,curry:()=>ct,equals:()=>A,escapeHTML:()=>Z,formatDateString:()=>ot,formatTimeAgo:()=>st,genid:()=>et,hasProperty:()=>a,isArray:()=>u,isBoolean:()=>V,isDate:()=>h,isElement:()=>G,isEmail:()=>Y,isEmpty:()=>d,isFunction:()=>X,isInteger:()=>$,isLetter:()=>W,isNil:()=>_,isNull:()=>E,isNumber:()=>y,isObject:()=>l,isString:()=>p,isUndefined:()=>N,maybe:()=>b,pick:()=>at,pipe:()=>ut,randint:()=>O,replaceAll:()=>w,shuffle:()=>P,slugify:()=>rt,sort:()=>L,sortBy:()=>ft,stripAccent:()=>D,stripTags:()=>Q,truncate:()=>K,ucfirst:()=>T,ucwords:()=>tt,unescapeHTML:()=>v,unique:()=>lt});var m=t=>({}).toString.call(t),$=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,V=t=>Boolean(t)===t,E=t=>m(t)==="[object Null]",N=t=>m(t)==="[object Undefined]",_=t=>N(t)||E(t),X=t=>m(t)==="[object Function]",l=t=>m(t)==="[object Object]"&&!u(t),h=t=>t instanceof Date&&!isNaN(t.valueOf()),G=t=>m(t).match(/^\[object HTML\w*Element]$/)!==null,W=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},Y=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},d=t=>!t||_(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var A=(t,e)=>{if(d(t)&&d(e))return!0;if(h(t)&&h(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=J),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},K=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Z=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),v=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),T=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},tt=t=>g(t).split(" ").map(e=>T(e)).join(" "),w=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=w(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=w(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},et=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthD(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var k={dateStyle:"medium",timeStyle:"long"},j={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},nt=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},ot=(...t)=>{let e=t[0],r=nt(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?k:l(t[1])?t[1]:k;return new Intl.DateTimeFormat(r,n).format(new Date(e))},st=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=j.second)return r;let s="second";for(let c in j){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var it=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var ut=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),h(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},I=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=I(s,e[o],r,n):e[o]=M(s)}return e},lt=(t=[])=>[...new Set(t)],pt=(t,e)=>t>e?1:t{let r=[...t],n=e||pt;return r.sort(n),r},ft=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:L(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},at=(t=[],e=1)=>{let r=P(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};return H(gt);})(); +// bellajs@11.0.3, by @ndaidong - built with esbuild at 2022-06-03T15:04:16.581Z - published under MIT license +var bella=(()=>{var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},z=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!F.call(t,o)&&o!==r&&S(t,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return t};var B=t=>z(S({},"__esModule",{value:!0}),t);var at={};R(at,{clone:()=>M,compose:()=>ct,copies:()=>I,curry:()=>st,equals:()=>A,escapeHTML:()=>Q,formatDateString:()=>nt,formatTimeAgo:()=>ot,genid:()=>tt,hasProperty:()=>a,isArray:()=>u,isBoolean:()=>$,isDate:()=>h,isElement:()=>X,isEmail:()=>W,isEmpty:()=>d,isFunction:()=>V,isInteger:()=>H,isLetter:()=>G,isNil:()=>_,isNull:()=>E,isNumber:()=>y,isObject:()=>l,isString:()=>p,isUndefined:()=>N,maybe:()=>b,pick:()=>ft,pipe:()=>it,randint:()=>O,replaceAll:()=>w,shuffle:()=>P,slugify:()=>et,sort:()=>L,sortBy:()=>pt,stripAccent:()=>D,stripTags:()=>K,truncate:()=>J,ucfirst:()=>T,ucwords:()=>v,unescapeHTML:()=>Z,unique:()=>ut});var m=t=>({}).toString.call(t),H=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,$=t=>Boolean(t)===t,E=t=>m(t)==="[object Null]",N=t=>m(t)==="[object Undefined]",_=t=>N(t)||E(t),V=t=>m(t)==="[object Function]",l=t=>m(t)==="[object Object]"&&!u(t),h=t=>t instanceof Date&&!isNaN(t.valueOf()),X=t=>m(t).match(/^\[object HTML\w*Element]$/)!==null,G=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},W=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},d=t=>!t||_(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var A=(t,e)=>{if(d(t)&&d(e))return!0;if(h(t)&&h(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=Y),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},J=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Q=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),Z=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),T=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},v=t=>g(t).split(" ").map(e=>T(e)).join(" "),w=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=w(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=w(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},tt=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthD(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var k={dateStyle:"medium",timeStyle:"long"},j={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},rt=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},nt=(...t)=>{let e=t[0],r=rt(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?k:l(t[1])?t[1]:k;return new Intl.DateTimeFormat(r,n).format(new Date(e))},ot=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=j.second)return r;let s="second";for(let c in j){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var ct=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var it=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),h(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},I=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=I(s,e[o],r,n):e[o]=M(s)}return e},ut=(t=[])=>[...new Set(t)],lt=(t,e)=>t>e?1:t{let r=[...t],n=e||lt;return r.sort(n),r},pt=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:L(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},ft=(t=[],e=1)=>{let r=P(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};return B(at);})(); diff --git a/dist/bella.min.js b/dist/bella.min.js index 8a6f44b..d039588 100644 --- a/dist/bella.min.js +++ b/dist/bella.min.js @@ -1,2 +1,2 @@ -// bellajs@11.0.2, by @ndaidong - built with esbuild at 2022-02-19T05:03:20.038Z - published under MIT license -var bella=(()=>{var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=t=>S(t,"__esModule",{value:!0});var z=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!F.call(t,o)&&(r||o!=="default")&&S(t,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return t};var H=(t=>(e,r)=>t&&t.get(e)||(r=B(R({}),e,1),t&&t.set(e,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var gt={};z(gt,{clone:()=>M,compose:()=>it,copies:()=>I,curry:()=>ct,equals:()=>A,escapeHTML:()=>Z,formatDateString:()=>ot,formatTimeAgo:()=>st,genid:()=>et,hasProperty:()=>a,isArray:()=>u,isBoolean:()=>V,isDate:()=>h,isElement:()=>G,isEmail:()=>Y,isEmpty:()=>d,isFunction:()=>X,isInteger:()=>$,isLetter:()=>W,isNil:()=>_,isNull:()=>E,isNumber:()=>y,isObject:()=>l,isString:()=>p,isUndefined:()=>N,maybe:()=>b,pick:()=>at,pipe:()=>ut,randint:()=>O,replaceAll:()=>w,shuffle:()=>P,slugify:()=>rt,sort:()=>L,sortBy:()=>ft,stripAccent:()=>D,stripTags:()=>Q,truncate:()=>K,ucfirst:()=>T,ucwords:()=>tt,unescapeHTML:()=>v,unique:()=>lt});var m=t=>({}).toString.call(t),$=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,V=t=>Boolean(t)===t,E=t=>m(t)==="[object Null]",N=t=>m(t)==="[object Undefined]",_=t=>N(t)||E(t),X=t=>m(t)==="[object Function]",l=t=>m(t)==="[object Object]"&&!u(t),h=t=>t instanceof Date&&!isNaN(t.valueOf()),G=t=>m(t).match(/^\[object HTML\w*Element]$/)!==null,W=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},Y=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},d=t=>!t||_(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var A=(t,e)=>{if(d(t)&&d(e))return!0;if(h(t)&&h(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=J),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},K=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Z=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),v=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),T=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},tt=t=>g(t).split(" ").map(e=>T(e)).join(" "),w=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=w(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=w(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},et=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthD(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var k={dateStyle:"medium",timeStyle:"long"},j={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},nt=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},ot=(...t)=>{let e=t[0],r=nt(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?k:l(t[1])?t[1]:k;return new Intl.DateTimeFormat(r,n).format(new Date(e))},st=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=j.second)return r;let s="second";for(let c in j){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var it=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var ut=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),h(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},I=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=I(s,e[o],r,n):e[o]=M(s)}return e},lt=(t=[])=>[...new Set(t)],pt=(t,e)=>t>e?1:t{let r=[...t],n=e||pt;return r.sort(n),r},ft=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:L(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},at=(t=[],e=1)=>{let r=P(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};return H(gt);})(); +// bellajs@11.0.3, by @ndaidong - built with esbuild at 2022-06-03T15:04:16.581Z - published under MIT license +var bella=(()=>{var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},z=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!F.call(t,o)&&o!==r&&S(t,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return t};var B=t=>z(S({},"__esModule",{value:!0}),t);var at={};R(at,{clone:()=>M,compose:()=>ct,copies:()=>I,curry:()=>st,equals:()=>A,escapeHTML:()=>Q,formatDateString:()=>nt,formatTimeAgo:()=>ot,genid:()=>tt,hasProperty:()=>a,isArray:()=>u,isBoolean:()=>$,isDate:()=>h,isElement:()=>X,isEmail:()=>W,isEmpty:()=>d,isFunction:()=>V,isInteger:()=>H,isLetter:()=>G,isNil:()=>_,isNull:()=>E,isNumber:()=>y,isObject:()=>l,isString:()=>p,isUndefined:()=>N,maybe:()=>b,pick:()=>ft,pipe:()=>it,randint:()=>O,replaceAll:()=>w,shuffle:()=>P,slugify:()=>et,sort:()=>L,sortBy:()=>pt,stripAccent:()=>D,stripTags:()=>K,truncate:()=>J,ucfirst:()=>T,ucwords:()=>v,unescapeHTML:()=>Z,unique:()=>ut});var m=t=>({}).toString.call(t),H=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,$=t=>Boolean(t)===t,E=t=>m(t)==="[object Null]",N=t=>m(t)==="[object Undefined]",_=t=>N(t)||E(t),V=t=>m(t)==="[object Function]",l=t=>m(t)==="[object Object]"&&!u(t),h=t=>t instanceof Date&&!isNaN(t.valueOf()),X=t=>m(t).match(/^\[object HTML\w*Element]$/)!==null,G=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},W=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},d=t=>!t||_(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var A=(t,e)=>{if(d(t)&&d(e))return!0;if(h(t)&&h(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=Y),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},J=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Q=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),Z=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),T=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},v=t=>g(t).split(" ").map(e=>T(e)).join(" "),w=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=w(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=w(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},tt=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthD(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var k={dateStyle:"medium",timeStyle:"long"},j={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},rt=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},nt=(...t)=>{let e=t[0],r=rt(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?k:l(t[1])?t[1]:k;return new Intl.DateTimeFormat(r,n).format(new Date(e))},ot=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=j.second)return r;let s="second";for(let c in j){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var ct=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var it=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),h(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},I=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=I(s,e[o],r,n):e[o]=M(s)}return e},ut=(t=[])=>[...new Set(t)],lt=(t,e)=>t>e?1:t{let r=[...t],n=e||lt;return r.sort(n),r},pt=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:L(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},ft=(t=[],e=1)=>{let r=P(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};return B(at);})(); diff --git a/dist/cjs/bella.js b/dist/cjs/bella.js index 637226a..3887512 100644 --- a/dist/cjs/bella.js +++ b/dist/cjs/bella.js @@ -1,2 +1,2 @@ -// bellajs@11.0.2, by @ndaidong - built with esbuild at 2022-02-19T05:03:20.038Z - published under MIT license -var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=t=>S(t,"__esModule",{value:!0});var z=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!F.call(t,o)&&(r||o!=="default")&&S(t,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return t};var H=(t=>(e,r)=>t&&t.get(e)||(r=B(R({}),e,1),t&&t.set(e,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var gt={};z(gt,{clone:()=>M,compose:()=>it,copies:()=>I,curry:()=>ct,equals:()=>A,escapeHTML:()=>Z,formatDateString:()=>ot,formatTimeAgo:()=>st,genid:()=>et,hasProperty:()=>a,isArray:()=>u,isBoolean:()=>V,isDate:()=>h,isElement:()=>G,isEmail:()=>Y,isEmpty:()=>d,isFunction:()=>X,isInteger:()=>$,isLetter:()=>W,isNil:()=>_,isNull:()=>E,isNumber:()=>y,isObject:()=>l,isString:()=>p,isUndefined:()=>N,maybe:()=>b,pick:()=>at,pipe:()=>ut,randint:()=>O,replaceAll:()=>w,shuffle:()=>P,slugify:()=>rt,sort:()=>L,sortBy:()=>ft,stripAccent:()=>D,stripTags:()=>Q,truncate:()=>K,ucfirst:()=>T,ucwords:()=>tt,unescapeHTML:()=>v,unique:()=>lt});var m=t=>({}).toString.call(t),$=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,V=t=>Boolean(t)===t,E=t=>m(t)==="[object Null]",N=t=>m(t)==="[object Undefined]",_=t=>N(t)||E(t),X=t=>m(t)==="[object Function]",l=t=>m(t)==="[object Object]"&&!u(t),h=t=>t instanceof Date&&!isNaN(t.valueOf()),G=t=>m(t).match(/^\[object HTML\w*Element]$/)!==null,W=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},Y=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},d=t=>!t||_(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var A=(t,e)=>{if(d(t)&&d(e))return!0;if(h(t)&&h(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=J),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},K=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Z=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),v=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),T=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},tt=t=>g(t).split(" ").map(e=>T(e)).join(" "),w=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=w(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=w(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},et=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthD(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var k={dateStyle:"medium",timeStyle:"long"},j={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},nt=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},ot=(...t)=>{let e=t[0],r=nt(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?k:l(t[1])?t[1]:k;return new Intl.DateTimeFormat(r,n).format(new Date(e))},st=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=j.second)return r;let s="second";for(let c in j){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var it=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var ut=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),h(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},I=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=I(s,e[o],r,n):e[o]=M(s)}return e},lt=(t=[])=>[...new Set(t)],pt=(t,e)=>t>e?1:t{let r=[...t],n=e||pt;return r.sort(n),r},ft=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:L(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},at=(t=[],e=1)=>{let r=P(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};module.exports=H(gt);0&&(module.exports={clone,compose,copies,curry,equals,escapeHTML,formatDateString,formatTimeAgo,genid,hasProperty,isArray,isBoolean,isDate,isElement,isEmail,isEmpty,isFunction,isInteger,isLetter,isNil,isNull,isNumber,isObject,isString,isUndefined,maybe,pick,pipe,randint,replaceAll,shuffle,slugify,sort,sortBy,stripAccent,stripTags,truncate,ucfirst,ucwords,unescapeHTML,unique}); +// bellajs@11.0.3, by @ndaidong - built with esbuild at 2022-06-03T15:04:16.581Z - published under MIT license +var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},z=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!F.call(t,o)&&o!==r&&S(t,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return t};var B=t=>z(S({},"__esModule",{value:!0}),t);var at={};R(at,{clone:()=>M,compose:()=>ct,copies:()=>I,curry:()=>st,equals:()=>A,escapeHTML:()=>Q,formatDateString:()=>nt,formatTimeAgo:()=>ot,genid:()=>tt,hasProperty:()=>a,isArray:()=>u,isBoolean:()=>$,isDate:()=>h,isElement:()=>X,isEmail:()=>W,isEmpty:()=>d,isFunction:()=>V,isInteger:()=>H,isLetter:()=>G,isNil:()=>_,isNull:()=>E,isNumber:()=>y,isObject:()=>l,isString:()=>p,isUndefined:()=>N,maybe:()=>b,pick:()=>ft,pipe:()=>it,randint:()=>O,replaceAll:()=>w,shuffle:()=>P,slugify:()=>et,sort:()=>L,sortBy:()=>pt,stripAccent:()=>D,stripTags:()=>K,truncate:()=>J,ucfirst:()=>T,ucwords:()=>v,unescapeHTML:()=>Z,unique:()=>ut});module.exports=B(at);var m=t=>({}).toString.call(t),H=t=>Number.isInteger(t),u=t=>Array.isArray(t),p=t=>String(t)===t,y=t=>Number(t)===t,$=t=>Boolean(t)===t,E=t=>m(t)==="[object Null]",N=t=>m(t)==="[object Undefined]",_=t=>N(t)||E(t),V=t=>m(t)==="[object Function]",l=t=>m(t)==="[object Object]"&&!u(t),h=t=>t instanceof Date&&!isNaN(t.valueOf()),X=t=>m(t).match(/^\[object HTML\w*Element]$/)!==null,G=t=>{let e=/^[a-z]+$/i;return p(t)&&e.test(t)},W=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return p(t)&&e.test(t)},d=t=>!t||_(t)||p(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,a=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var A=(t,e)=>{if(d(t)&&d(e))return!0;if(h(t)&&h(e))return t.getTime()===e.getTime();if(u(t)&&u(e)){if(t.length!==e.length)return!1;let r=!0;for(let n=0;n{if((!t||t<0)&&(t=0),e||(e=Y),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let r=t,n=e-t+1;return Math.floor(Math.random()*n)+r};var g=t=>{let e=y(t)?String(t):t;if(!p(e))throw new Error("InvalidInput: String required.");return e},J=(t,e)=>{let r=g(t),n=e||140;if(r.length<=n)return r;let o=r.substring(0,n),s=o.split(" "),i=s.length,c="";return i>1?(s.pop(),c+=s.join(" "),c.lengthg(t).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),Q=t=>g(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,"""),Z=t=>g(t).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),T=t=>{let e=g(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},v=t=>g(t).split(" ").map(e=>T(e)).join(" "),w=(t,e,r)=>{let n=g(t);if(y(e)&&(e=String(e)),y(r)&&(r=String(r)),p(e)&&p(r))n=n.split(e).join(r);else if(u(e)&&p(r))e.forEach(o=>{n=w(n,o,r)});else if(u(e)&&u(r)&&e.length===r.length){let o=e.length;if(o>0)for(let s=0;s{let e=g(t),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(o,s)=>{e=w(e,o,s)};for(let o in r)a(r,o)&&r[o].split("|").forEach(i=>n(i,o));return e},tt=(t,e="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),s=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=s.length,c=Math.max(t||32,e.length),f=e;for(;f.lengthD(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var k={dateStyle:"medium",timeStyle:"long"},j={second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12},rt=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},nt=(...t)=>{let e=t[0],r=rt(t[1])?t[1]:"en",n=t.length>=3?t[2]:t.length===1?k:l(t[1])?t[1]:k;return new Intl.DateTimeFormat(r,n).format(new Date(e))},ot=(t,e="en",r="just now")=>{let n=new Date(t),o=Date.now()-n;if(o<=j.second)return r;let s="second";for(let c in j){if(o{let e=t.length,r=(n,o)=>n>0?(...s)=>r(n-s.length,[...o,...s]):t(...o);return r(e,[])};var ct=(...t)=>t.reduce((e,r)=>n=>e(r(n)));var it=(...t)=>t.reduce((e,r)=>n=>r(e(n)));var x=(t,e,r,n={})=>{let{writable:o=!1,configurable:s=!1,enumerable:i=!1}=n;Object.defineProperty(t,e,{value:r,writable:o,configurable:s,enumerable:i})};var b=t=>{let e=t,r=()=>e==null,n=()=>e,o=f=>b(e||f()),s=f=>b(f(e)===!0?e:null),i=f=>b(r()?null:f(e)),c=Object.create({});return x(c,"__value__",e,{enumerable:!0}),x(c,"__type__","Maybe",{enumerable:!0}),x(c,"isNil",r),x(c,"value",n),x(c,"map",i),x(c,"if",s),x(c,"else",o),c};var M=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),h(t))return new Date(t.valueOf());let n=s=>{let i=Object.create({});for(let c in s)a(s,c)&&(i[c]=M(s[c],r));return i},o=s=>[...s].map(i=>u(i)?o(i):l(i)?n(i):M(i,r));return u(t)?o(t):l(t)?n(t):t},I=(t,e,r=!1,n=[])=>{for(let o in t)if(!(n.length>0&&n.includes(o))&&(!r||r&&a(e,o))){let s=t[o],i=e[o];l(i)&&l(s)||u(i)&&u(s)?e[o]=I(s,e[o],r,n):e[o]=M(s)}return e},ut=(t=[])=>[...new Set(t)],lt=(t,e)=>t>e?1:t{let r=[...t],n=e||lt;return r.sort(n),r},pt=(t=[],e=1,r="")=>!p(r)||!a(t[0],r)?t:L(t,(n,o)=>n[r]>o[r]?e:n[r]{let e=[...t],r=[],n=e.length;for(;n>0;){let o=Math.floor(Math.random()*n);r.push(e.splice(o,1)[0]),n--}return r},ft=(t=[],e=1)=>{let r=P(t),n=Math.max(1,e),o=Math.min(n,r.length-1);return r.splice(0,o)};0&&(module.exports={clone,compose,copies,curry,equals,escapeHTML,formatDateString,formatTimeAgo,genid,hasProperty,isArray,isBoolean,isDate,isElement,isEmail,isEmpty,isFunction,isInteger,isLetter,isNil,isNull,isNumber,isObject,isString,isUndefined,maybe,pick,pipe,randint,replaceAll,shuffle,slugify,sort,sortBy,stripAccent,stripTags,truncate,ucfirst,ucwords,unescapeHTML,unique}); diff --git a/dist/cjs/package.json b/dist/cjs/package.json index 2a88e91..b5492b7 100644 --- a/dist/cjs/package.json +++ b/dist/cjs/package.json @@ -1,5 +1,5 @@ { "name": "bellajs-cjs", - "version": "11.0.2", + "version": "11.0.3", "main": "./bella.js" } \ No newline at end of file diff --git a/package.json b/package.json index 3fc930d..178902b 100755 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "11.0.2", + "version": "11.0.3", "name": "bellajs", "description": "A useful helper for any javascript program", "homepage": "https://www.npmjs.com/package/bellajs", @@ -18,24 +18,15 @@ "scripts": { "lint": "standard .", "pretest": "npm run lint", - "test": "NODE_ENV=test jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles --env=jsdom", + "test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles --env=jsdom", "build": "node build.js src/main.js", "reset": "node reset" }, "devDependencies": { - "@babel/plugin-transform-modules-commonjs": "^7.16.7", - "esbuild": "^0.14.10", - "jest": "^27.4.7", - "standard": "^16.0.4" - }, - "babel": { - "env": { - "test": { - "plugins": [ - "@babel/plugin-transform-modules-commonjs" - ] - } - } + "esbuild": "^0.14.42", + "jest": "^28.1.0", + "jest-environment-jsdom": "^28.1.0", + "standard": "^17.0.0" }, "standard": { "ignore": [ diff --git a/src/utils/date.test.js b/src/utils/date.test.js index 3e5d714..f998799 100755 --- a/src/utils/date.test.js +++ b/src/utils/date.test.js @@ -2,6 +2,8 @@ /* eslint-env jest */ +import { jest } from '@jest/globals' + import { formatDateString, formatTimeAgo