Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bellajs

Package Overview
Dependencies
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bellajs - npm Package Compare versions

Comparing version 11.0.7 to 11.1.0

src/browser/crypto.js

4

dist/bella.esm.js

@@ -1,2 +0,2 @@

// bellajs@11.0.7 https://github.com/ndaidong/bellajs - built with esbuild at 2022-09-16T08:33:36.382Z
var x=t=>({}).toString.call(t),F=t=>Number.isInteger(t),p=t=>Array.isArray(t),l=t=>String(t)===t,h=t=>Number(t)===t,q=t=>Boolean(t)===t,M=t=>x(t)==="[object Null]",A=t=>x(t)==="[object Undefined]",O=t=>A(t)||M(t),z=t=>x(t)==="[object Function]",a=t=>x(t)==="[object Object]"&&!p(t),y=t=>t instanceof Date&&!isNaN(t.valueOf()),B=t=>x(t).match(/^\[object HTML\w*Element]$/)!==null,H=t=>{let e=/^[a-z]+$/i;return l(t)&&e.test(t)},$=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return l(t)&&e.test(t)},R=t=>!t||O(t)||l(t)&&t===""||p(t)&&t.length===0||a(t)&&Object.keys(t).length===0,g=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var j=(t,e)=>{let r=Number.MAX_SAFE_INTEGER;if((!t||t<0)&&(t=0),e||(e=r),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let o=t,n=e-t+1;return Math.floor(Math.random()*n)+o};var f=t=>{let e=h(t)?String(t):t;if(!l(e))throw new Error("InvalidInput: String required.");return e},X=(t,e=140)=>{let r=f(t);if(r.length<=e)return r;let n=r.substring(0,e).trim(),s=n.split(" ");return s.length>1?(s.pop(),s.map(u=>u.trim()).join(" ")+"..."):n.substring(0,e-3)+"..."},J=t=>f(t).replace(/(<([^>]+)>)/ig,"").trim(),Q=t=>f(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Y=t=>f(t).replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),N=t=>{let e=f(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},Z=t=>f(t).split(" ").map(e=>N(e)).join(" "),b=(t,e,r)=>{let o=f(t),n=h(e)?String(e):e,s=h(r)?String(r):r;if(l(n)&&l(s))o=o.split(n).join(s);else if(p(n)&&l(s))n.forEach(c=>{o=b(o,c,s)});else if(p(n)&&p(s)&&n.length===s.length){let c=n.length;if(c>0)for(let u=0;u<c;u++){let i=n[u],S=s[u];o=b(o,i,S)}}return o},C=()=>{let t={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä|æ",c:"ç",d:"đ|ð",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",i:"í|ì|ỉ|ĩ|ị|ï|î",n:"ñ",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö|ø",s:"ß",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",y:"ý|ỳ|ỷ|ỹ|ỵ|ÿ"},e={...t};return Object.keys(t).forEach(r=>{let o=r.toUpperCase();e[o]=t[r].toUpperCase()}),e},E=t=>{let e=f(t),r=(n,s)=>{e=b(e,n,s)},o=C();for(let n in o)g(o,n)&&o[n].split("|").forEach(c=>r(c,n));return e},_=()=>{let t="abcdefghijklmnopqrstuvwxyz",e=t.toUpperCase(),r="0123456789";return t.concat(e).concat(r).split("")},v=(t=32,e="")=>{let r=_().sort(()=>Math.random()>.5).join(""),o=r.length,n=Math.max(t,e.length),s=e;for(;s.length<n;){let c=j(0,o);s+=r.charAt(c)||""}return s},tt=(t,e="-")=>E(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var L=()=>({dateStyle:"medium",timeStyle:"long"}),D=()=>({second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12}),T=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},nt=(...t)=>{let e=t[0],r=T(t[1])?t[1]:"en",o=L(),n=t.length>=3?t[2]:t.length===1?o:a(t[1])?t[1]:o;return new Intl.DateTimeFormat(r,n).format(new Date(e))},ot=(t,e="en",r="just now")=>{let o=new Date(t),n=Date.now()-o,s=D();if(n<=s.second)return r;let c="second";for(let i in s){if(n<s[i])break;c=i,n/=s[i]}return n=Math.floor(n),new Intl.RelativeTimeFormat(e).format(-n,c)};var ct=t=>{let e=t.length,r=(o,n)=>o>0?(...s)=>r(o-s.length,[...n,...s]):t(...n);return r(e,[])};var it=(...t)=>t.reduce((e,r)=>o=>e(r(o)));var lt=(...t)=>t.reduce((e,r)=>o=>r(e(o)));var m=(t,e,r,o={})=>{let{writable:n=!1,configurable:s=!1,enumerable:c=!1}=o;Object.defineProperty(t,e,{value:r,writable:n,configurable:s,enumerable:c})};var d=t=>{let e=t,r=()=>e==null,o=()=>e,n=i=>d(e||i()),s=i=>d(i(e)===!0?e:null),c=i=>d(r()?null:i(e)),u=Object.create({});return m(u,"__value__",e,{enumerable:!0}),m(u,"__type__","Maybe",{enumerable:!0}),m(u,"isNil",r),m(u,"value",o),m(u,"map",c),m(u,"if",s),m(u,"else",n),u};var w=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),y(t))return new Date(t.valueOf());let o=s=>{let c=Object.create({});for(let u in s)g(s,u)&&(c[u]=w(s[u],r));return c},n=s=>[...s].map(c=>p(c)?n(c):a(c)?o(c):w(c,r));return p(t)?n(t):a(t)?o(t):t},I=(t,e,r=!1,o=[])=>{for(let n in t)if(!(o.length>0&&o.includes(n))&&(!r||r&&g(e,n))){let s=t[n],c=e[n];a(c)&&a(s)||p(c)&&p(s)?e[n]=I(s,e[n],r,o):e[n]=w(s)}return e},ht=(t=[])=>[...new Set(t)],P=(t,e)=>t>e?1:t<e?-1:0,U=(t=[],e=null)=>{let r=[...t],o=e||P;return r.sort(o),r},bt=(t=[],e=1,r="")=>!l(r)||!g(t[0],r)?t:U(t,(o,n)=>o[r]>n[r]?e:o[r]<n[r]?-1*e:0),k=(t=[])=>{let e=[...t],r=[],o=e.length;for(;o>0;){let n=Math.floor(Math.random()*o);r.push(e.splice(n,1)[0]),o--}return r},dt=(t=[],e=1)=>{let r=k(t),o=Math.max(1,e),n=Math.min(o,r.length-1);return r.splice(0,n)};export{w as clone,it as compose,I as copies,ct as curry,Q as escapeHTML,nt as formatDateString,ot as formatTimeAgo,v as genid,g as hasProperty,p as isArray,q as isBoolean,y as isDate,B as isElement,$ as isEmail,R as isEmpty,z as isFunction,F as isInteger,H as isLetter,O as isNil,M as isNull,h as isNumber,a as isObject,l as isString,A as isUndefined,d as maybe,dt as pick,lt as pipe,j as randint,b as replaceAll,k as shuffle,tt as slugify,U as sort,bt as sortBy,E as stripAccent,J as stripTags,X as truncate,N as ucfirst,Z as ucwords,Y as unescapeHTML,ht as unique};
// bellajs@11.1.0 https://github.com/ndaidong/bellajs - built with esbuild at 2022-10-12T09:56:19.003Z
var g=t=>({}).toString.call(t),z=t=>Number.isInteger(t),p=t=>Array.isArray(t),a=t=>String(t)===t,h=t=>Number(t)===t,B=t=>Boolean(t)===t,E=t=>g(t)==="[object Null]",D=t=>g(t)==="[object Undefined]",N=t=>D(t)||E(t),R=t=>g(t)==="[object Function]",l=t=>g(t)==="[object Object]"&&!p(t),A=t=>t instanceof Date&&!isNaN(t.valueOf()),V=t=>g(t).match(/^\[object HTML\w*Element]$/)!==null,G=t=>{let e=/^[a-z]+$/i;return a(t)&&e.test(t)},K=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return a(t)&&e.test(t)},W=t=>!t||N(t)||a(t)&&t===""||p(t)&&t.length===0||l(t)&&Object.keys(t).length===0,x=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var f=t=>{let e=h(t)?String(t):t;if(!a(e))throw new Error("InvalidInput: String required.");return e},X=(t,e=140)=>{let r=f(t);if(r.length<=e)return r;let n=r.substring(0,e).trim(),s=n.split(" ");return s.length>1?(s.pop(),s.map(i=>i.trim()).join(" ")+"..."):n.substring(0,e-3)+"..."},Y=t=>f(t).replace(/(<([^>]+)>)/ig,"").trim(),Z=t=>f(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),v=t=>f(t).replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),U=t=>{let e=f(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},tt=t=>f(t).split(" ").map(e=>U(e)).join(" "),y=(t,e,r)=>{let o=f(t),n=h(e)?String(e):e,s=h(r)?String(r):r;if(a(n)&&a(s))o=o.split(n).join(s);else if(p(n)&&a(s))n.forEach(c=>{o=y(o,c,s)});else if(p(n)&&p(s)&&n.length===s.length){let c=n.length;if(c>0)for(let i=0;i<c;i++){let u=n[i],T=s[i];o=y(o,u,T)}}return o},C=()=>{let t={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä|æ",c:"ç",d:"đ|ð",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",i:"í|ì|ỉ|ĩ|ị|ï|î",n:"ñ",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö|ø",s:"ß",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",y:"ý|ỳ|ỷ|ỹ|ỵ|ÿ"},e={...t};return Object.keys(t).forEach(r=>{let o=r.toUpperCase();e[o]=t[r].toUpperCase()}),e},L=t=>{let e=f(t),r=(n,s)=>{e=y(e,n,s)},o=C();for(let n in o)x(o,n)&&o[n].split("|").forEach(c=>r(c,n));return e},et=(t,e="-")=>L(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var b=crypto;var w=window.TextEncoder,ot=window.TextDecoder;var d=b.webcrypto?b.webcrypto:b,it=(t=0,e=1e6)=>{let r=new Uint8Array(1);d.getRandomValues(r);let o="0."+r[0].toString();return Math.floor(o*(e-t+1))+t},_=(t=32,e="")=>{let r=e;for(let o=0;o<t;o++){let n=Math.random(),s=Math.floor(n*36),c=s.toString(36);r+=s>9&&n>.3&&n<.7?c.toUpperCase():c}return r.substring(0,t)},M=(t=32,e="")=>{let r=e,o=d.getRandomValues(new Uint16Array(t));for(let n=0;n<o.length;n++){let s=o[n].toString(36),c=Math.random(),i=s.charAt(Math.floor(c*s.length));r+=c>.3&&c<.7?i.toUpperCase():i}return r.substring(0,t)},ut=(t=32,e="")=>t<=128?M(t,e):`${M(99,e)}${_(t-99)}`;var O=async(t,e)=>{let r=new w().encode(t),o=await d.subtle.digest(e,r);return[...new Uint8Array(o)].map(s=>s.toString(16).padStart(2,"0")).join("")},ft=async(t="")=>await O(t,"SHA-256"),mt=async(t="")=>await O(t,"SHA-512");var I=()=>({dateStyle:"medium",timeStyle:"long"}),P=()=>({second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12}),k=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},ht=(...t)=>{let e=t[0],r=k(t[1])?t[1]:"en",o=I(),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))},bt=(t,e="en",r="just now")=>{let o=new Date(t),n=Date.now()-o,s=P();if(n<=s.second)return r;let c="second";for(let u in s){if(n<s[u])break;c=u,n/=s[u]}return n=Math.floor(n),new Intl.RelativeTimeFormat(e).format(-n,c)};var yt=t=>{let e=t.length,r=(o,n)=>o>0?(...s)=>r(o-s.length,[...n,...s]):t(...n);return r(e,[])};var St=(...t)=>t.reduce((e,r)=>o=>e(r(o)));var At=(...t)=>t.reduce((e,r)=>o=>r(e(o)));var m=(t,e,r,o={})=>{let{writable:n=!1,configurable:s=!1,enumerable:c=!1}=o;Object.defineProperty(t,e,{value:r,writable:n,configurable:s,enumerable:c})};var S=t=>{let e=t,r=()=>e==null,o=()=>e,n=u=>S(e||u()),s=u=>S(u(e)===!0?e:null),c=u=>S(r()?null:u(e)),i=Object.create({});return m(i,"__value__",e,{enumerable:!0}),m(i,"__type__","Maybe",{enumerable:!0}),m(i,"isNil",r),m(i,"value",o),m(i,"map",c),m(i,"if",s),m(i,"else",n),i};var j=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),A(t))return new Date(t.valueOf());let o=s=>{let c=Object.create({});for(let i in s)x(s,i)&&(c[i]=j(s[i],r));return c},n=s=>[...s].map(c=>p(c)?n(c):l(c)?o(c):j(c,r));return p(t)?n(t):l(t)?o(t):t},F=(t,e,r=!1,o=[])=>{for(let n in t)if(!(o.length>0&&o.includes(n))&&(!r||r&&x(e,n))){let s=t[n],c=e[n];l(c)&&l(s)||p(c)&&p(s)?e[n]=F(s,e[n],r,o):e[n]=j(s)}return e},Nt=(t=[])=>[...new Set(t)],H=(t,e)=>t>e?1:t<e?-1:0,$=(t=[],e=null)=>{let r=[...t],o=e||H;return r.sort(o),r},Ut=(t=[],e=1,r="")=>!a(r)||!x(t[0],r)?t:$(t,(o,n)=>o[r]>n[r]?e:o[r]<n[r]?-1*e:0),q=(t=[])=>{let e=[...t],r=[],o=e.length;for(;o>0;){let n=Math.floor(Math.random()*o);r.push(e.splice(n,1)[0]),o--}return r},Ct=(t=[],e=1)=>{let r=q(t),o=Math.max(1,e),n=Math.min(o,r.length-1);return r.splice(0,n)};export{w as TextEncoder,j as clone,St as compose,F as copies,d as crypto,yt as curry,Z as escapeHTML,ht as formatDateString,bt as formatTimeAgo,ut as genid,x as hasProperty,p as isArray,B as isBoolean,A as isDate,V as isElement,K as isEmail,W as isEmpty,R as isFunction,z as isInteger,G as isLetter,N as isNil,E as isNull,h as isNumber,l as isObject,a as isString,D as isUndefined,S as maybe,Ct as pick,At as pipe,it as randint,y as replaceAll,ft as sha256,mt as sha512,q as shuffle,et as slugify,$ as sort,Ut as sortBy,L as stripAccent,Y as stripTags,X as truncate,U as ucfirst,tt as ucwords,v as unescapeHTML,Nt as unique};

