Comparing version 10.0.0 to 10.0.1
/** | ||
* bellajs@10.0.0 | ||
* built on: Thu, 02 Dec 2021 10:57:05 GMT | ||
* built on: Thu, 02 Dec 2021 13:50:33 GMT | ||
* repository: https://github.com/ndaidong/bellajs | ||
@@ -320,3 +320,3 @@ * maintainer: @ndaidong | ||
const vchar = /\.*\\?([a-z])/gi; | ||
const meridiem = output.match(/(\.*)a{1}(\.*)*/i); | ||
const meridiem = output.includes('a') || output.includes('A'); | ||
const wn = WEEKDAYS; | ||
@@ -624,5 +624,5 @@ const mn = MONTHS; | ||
const fnSort = (a, b) => { | ||
return a > b ? 1 : a < b ? -1 : 0 | ||
return a > b ? 1 : (a < b ? -1 : 0) | ||
}; | ||
const sort = (arr = [], sorting) => { | ||
const sort = (arr = [], sorting = null) => { | ||
const tmp = [...arr]; | ||
@@ -633,3 +633,6 @@ const fn = sorting || fnSort; | ||
}; | ||
const sortBy = (arr = [], order = 1, key) => { | ||
const sortBy = (arr = [], order = 1, key = '') => { | ||
if (!isString(key) || !hasProperty(arr[0], key)) { | ||
return arr | ||
} | ||
return sort(arr, (m, n) => { | ||
@@ -636,0 +639,0 @@ return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0) |
@@ -1,2 +0,2 @@ | ||
// bellajs@10.0.0, by @ndaidong - built on Thu, 02 Dec 2021 10:57:05 GMT - published under MIT license | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bella={})}(this,(function(e){const t=e=>({}.toString.call(e)),r=e=>Array.isArray(e),n=e=>String(e)===e,o=e=>Number(e)===e,a=e=>"[object Null]"===t(e),i=e=>"[object Undefined]"===t(e),s=e=>i(e)||a(e),l=e=>"[object Object]"===t(e)&&!r(e),c=e=>e instanceof Date&&!isNaN(e.valueOf()),u=e=>!e||s(e)||n(e)&&""===e||r(e)&&0===e.length||l(e)&&0===Object.keys(e).length,g=(e,t)=>!(!e||!t)&&Object.prototype.hasOwnProperty.call(e,t),f=(e,t)=>{if(u(e)&&u(t))return!0;if(c(e)&&c(t))return e.getTime()===t.getTime();if(r(e)&&r(t)){if(e.length!==t.length)return!1;let r=!0;for(let n=0;n<e.length;n++)if(!f(e[n],t[n])){r=!1;break}return r}if(l(e)&&l(t)){if(Object.keys(e).length!==Object.keys(t).length)return!1;let r=!0;for(const n in e)if(!g(t,n)||!f(e[n],t[n])){r=!1;break}return r}return e===t},p=Number.MAX_SAFE_INTEGER,h=(e,t)=>{if((!e||e<0)&&(e=0),t||(t=p),e===t)return t;e>t&&(e=Math.min(e,t),t=Math.max(e,t));const r=e,n=t-e+1;return Math.floor(Math.random()*n)+r},d=e=>{const t=o(e)?String(e):e;if(!n(t))throw new Error("InvalidInput: String required.");return t},m=e=>{const t=d(e).toLowerCase();return t.length>1?t.charAt(0).toUpperCase()+t.slice(1):t.toUpperCase()},b=(e,t,a)=>{let i=d(e);if(o(t)&&(t=String(t)),o(a)&&(a=String(a)),n(t)&&n(a)){const e=i.split(t);i=e.join(a)}else if(r(t)&&n(a))t.forEach((e=>{i=b(i,e,a)}));else if(r(t)&&r(a)&&t.length===a.length){const e=t.length;if(e>0)for(let r=0;r<e;r++){const e=t[r],n=a[r];i=b(i,e,n)}}return i},y=e=>{let t=d(e);const r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(e,r)=>{t=b(t,e,r)};for(const e in r)if(g(r,e)){r[e].split("|").forEach((t=>n(t,e)))}return t},w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],M=["January","February","March","April","May","June","July","August","September","October","November","December"],j=()=>new Date,D=()=>Date.now(),S=j().getTimezoneOffset(),N=(()=>{const e=Math.abs(S/60);return["GMT",S<0?"+":"-",String(e).padStart(4,"0")].join("")})(),O=e=>String(e<10?"0"+e:e),I=(e,t="D, M d, Y h:i:s A")=>{const r=c(e)?e:new Date(e);if(!c(r))throw new Error("InvalidInput: Number or Date required.");const n=t.match(/(\.*)a{1}(\.*)*/i),o=w,a=M,i={Y:()=>r.getFullYear(),y:()=>(i.Y()+"").slice(-2),F:()=>a[i.n()-1],M:()=>(i.F()+"").slice(0,3),m:()=>O(i.n()),n:()=>r.getMonth()+1,S:()=>(e=>{let t=e+" ";const r=t.charAt(t.length-2);return t="1"===r?"st":"2"===r?"nd":"3"===r?"rd":"th",t})(i.j()),j:()=>r.getDate(),d:()=>O(i.j()),t:()=>new Date(i.Y(),i.n(),0).getDate(),w:()=>r.getDay(),l:()=>o[i.w()],D:()=>(i.l()+"").slice(0,3),G:()=>r.getHours(),g:()=>i.G()%12||12,h:()=>O(n?i.g():i.G()),i:()=>O(r.getMinutes()),s:()=>O(r.getSeconds()),a:()=>i.G()>11?"pm":"am",A:()=>i.a().toUpperCase(),O:()=>N};return t.replace(/\.*\\?([a-z])/gi,((e,t)=>i[e]?i[e]():t))};const v=(e,t,r,n={})=>{const{writable:o=!1,configurable:a=!1,enumerable:i=!1}=n;Object.defineProperty(e,t,{value:r,writable:o,configurable:a,enumerable:i})},A=e=>{const t=e,r=()=>null==t,n=Object.create({});return v(n,"__value__",t,{enumerable:!0}),v(n,"__type__","Maybe",{enumerable:!0}),v(n,"isNil",r),v(n,"value",(()=>t)),v(n,"map",(e=>A(r()?null:e(t)))),v(n,"if",(e=>A(!0===e(t)?t:null))),v(n,"else",(e=>A(t||e()))),n},T=(e,t=null)=>{const n=t||new Set;if(n.has(e))return e;if(n.add(e),c(e))return new Date(e.valueOf());const o=e=>{const t=Object.create({});for(const r in e)g(e,r)&&(t[r]=T(e[r],n));return t},a=e=>[...e].map((e=>r(e)?a(e):l(e)?o(e):T(e,n)));return r(e)?a(e):l(e)?o(e):e},E=(e,t,n=!1,o=[])=>{for(const a in e)if(!(o.length>0&&o.includes(a))&&(!n||n&&g(t,a))){const i=e[a],s=t[a];l(s)&&l(i)||r(s)&&r(i)?t[a]=E(i,t[a],n,o):t[a]=T(i)}return t},_=(e,t)=>e>t?1:e<t?-1:0,q=(e=[],t)=>{const r=[...e],n=t||_;return r.sort(n),r},C=(e=[])=>{const t=[...e],r=[];let n=t.length;for(;n>0;){const e=Math.floor(Math.random()*n);r.push(t.splice(e,1)[0]),n--}return r};e.clone=T,e.compose=(...e)=>e.reduce(((e,t)=>r=>e(t(r)))),e.copies=E,e.curry=e=>{const t=e.length,r=(t,n)=>t>0?(...e)=>r(t-e.length,[...n,...e]):e(...n);return r(t,[])},e.equals=f,e.escapeHTML=e=>d(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),e.genid=(e,t="")=>{const r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),o=[r,n,"0123456789"].join("").split("").sort((()=>Math.random()>.5)).join(""),a=o.length,i=Math.max(e||32,t.length);let s=t;for(;s.length<i;){const e=h(0,a);s+=o.charAt(e)||""}return s},e.hasProperty=g,e.isArray=r,e.isBoolean=e=>Boolean(e)===e,e.isDate=c,e.isElement=e=>null!==t(e).match(/^\[object HTML\w*Element]$/),e.isEmail=e=>n(e)&&/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(e),e.isEmpty=u,e.isFunction=e=>"[object Function]"===t(e),e.isInteger=e=>Number.isInteger(e),e.isLetter=e=>n(e)&&/^[a-z]+$/i.test(e),e.isNil=s,e.isNull=a,e.isNumber=o,e.isObject=l,e.isString=n,e.isUndefined=i,e.maybe=A,e.md5=e=>{for(var t=[],r=0;r<64;)t[r]=0|4294967296*Math.abs(Math.sin(++r));for(var n,o,a,i,s=[],l=decodeURIComponent(encodeURI(e)),c=l.length,u=[n=1732584193,o=-271733879,~n,~o],g=0;g<=c;)s[g>>2]|=(l.charCodeAt(g)||128)<<g++%4*8;for(s[e=16*(c+8>>6)+14]=8*c,g=0;g<e;g+=16){for(c=u,i=0;i<64;)c=[a=c[3],(n=0|c[1])+((a=c[0]+[n&(o=c[2])|~n&a,a&n|~a&o,n^o^a,o^(n|~a)][c=i>>4]+(t[i]+(0|s[[i,5*i+1,3*i+5,7*i][c]%16+g])))<<(c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*c+i++%4])|a>>>32-c),n,o];for(i=4;i;)u[--i]=u[i]+c[i]}for(e="";i<32;)e+=(u[i>>3]>>4*(1^7&i++)&15).toString(16);return e},e.now=j,e.pick=(e=[],t=1)=>{const r=C(e),n=Math.max(1,t),o=Math.min(n,r.length-1);return r.splice(0,o)},e.pipe=(...e)=>e.reduce(((e,t)=>r=>t(e(r)))),e.randint=h,e.replaceAll=b,e.shuffle=C,e.slugify=(e,t="-")=>y(e).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,t),e.sort=q,e.sortBy=(e=[],t=1,r)=>q(e,((e,n)=>e[r]>n[r]?t:e[r]<n[r]?-1*t:0)),e.stripAccent=y,e.stripTags=e=>d(e).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),e.time=D,e.toDateString=I,e.toLocalDateString=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");return I(t,"D, j M Y h:i:s O")},e.toRelativeTime=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");let r=j()-t,n=parseInt(t,10);if(isNaN(n)&&(n=0),r<=n)return"Just now";let o=null;const a={millisecond:1,second:1e3,minute:60,hour:60,day:24,month:30,year:12};for(const e in a){if(r<a[e])break;o=e,r/=a[e]}return r=Math.floor(r),1!==r&&(o+="s"),[r,o].join(" ")+" ago"},e.toUTCDateString=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");const r=t.getMinutes(),n=new Date(t);return n.setMinutes(r+S),`${I(n,"D, j M Y h:i:s")} GMT+0000`},e.truncate=(e,t)=>{const r=d(e),n=t||140;if(r.length<=n)return r;let o=r.substring(0,n);const a=o.split(" ");let i="";return a.length>1?(a.pop(),i+=a.join(" "),i.length<r.length&&(i+="...")):(o=o.substring(0,n-3),i=o+"..."),i},e.ucfirst=m,e.ucwords=e=>d(e).split(" ").map((e=>m(e))).join(" "),e.unescapeHTML=e=>d(e).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),e.unique=(e=[])=>[...new Set(e)],Object.defineProperty(e,"__esModule",{value:!0})})); | ||
// bellajs@10.0.0, by @ndaidong - built on Thu, 02 Dec 2021 13:50:33 GMT - published under MIT license | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bella={})}(this,(function(e){const t=e=>({}.toString.call(e)),r=e=>Array.isArray(e),n=e=>String(e)===e,o=e=>Number(e)===e,a=e=>"[object Null]"===t(e),i=e=>"[object Undefined]"===t(e),l=e=>i(e)||a(e),s=e=>"[object Object]"===t(e)&&!r(e),c=e=>e instanceof Date&&!isNaN(e.valueOf()),u=e=>!e||l(e)||n(e)&&""===e||r(e)&&0===e.length||s(e)&&0===Object.keys(e).length,g=(e,t)=>!(!e||!t)&&Object.prototype.hasOwnProperty.call(e,t),f=(e,t)=>{if(u(e)&&u(t))return!0;if(c(e)&&c(t))return e.getTime()===t.getTime();if(r(e)&&r(t)){if(e.length!==t.length)return!1;let r=!0;for(let n=0;n<e.length;n++)if(!f(e[n],t[n])){r=!1;break}return r}if(s(e)&&s(t)){if(Object.keys(e).length!==Object.keys(t).length)return!1;let r=!0;for(const n in e)if(!g(t,n)||!f(e[n],t[n])){r=!1;break}return r}return e===t},p=Number.MAX_SAFE_INTEGER,h=(e,t)=>{if((!e||e<0)&&(e=0),t||(t=p),e===t)return t;e>t&&(e=Math.min(e,t),t=Math.max(e,t));const r=e,n=t-e+1;return Math.floor(Math.random()*n)+r},d=e=>{const t=o(e)?String(e):e;if(!n(t))throw new Error("InvalidInput: String required.");return t},m=e=>{const t=d(e).toLowerCase();return t.length>1?t.charAt(0).toUpperCase()+t.slice(1):t.toUpperCase()},b=(e,t,a)=>{let i=d(e);if(o(t)&&(t=String(t)),o(a)&&(a=String(a)),n(t)&&n(a)){const e=i.split(t);i=e.join(a)}else if(r(t)&&n(a))t.forEach((e=>{i=b(i,e,a)}));else if(r(t)&&r(a)&&t.length===a.length){const e=t.length;if(e>0)for(let r=0;r<e;r++){const e=t[r],n=a[r];i=b(i,e,n)}}return i},y=e=>{let t=d(e);const r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(e,r)=>{t=b(t,e,r)};for(const e in r)if(g(r,e)){r[e].split("|").forEach((t=>n(t,e)))}return t},w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],M=["January","February","March","April","May","June","July","August","September","October","November","December"],j=()=>new Date,D=()=>Date.now(),S=j().getTimezoneOffset(),N=(()=>{const e=Math.abs(S/60);return["GMT",S<0?"+":"-",String(e).padStart(4,"0")].join("")})(),O=e=>String(e<10?"0"+e:e),A=(e,t="D, M d, Y h:i:s A")=>{const r=c(e)?e:new Date(e);if(!c(r))throw new Error("InvalidInput: Number or Date required.");const n=t.includes("a")||t.includes("A"),o=w,a=M,i={Y:()=>r.getFullYear(),y:()=>(i.Y()+"").slice(-2),F:()=>a[i.n()-1],M:()=>(i.F()+"").slice(0,3),m:()=>O(i.n()),n:()=>r.getMonth()+1,S:()=>(e=>{let t=e+" ";const r=t.charAt(t.length-2);return t="1"===r?"st":"2"===r?"nd":"3"===r?"rd":"th",t})(i.j()),j:()=>r.getDate(),d:()=>O(i.j()),t:()=>new Date(i.Y(),i.n(),0).getDate(),w:()=>r.getDay(),l:()=>o[i.w()],D:()=>(i.l()+"").slice(0,3),G:()=>r.getHours(),g:()=>i.G()%12||12,h:()=>O(n?i.g():i.G()),i:()=>O(r.getMinutes()),s:()=>O(r.getSeconds()),a:()=>i.G()>11?"pm":"am",A:()=>i.a().toUpperCase(),O:()=>N};return t.replace(/\.*\\?([a-z])/gi,((e,t)=>i[e]?i[e]():t))};const I=(e,t,r,n={})=>{const{writable:o=!1,configurable:a=!1,enumerable:i=!1}=n;Object.defineProperty(e,t,{value:r,writable:o,configurable:a,enumerable:i})},v=e=>{const t=e,r=()=>null==t,n=Object.create({});return I(n,"__value__",t,{enumerable:!0}),I(n,"__type__","Maybe",{enumerable:!0}),I(n,"isNil",r),I(n,"value",(()=>t)),I(n,"map",(e=>v(r()?null:e(t)))),I(n,"if",(e=>v(!0===e(t)?t:null))),I(n,"else",(e=>v(t||e()))),n},T=(e,t=null)=>{const n=t||new Set;if(n.has(e))return e;if(n.add(e),c(e))return new Date(e.valueOf());const o=e=>{const t=Object.create({});for(const r in e)g(e,r)&&(t[r]=T(e[r],n));return t},a=e=>[...e].map((e=>r(e)?a(e):s(e)?o(e):T(e,n)));return r(e)?a(e):s(e)?o(e):e},E=(e,t,n=!1,o=[])=>{for(const a in e)if(!(o.length>0&&o.includes(a))&&(!n||n&&g(t,a))){const i=e[a],l=t[a];s(l)&&s(i)||r(l)&&r(i)?t[a]=E(i,t[a],n,o):t[a]=T(i)}return t},_=(e,t)=>e>t?1:e<t?-1:0,q=(e=[],t=null)=>{const r=[...e],n=t||_;return r.sort(n),r},C=(e=[])=>{const t=[...e],r=[];let n=t.length;for(;n>0;){const e=Math.floor(Math.random()*n);r.push(t.splice(e,1)[0]),n--}return r};e.clone=T,e.compose=(...e)=>e.reduce(((e,t)=>r=>e(t(r)))),e.copies=E,e.curry=e=>{const t=e.length,r=(t,n)=>t>0?(...e)=>r(t-e.length,[...n,...e]):e(...n);return r(t,[])},e.equals=f,e.escapeHTML=e=>d(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),e.genid=(e,t="")=>{const r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),o=[r,n,"0123456789"].join("").split("").sort((()=>Math.random()>.5)).join(""),a=o.length,i=Math.max(e||32,t.length);let l=t;for(;l.length<i;){const e=h(0,a);l+=o.charAt(e)||""}return l},e.hasProperty=g,e.isArray=r,e.isBoolean=e=>Boolean(e)===e,e.isDate=c,e.isElement=e=>null!==t(e).match(/^\[object HTML\w*Element]$/),e.isEmail=e=>n(e)&&/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(e),e.isEmpty=u,e.isFunction=e=>"[object Function]"===t(e),e.isInteger=e=>Number.isInteger(e),e.isLetter=e=>n(e)&&/^[a-z]+$/i.test(e),e.isNil=l,e.isNull=a,e.isNumber=o,e.isObject=s,e.isString=n,e.isUndefined=i,e.maybe=v,e.md5=e=>{for(var t=[],r=0;r<64;)t[r]=0|4294967296*Math.abs(Math.sin(++r));for(var n,o,a,i,l=[],s=decodeURIComponent(encodeURI(e)),c=s.length,u=[n=1732584193,o=-271733879,~n,~o],g=0;g<=c;)l[g>>2]|=(s.charCodeAt(g)||128)<<g++%4*8;for(l[e=16*(c+8>>6)+14]=8*c,g=0;g<e;g+=16){for(c=u,i=0;i<64;)c=[a=c[3],(n=0|c[1])+((a=c[0]+[n&(o=c[2])|~n&a,a&n|~a&o,n^o^a,o^(n|~a)][c=i>>4]+(t[i]+(0|l[[i,5*i+1,3*i+5,7*i][c]%16+g])))<<(c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*c+i++%4])|a>>>32-c),n,o];for(i=4;i;)u[--i]=u[i]+c[i]}for(e="";i<32;)e+=(u[i>>3]>>4*(1^7&i++)&15).toString(16);return e},e.now=j,e.pick=(e=[],t=1)=>{const r=C(e),n=Math.max(1,t),o=Math.min(n,r.length-1);return r.splice(0,o)},e.pipe=(...e)=>e.reduce(((e,t)=>r=>t(e(r)))),e.randint=h,e.replaceAll=b,e.shuffle=C,e.slugify=(e,t="-")=>y(e).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,t),e.sort=q,e.sortBy=(e=[],t=1,r="")=>n(r)&&g(e[0],r)?q(e,((e,n)=>e[r]>n[r]?t:e[r]<n[r]?-1*t:0)):e,e.stripAccent=y,e.stripTags=e=>d(e).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),e.time=D,e.toDateString=A,e.toLocalDateString=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");return A(t,"D, j M Y h:i:s O")},e.toRelativeTime=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");let r=j()-t,n=parseInt(t,10);if(isNaN(n)&&(n=0),r<=n)return"Just now";let o=null;const a={millisecond:1,second:1e3,minute:60,hour:60,day:24,month:30,year:12};for(const e in a){if(r<a[e])break;o=e,r/=a[e]}return r=Math.floor(r),1!==r&&(o+="s"),[r,o].join(" ")+" ago"},e.toUTCDateString=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");const r=t.getMinutes(),n=new Date(t);return n.setMinutes(r+S),`${A(n,"D, j M Y h:i:s")} GMT+0000`},e.truncate=(e,t)=>{const r=d(e),n=t||140;if(r.length<=n)return r;let o=r.substring(0,n);const a=o.split(" ");let i="";return a.length>1?(a.pop(),i+=a.join(" "),i.length<r.length&&(i+="...")):(o=o.substring(0,n-3),i=o+"..."),i},e.ucfirst=m,e.ucwords=e=>d(e).split(" ").map((e=>m(e))).join(" "),e.unescapeHTML=e=>d(e).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),e.unique=(e=[])=>[...new Set(e)],Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"version": "10.0.0", | ||
"version": "10.0.1", | ||
"name": "bellajs", | ||
@@ -4,0 +4,0 @@ "description": "A useful helper for any javascript program", |
@@ -139,3 +139,3 @@ BellaJS | ||
``` | ||
t s | ||
Example: | ||
@@ -224,3 +224,2 @@ | ||
Example: | ||
@@ -302,3 +301,3 @@ ```js | ||
Examples: | ||
For example: | ||
@@ -313,3 +312,2 @@ ```js | ||
sort([3, 1, 5, 2], fn) // => [ 1, 2, 3, 5 ] | ||
sort([3, 1, 5, 2], fn) // => [ 5, 3, 2, 1 ] | ||
``` | ||
@@ -323,3 +321,3 @@ | ||
Examples: | ||
For example: | ||
@@ -365,3 +363,3 @@ ```js | ||
Examples: | ||
For example: | ||
@@ -380,3 +378,3 @@ ```js | ||
Examples: | ||
For example: | ||
@@ -603,3 +601,3 @@ ```js | ||
Examples: | ||
For example: | ||
@@ -606,0 +604,0 @@ ```js |
@@ -10,3 +10,3 @@ /** | ||
isDate, | ||
isNil, | ||
isString, | ||
hasProperty | ||
@@ -94,3 +94,3 @@ } from './utils/detection' | ||
export const sortBy = (arr = [], order = 1, key = '') => { | ||
if (isNil(key)) { | ||
if (!isString(key) || !hasProperty(arr[0], key)) { | ||
return arr | ||
@@ -97,0 +97,0 @@ } |
@@ -169,2 +169,8 @@ // main.test | ||
expect(JSON.stringify(sortedArr) === JSON.stringify(sortedByAge)).toBeTruthy() | ||
const sortedByNonStringKey = sortBy(arr, 1, 99) | ||
expect(JSON.stringify(sortedByNonStringKey) === JSON.stringify(arr)).toBeTruthy() | ||
const sortedByNonExistKey = sortBy(arr, 1, 'balance') | ||
expect(JSON.stringify(sortedByNonExistKey) === JSON.stringify(arr)).toBeTruthy() | ||
}) | ||
@@ -171,0 +177,0 @@ }) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
98918
2519
1
615