@@ -1,2 +0,2 @@

// bellajs@11.0.7 https://github.com/ndaidong/bellajs - built with esbuild at 2022-09-16T08:33:36.382Z
var y=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var U=(t,e)=>{for(var r in e)y(t,r,{get:e[r],enumerable:!0})},k=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of I(e))!P.call(t,n)&&n!==r&&y(t,n,{get:()=>e[n],enumerable:!(o=T(e,n))||o.enumerable});return t};var F=t=>k(y({},"__esModule",{value:!0}),t);var ft={};U(ft,{clone:()=>w,compose:()=>ct,copies:()=>E,curry:()=>st,escapeHTML:()=>W,formatDateString:()=>nt,formatTimeAgo:()=>ot,genid:()=>Z,hasProperty:()=>g,isArray:()=>i,isBoolean:()=>z,isDate:()=>j,isElement:()=>H,isEmail:()=>R,isEmpty:()=>G,isFunction:()=>B,isInteger:()=>q,isLetter:()=>$,isNil:()=>O,isNull:()=>M,isNumber:()=>h,isObject:()=>a,isString:()=>l,isUndefined:()=>A,maybe:()=>d,pick:()=>at,pipe:()=>ut,randint:()=>S,replaceAll:()=>b,shuffle:()=>L,slugify:()=>v,sort:()=>_,sortBy:()=>lt,stripAccent:()=>C,stripTags:()=>V,truncate:()=>K,ucfirst:()=>N,ucwords:()=>J,unescapeHTML:()=>X,unique:()=>it});module.exports=F(ft);var x=t=>({}).toString.call(t),q=t=>Number.isInteger(t),i=t=>Array.isArray(t),l=t=>String(t)===t,h=t=>Number(t)===t,z=t=>Boolean(t)===t,M=t=>x(t)==="[object Null]",A=t=>x(t)==="[object Undefined]",O=t=>A(t)||M(t),B=t=>x(t)==="[object Function]",a=t=>x(t)==="[object Object]"&&!i(t),j=t=>t instanceof Date&&!isNaN(t.valueOf()),H=t=>x(t).match(/^\[object HTML\w*Element]$/)!==null,$=t=>{let e=/^[a-z]+$/i;return l(t)&&e.test(t)},R=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return l(t)&&e.test(t)},G=t=>!t||O(t)||l(t)&&t===""||i(t)&&t.length===0||a(t)&&Object.keys(t).length===0,g=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var S=(t,e)=>{let r=Number.MAX_SAFE_INTEGER;if((!t||t<0)&&(t=0),e||(e=r),t===e)return e;t>e&&(t=Math.min(t,e),e=Math.max(t,e));let o=t,n=e-t+1;return Math.floor(Math.random()*n)+o};var f=t=>{let e=h(t)?String(t):t;if(!l(e))throw new Error("InvalidInput: String required.");return e},K=(t,e=140)=>{let r=f(t);if(r.length<=e)return r;let n=r.substring(0,e).trim(),s=n.split(" ");return s.length>1?(s.pop(),s.map(u=>u.trim()).join(" ")+"..."):n.substring(0,e-3)+"..."},V=t=>f(t).replace(/(<([^>]+)>)/ig,"").trim(),W=t=>f(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),X=t=>f(t).replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),N=t=>{let e=f(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},J=t=>f(t).split(" ").map(e=>N(e)).join(" "),b=(t,e,r)=>{let o=f(t),n=h(e)?String(e):e,s=h(r)?String(r):r;if(l(n)&&l(s))o=o.split(n).join(s);else if(i(n)&&l(s))n.forEach(c=>{o=b(o,c,s)});else if(i(n)&&i(s)&&n.length===s.length){let c=n.length;if(c>0)for(let u=0;u<c;u++){let p=n[u],D=s[u];o=b(o,p,D)}}return o},Q=()=>{let t={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä|æ",c:"ç",d:"đ|ð",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",i:"í|ì|ỉ|ĩ|ị|ï|î",n:"ñ",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö|ø",s:"ß",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",y:"ý|ỳ|ỷ|ỹ|ỵ|ÿ"},e={...t};return Object.keys(t).forEach(r=>{let o=r.toUpperCase();e[o]=t[r].toUpperCase()}),e},C=t=>{let e=f(t),r=(n,s)=>{e=b(e,n,s)},o=Q();for(let n in o)g(o,n)&&o[n].split("|").forEach(c=>r(c,n));return e},Y=()=>{let t="abcdefghijklmnopqrstuvwxyz",e=t.toUpperCase(),r="0123456789";return t.concat(e).concat(r).split("")},Z=(t=32,e="")=>{let r=Y().sort(()=>Math.random()>.5).join(""),o=r.length,n=Math.max(t,e.length),s=e;for(;s.length<n;){let c=S(0,o);s+=r.charAt(c)||""}return s},v=(t,e="-")=>C(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var tt=()=>({dateStyle:"medium",timeStyle:"long"}),et=()=>({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",o=tt(),n=t.length>=3?t[2]:t.length===1?o:a(t[1])?t[1]:o;return new Intl.DateTimeFormat(r,n).format(new Date(e))},ot=(t,e="en",r="just now")=>{let o=new Date(t),n=Date.now()-o,s=et();if(n<=s.second)return r;let c="second";for(let p in s){if(n<s[p])break;c=p,n/=s[p]}return n=Math.floor(n),new Intl.RelativeTimeFormat(e).format(-n,c)};var st=t=>{let e=t.length,r=(o,n)=>o>0?(...s)=>r(o-s.length,[...n,...s]):t(...n);return r(e,[])};var ct=(...t)=>t.reduce((e,r)=>o=>e(r(o)));var ut=(...t)=>t.reduce((e,r)=>o=>r(e(o)));var m=(t,e,r,o={})=>{let{writable:n=!1,configurable:s=!1,enumerable:c=!1}=o;Object.defineProperty(t,e,{value:r,writable:n,configurable:s,enumerable:c})};var d=t=>{let e=t,r=()=>e==null,o=()=>e,n=p=>d(e||p()),s=p=>d(p(e)===!0?e:null),c=p=>d(r()?null:p(e)),u=Object.create({});return m(u,"__value__",e,{enumerable:!0}),m(u,"__type__","Maybe",{enumerable:!0}),m(u,"isNil",r),m(u,"value",o),m(u,"map",c),m(u,"if",s),m(u,"else",n),u};var w=(t,e=null)=>{let r=e||new Set;if(r.has(t))return t;if(r.add(t),j(t))return new Date(t.valueOf());let o=s=>{let c=Object.create({});for(let u in s)g(s,u)&&(c[u]=w(s[u],r));return c},n=s=>[...s].map(c=>i(c)?n(c):a(c)?o(c):w(c,r));return i(t)?n(t):a(t)?o(t):t},E=(t,e,r=!1,o=[])=>{for(let n in t)if(!(o.length>0&&o.includes(n))&&(!r||r&&g(e,n))){let s=t[n],c=e[n];a(c)&&a(s)||i(c)&&i(s)?e[n]=E(s,e[n],r,o):e[n]=w(s)}return e},it=(t=[])=>[...new Set(t)],pt=(t,e)=>t>e?1:t<e?-1:0,_=(t=[],e=null)=>{let r=[...t],o=e||pt;return r.sort(o),r},lt=(t=[],e=1,r="")=>!l(r)||!g(t[0],r)?t:_(t,(o,n)=>o[r]>n[r]?e:o[r]<n[r]?-1*e:0),L=(t=[])=>{let e=[...t],r=[],o=e.length;for(;o>0;){let n=Math.floor(Math.random()*o);r.push(e.splice(n,1)[0]),o--}return r},at=(t=[],e=1)=>{let r=L(t),o=Math.max(1,e),n=Math.min(o,r.length-1);return r.splice(0,n)};0&&(module.exports={clone,compose,copies,curry,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.1.0 https://github.com/ndaidong/bellajs - built with esbuild at 2022-10-12T09:56:19.003Z
var F=Object.create;var y=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var B=(t,e)=>{for(var r in e)y(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of $(e))!z.call(t,n)&&n!==r&&y(t,n,{get:()=>e[n],enumerable:!(o=H(e,n))||o.enumerable});return t};var R=(t,e,r)=>(r=t!=null?F(q(t)):{},O(e||!t||!t.__esModule?y(r,"default",{value:t,enumerable:!0}):r,t)),V=t=>O(y({},"__esModule",{value:!0}),t);var jt={};B(jt,{TextEncoder:()=>S.TextEncoder,clone:()=>A,compose:()=>ht,copies:()=>_,crypto:()=>b,curry:()=>gt,escapeHTML:()=>tt,formatDateString:()=>mt,formatTimeAgo:()=>xt,genid:()=>it,hasProperty:()=>x,isArray:()=>u,isBoolean:()=>K,isDate:()=>M,isElement:()=>J,isEmail:()=>X,isEmpty:()=>Y,isFunction:()=>W,isInteger:()=>G,isLetter:()=>Q,isNil:()=>U,isNull:()=>N,isNumber:()=>h,isObject:()=>l,isString:()=>a,isUndefined:()=>E,maybe:()=>j,pick:()=>St,pipe:()=>bt,randint:()=>st,replaceAll:()=>d,sha256:()=>ut,sha512:()=>pt,shuffle:()=>P,slugify:()=>ot,sort:()=>I,sortBy:()=>wt,stripAccent:()=>D,stripTags:()=>v,truncate:()=>Z,ucfirst:()=>C,ucwords:()=>rt,unescapeHTML:()=>et,unique:()=>yt});module.exports=V(jt);var g=t=>({}).toString.call(t),G=t=>Number.isInteger(t),u=t=>Array.isArray(t),a=t=>String(t)===t,h=t=>Number(t)===t,K=t=>Boolean(t)===t,N=t=>g(t)==="[object Null]",E=t=>g(t)==="[object Undefined]",U=t=>E(t)||N(t),W=t=>g(t)==="[object Function]",l=t=>g(t)==="[object Object]"&&!u(t),M=t=>t instanceof Date&&!isNaN(t.valueOf()),J=t=>g(t).match(/^\[object HTML\w*Element]$/)!==null,Q=t=>{let e=/^[a-z]+$/i;return a(t)&&e.test(t)},X=t=>{let e=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return a(t)&&e.test(t)},Y=t=>!t||U(t)||a(t)&&t===""||u(t)&&t.length===0||l(t)&&Object.keys(t).length===0,x=(t,e)=>!t||!e?!1:Object.prototype.hasOwnProperty.call(t,e);var f=t=>{let e=h(t)?String(t):t;if(!a(e))throw new Error("InvalidInput: String required.");return e},Z=(t,e=140)=>{let r=f(t);if(r.length<=e)return r;let n=r.substring(0,e).trim(),s=n.split(" ");return s.length>1?(s.pop(),s.map(i=>i.trim()).join(" ")+"..."):n.substring(0,e-3)+"..."},v=t=>f(t).replace(/(<([^>]+)>)/ig,"").trim(),tt=t=>f(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),et=t=>f(t).replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),C=t=>{let e=f(t).toLowerCase();return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e.toUpperCase()},rt=t=>f(t).split(" ").map(e=>C(e)).join(" "),d=(t,e,r)=>{let o=f(t),n=h(e)?String(e):e,s=h(r)?String(r):r;if(a(n)&&a(s))o=o.split(n).join(s);else if(u(n)&&a(s))n.forEach(c=>{o=d(o,c,s)});else if(u(n)&&u(s)&&n.length===s.length){let c=n.length;if(c>0)for(let i=0;i<c;i++){let p=n[i],k=s[i];o=d(o,p,k)}}return o},nt=()=>{let t={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä|æ",c:"ç",d:"đ|ð",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",i:"í|ì|ỉ|ĩ|ị|ï|î",n:"ñ",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö|ø",s:"ß",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",y:"ý|ỳ|ỷ|ỹ|ỵ|ÿ"},e={...t};return Object.keys(t).forEach(r=>{let o=r.toUpperCase();e[o]=t[r].toUpperCase()}),e},D=t=>{let e=f(t),r=(n,s)=>{e=d(e,n,s)},o=nt();for(let n in o)x(o,n)&&o[n].split("|").forEach(c=>r(c,n));return e},ot=(t,e="-")=>D(t).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,e);var w=R(require("crypto"),1),S=require("util"),b=w.default.webcrypto?w.default.webcrypto:w.default,st=(t=0,e=1e6)=>{let r=new Uint8Array(1);b.getRandomValues(r);let o="0."+r[0].toString();return Math.floor(o*(e-t+1))+t},ct=(t=32,e="")=>{let r=e;for(let o=0;o<t;o++){let n=Math.random(),s=Math.floor(n*36),c=s.toString(36);r+=s>9&&n>.3&&n<.7?c.toUpperCase():c}return r.substring(0,t)},L=(t=32,e="")=>{let r=e,o=b.getRandomValues(new Uint16Array(t));for(let n=0;n<o.length;n++){let s=o[n].toString(36),c=Math.random(),i=s.charAt(Math.floor(c*s.length));r+=c>.3&&c<.7?i.toUpperCase():i}return r.substring(0,t)},it=(t=32,e="")=>t<=128?L(t,e):`${L(99,e)}${ct(t-99)}`;var T=async(t,e)=>{let r=new S.TextEncoder().encode(t),o=await b.subtle.digest(e,r);return[...new Uint8Array(o)].map(s=>s.toString(16).padStart(2,"0")).join("")},ut=async(t="")=>await T(t,"SHA-256"),pt=async(t="")=>await T(t,"SHA-512");var at=()=>({dateStyle:"medium",timeStyle:"long"}),lt=()=>({second:1e3,minute:60,hour:60,day:24,week:7,month:4,year:12}),ft=t=>{try{return new Intl.Locale(t).language!==""}catch{return!1}},mt=(...t)=>{let e=t[0],r=ft(t[1])?t[1]:"en",o=at(),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))},xt=(t,e="en",r="just now")=>{let o=new Date(t),n=Date.now()-o,s=lt();if(n<=s.second)return r;let c="second";for(let p in s){if(n<s[p])break;c=p,n/=s[p]}return n=Math.floor(n),new Intl.RelativeTimeFormat(e).format(-n,c)};var gt=t=>{let e=t.length,r=(o,n)=>o>0?(...s)=>r(o-s.length,[...n,...s]):t(...n);return r(e,[])};var ht=(...t)=>t.reduce((e,r)=>o=>e(r(o)));var bt=(...t)=>t.reduce((e,r)=>o=>r(e(o)));var m=(t,e,r,o={})=>{let{writable:n=!1,configurable:s=!1,enumerable:c=!1}=o;Object.defineProperty(t,e,{value:r,writable:n,configurable:s,enumerable:c})};var j=t=>{let e=t,r=()=>e==null,o=()=>e,n=p=>j(e||p()),s=p=>j(p(e)===!0?e:null),c=p=>j(r()?null:p(e)),i=Object.create({});return m(i,"__value__",e,{enumerable:!0}),m(i,"__type__","Maybe",{enumerable:!0}),m(i,"isNil",r),m(i,"value",o),m(i,"map",c),m(i,"if",s),m(i,"else",n),i};var A=(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 o=s=>{let c=Object.create({});for(let i in s)x(s,i)&&(c[i]=A(s[i],r));return c},n=s=>[...s].map(c=>u(c)?n(c):l(c)?o(c):A(c,r));return u(t)?n(t):l(t)?o(t):t},_=(t,e,r=!1,o=[])=>{for(let n in t)if(!(o.length>0&&o.includes(n))&&(!r||r&&x(e,n))){let s=t[n],c=e[n];l(c)&&l(s)||u(c)&&u(s)?e[n]=_(s,e[n],r,o):e[n]=A(s)}return e},yt=(t=[])=>[...new Set(t)],dt=(t,e)=>t>e?1:t<e?-1:0,I=(t=[],e=null)=>{let r=[...t],o=e||dt;return r.sort(o),r},wt=(t=[],e=1,r="")=>!a(r)||!x(t[0],r)?t:I(t,(o,n)=>o[r]>n[r]?e:o[r]<n[r]?-1*e:0),P=(t=[])=>{let e=[...t],r=[],o=e.length;for(;o>0;){let n=Math.floor(Math.random()*o);r.push(e.splice(n,1)[0]),o--}return r},St=(t=[],e=1)=>{let r=P(t),o=Math.max(1,e),n=Math.min(o,r.length-1);return r.splice(0,n)};0&&(module.exports={TextEncoder,clone,compose,copies,crypto,curry,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,sha256,sha512,shuffle,slugify,sort,sortBy,stripAccent,stripTags,truncate,ucfirst,ucwords,unescapeHTML,unique});
{
"version": "11.0.7",
"version": "11.1.0",
"name": "bellajs",

@@ -16,8 +16,16 @@ "description": "A useful helper for any javascript program",

},
"imports": {
"node:crypto": "./src/browser/crypto.js"
},
"browser": {
"node:crypto": "./src/browser/crypto.js",
"node:util": "./src/browser/txtutil.js"
},
"type": "module",
"engines": {
"node": ">= 14"
"node": ">= 15"
},
"scripts": {
"lint": "standard .",
"lint:fix": "standard --fix",
"pretest": "npm run lint",

@@ -29,5 +37,6 @@ "test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true --env=jsdom",

"devDependencies": {
"esbuild": "^0.15.7",
"jest": "^29.0.3",
"jest-environment-jsdom": "^29.0.3"
"esbuild": "^0.15.10",
"jest": "^29.1.2",
"jest-environment-jsdom": "^29.1.2",
"standard": "^17.0.0"
},

@@ -34,0 +43,0 @@ "standard": {

@@ -24,3 +24,4 @@ BellaJS

* [Date utils](#date-utils): [`formatDateString`](#formatdatestringdate--timestamp--string-locale--object-options), [`formatTimeAgo`](#formattimeagodate--timestamp--string-locale--string-justnow)
* [Other utils](#other-utils): [`randint`](#randintnumber-min--number-max), [`genid`](#genidnumber-length--string-prefix)
* [Crypto utils](#crypto-utils): [`sha256`](#sha256), [`sha512`](#sha512)
* [Random utils](#random-utils): [`randint`](#randintnumber-min--number-max), [`genid`](#genidnumber-length--string-prefix)

@@ -31,5 +32,5 @@ * [Test](#test)

## Install
## Install & Usage
- Node.js
### Node.js

@@ -46,25 +47,18 @@ ```bash

- Browser
### Deno
```html
<script type="module">
import { genid } from 'https://unpkg.com/bellajs/dist/bella.esm.js'
```ts
import { genid } from 'https://esm.sh/bellajs'
console.log(genid())
</script>
```
### Browser
## Usage
```html
<script type="module">
import { genid, slugify } from 'https://unpkg.com/bellajs/dist/bella.esm.js'
```js
import {
genid,
slugify
} from 'bella'
const postId = genid(32)
console.log(postId)
const slug = slugify('Goldman Sachs, JPMorgan Predict Euro-Area Recession')
console.log(slug)
console.log(genid())
</script>
```

@@ -501,4 +495,26 @@

### Other utils
### Crypto utils
#### `sha256()`
Generate signature for a text using SHA-256 Cryptographic Hash Algorithm.
```js
import { sha256 } from 'bellajs'
sha256(text) // => hashed string 64 hex characters, 256-bit (16-byte)
```
#### `sha512()`
Generate signature for a text using SHA-512 Cryptographic Hash Algorithm.
```js
import { sha512 } from 'bellajs'
sha512(text) // => hashed string 128 hex characters, 512-bit (32-byte)
```
### Random utils
#### `randint([Number min [, Number max]])`

@@ -528,2 +544,4 @@

When `length` > 128, only first 99 characters are being generated using `crypto.getRandomValues()`, the rest will be calculated with `Math.random()`.
## Test

@@ -530,0 +548,0 @@

@@ -123,2 +123,3 @@ /**

export * from './utils/random.js'
export * from './utils/crypto.js'
export * from './utils/date.js'

@@ -125,0 +126,0 @@

// utils / random
import ncrypto from 'node:crypto'
export { TextEncoder } from 'node:util'
export const randint = (min, max) => {
const maxint = Number.MAX_SAFE_INTEGER
if (!min || min < 0) {
min = 0
export const crypto = ncrypto.webcrypto ? ncrypto.webcrypto : ncrypto
export const randint = (min = 0, max = 1e6) => {
const byteArray = new Uint8Array(1)
crypto.getRandomValues(byteArray)
const floatNum = '0.' + byteArray[0].toString()
return Math.floor(floatNum * (max - min + 1)) + min
}
const mathGen = (len = 32, prefix = '') => {
let s = prefix
for (let i = 0; i < len; i++) {
const r = Math.random()
const k = Math.floor(r * 36)
const c = k.toString(36)
s += (k > 9 && r > 0.3 && r < 0.7) ? c.toUpperCase() : c
}
if (!max) {
max = maxint
return s.substring(0, len)
}
const cryptoGen = (len = 32, prefix = '') => {
let s = prefix
const nums = crypto.getRandomValues(new Uint16Array(len))
for (let i = 0; i < nums.length; i++) {
const n = nums[i].toString(36)
const r = Math.random()
const c = n.charAt(Math.floor(r * n.length))
s += (r > 0.3 && r < 0.7) ? c.toUpperCase() : c
}
if (min === max) {
return max
}
if (min > max) {
min = Math.min(min, max)
max = Math.max(min, max)
}
const offset = min
const range = max - min + 1
return Math.floor(Math.random() * range) + offset
return s.substring(0, len)
}
export const genid = (len = 32, prefix = '') => {
return len <= 128 ? cryptoGen(len, prefix) : `${cryptoGen(99, prefix)}${mathGen(len - 99)}`
}

@@ -5,3 +5,3 @@ // random.test

import { randint } from './random.js'
import { randint, genid } from './random.js'

@@ -33,12 +33,25 @@ describe('test .randint() method:', () => {

})
})
const min2 = 100
const max2 = 30
test(`test .randint() between ${min2} - ${max2}`, () => {
for (let i = 0; i < 100; i++) {
const q = randint(min2, max2)
expect(q).toBeGreaterThanOrEqual(max2)
expect(q).toBeLessThanOrEqual(min2)
}
describe('test .genid() method:', () => {
test('check .genid() default param', () => {
const actual = genid()
expect(actual).toHaveLength(32)
})
test('check .genid(512)', () => {
const actual = genid(512)
expect(actual).toHaveLength(512)
})
const len = 100
const ids = []
while (ids.length < len) {
ids.push(genid())
}
const uniques = Array.from(new Set(ids))
test('check .genid() always return unique string', () => {
expect(ids).toHaveLength(len)
expect(uniques).toHaveLength(ids.length)
})
})

@@ -10,4 +10,2 @@ // utils / string

import { randint } from './random.js'
const toString = (input) => {

@@ -137,23 +135,2 @@ const s = isNumber(input) ? String(input) : input

const getCharList = () => {
const lowerChars = 'abcdefghijklmnopqrstuvwxyz'
const upperChars = lowerChars.toUpperCase()
const digits = '0123456789'
return lowerChars.concat(upperChars).concat(digits).split('')
}
export const genid = (len = 32, prefix = '') => {
const chars = getCharList().sort(() => {
return Math.random() > 0.5
}).join('')
const t = chars.length
const ln = Math.max(len, prefix.length)
let s = prefix
while (s.length < ln) {
const k = randint(0, t)
s += chars.charAt(k) || ''
}
return s
}
export const slugify = (s, delimiter = '-') => {

@@ -160,0 +137,0 @@ return stripAccent(s)

@@ -14,4 +14,3 @@ // string.test

stripAccent,
slugify,
genid
slugify
} from './string.js'

@@ -257,24 +256,1 @@

})
describe('test .genid() method:', () => {
test(' check .genid() default param', () => {
const actual = genid()
expect(actual).toHaveLength(32)
})
test(' check .genid(80)', () => {
const actual = genid(80)
expect(actual).toHaveLength(80)
})
const len = 100
const ids = []
while (ids.length < len) {
ids.push(genid())
}
const uniques = Array.from(new Set(ids))
test(' check .genid() always return unique string', () => {
expect(ids).toHaveLength(len)
expect(uniques).toHaveLength(ids.length)
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc