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 7.5.0 to 8.0.0-rc1

test/specs/utils/genid.js

5

.eslintrc.json
{
"extends": "eslint-config-goes"
"extends": "eslint-config-goes",
"rules": {
"no-prototype-builtins": 0
}
}

341

dist/bella.js
/**
* bellajs@7.5.0
* built on: Mon, 17 Sep 2018 08:14:14 GMT
* bellajs@8.0.0rc1
* built on: Thu, 12 Sep 2019 23:48:47 GMT
* repository: https://github.com/ndaidong/bellajs

@@ -11,4 +11,4 @@ * maintainer: @ndaidong

typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.bella = {})));
}(this, (function (exports) { 'use strict';
(global = global || self, factory(global.bella = {}));
}(this, function (exports) {
const ob2Str = (val) => {

@@ -51,7 +51,7 @@ return {}.toString.call(val);

const isLetter = (val) => {
let re = /^[a-z]+$/i;
const re = /^[a-z]+$/i;
return isString(val) && re.test(val);
};
const isEmail = (val) => {
let re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return isString(val) && re.test(val);

@@ -71,2 +71,3 @@ };

};
const equals = (a, b) => {

@@ -96,5 +97,5 @@ let re = true;

} else if (isObject(a) && isObject(b)) {
let as = [];
let bs = [];
for (let k1 in a) {
const as = [];
const bs = [];
for (const k1 in a) {
if (hasProperty(a, k1)) {

@@ -104,3 +105,3 @@ as.push(k1);

}
for (let k2 in b) {
for (const k2 in b) {
if (hasProperty(b, k2)) {

@@ -113,3 +114,3 @@ bs.push(k2);

}
for (let k in a) {
for (const k in a) {
if (!hasProperty(b, k) || !equals(a[k], b[k])) {

@@ -123,4 +124,5 @@ re = false;

};
const MAX_NUMBER = Number.MAX_SAFE_INTEGER;
const random = (min, max) => {
const randint = (min, max) => {
if (!min || min < 0) {

@@ -139,9 +141,9 @@ min = 0;

}
let offset = min;
let range = max - min + 1;
const offset = min;
const range = max - min + 1;
return Math.floor(Math.random() * range) + offset;
};
const MAX_STRING = 1 << 28;
const toString = (input) => {
let s = isNumber(input) ? String(input) : input;
const s = isNumber(input) ? String(input) : input;
if (!isString(s)) {

@@ -152,21 +154,5 @@ throw new Error('InvalidInput: String required.');

};
const encode = (s) => {
let x = toString(s);
return encodeURIComponent(x);
};
const decode = (s) => {
let x = toString(s);
return decodeURIComponent(x.replace(/\+/g, ' '));
};
const trim = (s, all = false) => {
let x = toString(s);
x = x.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
if (x && all) {
x = x.replace(/\r?\n|\r/g, ' ').replace(/\s\s+|\r/g, ' ');
}
return x;
};
const truncate = (s, l) => {
let o = toString(s);
let t = l || 140;
const o = toString(s);
const t = l || 140;
if (o.length <= t) {

@@ -176,4 +162,4 @@ return o;

let x = o.substring(0, t);
let a = x.split(' ');
let b = a.length;
const a = x.split(' ');
const b = a.length;
let r = '';

@@ -193,7 +179,7 @@ if (b > 1) {

const stripTags = (s) => {
let x = toString(s);
return trim(x.replace(/<.*?>/gi, ' ').replace(/\s\s+/g, ' '));
const x = toString(s);
return x.replace(/<.*?>/gi, ' ').replace(/\s\s+/g, ' ').trim();
};
const escapeHTML = (s) => {
let x = toString(s);
const x = toString(s);
return x.replace(/&/g, '&amp;')

@@ -205,3 +191,3 @@ .replace(/</g, '&lt;')

const unescapeHTML = (s) => {
let x = toString(s);
const x = toString(s);
return x.replace(/&quot;/g, '"')

@@ -221,5 +207,5 @@ .replace(/&lt;/g, '<')

const ucwords = (s) => {
let x = toString(s);
let c = x.split(' ');
let a = [];
const x = toString(s);
const c = x.split(' ');
const a = [];
c.forEach((w) => {

@@ -230,22 +216,2 @@ a.push(ucfirst(w));

};
const leftPad = (s, size = 2, pad = '0') => {
let x = toString(s);
return x.length >= size ? x : new Array(size - x.length + 1).join(pad) + x;
};
const rightPad = (s, size = 2, pad = '0') => {
let x = toString(s);
return x.length >= size ? x : x + new Array(size - x.length + 1).join(pad);
};
const repeat = (s, m) => {
let x = toString(s);
if (!isInteger(m) || m < 1) {
return x;
}
if (x.length * m >= MAX_STRING) {
throw new RangeError(`Repeat count must not overflow maximum string size.`);
}
let a = [];
a.length = m;
return a.fill(x, 0, m).join('');
};
const replaceAll = (s, a, b) => {

@@ -260,3 +226,3 @@ let x = toString(s);

if (isString(a) && isString(b)) {
let aa = x.split(a);
const aa = x.split(a);
x = aa.join(b);

@@ -268,7 +234,7 @@ } else if (isArray(a) && isString(b)) {

} else if (isArray(a) && isArray(b) && a.length === b.length) {
let k = a.length;
const k = a.length;
if (k > 0) {
for (let i = 0; i < k; i++) {
let aaa = a[i];
let bb = b[i];
const aaa = a[i];
const bb = b[i];
x = replaceAll(x, aaa, bb);

@@ -282,3 +248,3 @@ }

let x = toString(s);
let map = {
const map = {
a: 'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä',

@@ -301,8 +267,8 @@ A: 'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä',

};
let updateS = (ai, key) => {
const updateS = (ai, key) => {
x = replaceAll(x, ai, key);
};
for (let key in map) {
for (const key in map) {
if (hasProperty(map, key)) {
let a = map[key].split('|');
const a = map[key].split('|');
a.forEach((item) => {

@@ -315,7 +281,7 @@ return updateS(item, key);

};
const createId = (leng, prefix = '') => {
let lc = 'abcdefghijklmnopqrstuvwxyz';
let uc = lc.toUpperCase();
let nb = '0123456789';
let cand = [
const genid = (leng, prefix = '') => {
const lc = 'abcdefghijklmnopqrstuvwxyz';
const uc = lc.toUpperCase();
const nb = '0123456789';
const cand = [
lc,

@@ -327,7 +293,7 @@ uc,

}).join('');
let t = cand.length;
let ln = Math.max(leng || 32, prefix.length);
const t = cand.length;
const ln = Math.max(leng || 32, prefix.length);
let s = prefix;
while (s.length < ln) {
let k = random(0, t);
const k = randint(0, t);
s += cand.charAt(k) || '';

@@ -337,5 +303,5 @@ }

};
const createAlias = (s, delimiter) => {
let x = trim(stripAccent(s));
let d = delimiter || '-';
const slugify = (s, delimiter) => {
const x = stripAccent(s).trim();
const d = delimiter || '-';
return x.toLowerCase()

@@ -346,53 +312,3 @@ .replace(/\W+/g, ' ')

};
const compile = (tpl, data) => {
let ns = [];
let c = (s, ctx, namespace) => {
if (namespace) {
ns.push(namespace);
}
let a = [];
for (let k in ctx) {
if (hasProperty(ctx, k)) {
let v = ctx[k];
if (isNumber(v)) {
v = String(v);
}
if (isObject(v) || isArray(v)) {
a.push({
key: k,
data: v,
});
} else if (isString(v)) {
v = replaceAll(v, [
'{',
'}',
], [
'&#123;',
'&#125;',
]);
let cns = ns.concat([k]);
let r = new RegExp('{' + cns.join('.') + '}', 'gi');
s = s.replace(r, v);
}
}
}
if (a.length > 0) {
a.forEach((item) => {
s = c(s, item.data, item.key);
});
}
return trim(s, true);
};
if (data && (isString(data) || isObject(data) || isArray(data))) {
return c(tpl, data);
}
return tpl;
};
const template = (tpl) => {
return {
compile: (data) => {
return compile(tpl, data);
},
};
};
const PATTERN = 'D, M d, Y h:i:s A';

@@ -415,12 +331,12 @@ const WEEKDAYS = [

const tz = (() => {
let z = Math.abs(tzone / 60);
let sign = tzone < 0 ? '+' : '-';
return ['GMT', sign, leftPad(z, 4)].join('');
const z = Math.abs(tzone / 60);
const sign = tzone < 0 ? '+' : '-';
return ['GMT', sign, String(z).padStart(4, '0')].join('');
})();
let _num = (n) => {
const _num = (n) => {
return String(n < 10 ? '0' + n : n);
};
let _ord = (day) => {
const _ord = (day) => {
let s = day + ' ';
let x = s.charAt(s.length - 2);
const x = s.charAt(s.length - 2);
if (x === '1') {

@@ -437,4 +353,4 @@ s = 'st';

};
let format = (input, output = PATTERN) => {
let d = isDate(input) ? input : new Date(input);
const format = (input, output = PATTERN) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {

@@ -446,6 +362,6 @@ throw new Error('InvalidInput: Number or Date required.');

}
let vchar = /\.*\\?([a-z])/gi;
let meridiem = output.match(/(\.*)a{1}(\.*)*/i);
let wn = WEEKDAYS;
let mn = MONTHS;
const vchar = /\.*\\?([a-z])/gi;
const meridiem = output.match(/(\.*)a{1}(\.*)*/i);
const wn = WEEKDAYS;
const mn = MONTHS;
let f = {

@@ -516,3 +432,3 @@ Y() {

};
let _term = (t, s) => {
const _term = (t, s) => {
return f[t] ? f[t]() : s;

@@ -522,4 +438,4 @@ };

};
let relativize = (input = time()) => {
let d = isDate(input) ? input : new Date(input);
const relativize = (input = time()) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {

@@ -537,3 +453,3 @@ throw new Error('InvalidInput: Number or Date required.');

let units = null;
let conversions = {
const conversions = {
millisecond: 1,

@@ -547,3 +463,3 @@ second: 1000,

};
for (let key in conversions) {
for (const key in conversions) {
if (delta < conversions[key]) {

@@ -562,14 +478,14 @@ break;

};
let utc = (input = time()) => {
let d = isDate(input) ? input : new Date(input);
const utc = (input = time()) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {
throw new Error('InvalidInput: Number or Date required.');
}
let dMinutes = d.getMinutes();
let dClone = new Date(d);
const dMinutes = d.getMinutes();
const dClone = new Date(d);
dClone.setMinutes(dMinutes + tzone);
return `${format(dClone, 'D, j M Y h:i:s')} GMT+0000`;
};
let local = (input = time()) => {
let d = isDate(input) ? input : new Date(input);
const local = (input = time()) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {

@@ -580,2 +496,3 @@ throw new Error('InvalidInput: Number or Date required.');

};
let md5 = (str) => {

@@ -635,5 +552,6 @@ var k = [], i = 0;

};
const curry = (fn) => {
let totalArguments = fn.length;
let next = (argumentLength, rest) => {
const totalArguments = fn.length;
const next = (argumentLength, rest) => {
if (argumentLength > 0) {

@@ -658,5 +576,5 @@ return (...args) => {

}
let copyObject = (o) => {
let oo = Object.create({});
for (let k in o) {
const copyObject = (o) => {
const oo = Object.create({});
for (const k in o) {
if (hasProperty(o, k)) {

@@ -668,3 +586,3 @@ oo[k] = clone(o[k]);

};
let copyArray = (a) => {
const copyArray = (a) => {
return [...a].map((e) => {

@@ -688,9 +606,9 @@ if (isArray(e)) {

const copies = (source, dest, matched = false, excepts = []) => {
for (let k in source) {
for (const k in source) {
if (excepts.length > 0 && excepts.includes(k)) {
continue;
}
if (!matched || matched && dest.hasOwnProperty(k)) {
let oa = source[k];
let ob = dest[k];
if (!matched || matched && hasProperty(dest, k)) {
const oa = source[k];
const ob = dest[k];
if (isObject(ob) && isObject(oa) || isArray(ob) && isArray(oa)) {

@@ -708,50 +626,69 @@ dest[k] = copies(oa, dest[k], matched, excepts);

};
exports.curry = curry;
const sort = (fn, arr = []) => {
return [...arr].sort(fn);
};
const sortBy = (key, order = 1, arr = []) => {
return sort(arr, (m, n) => {
return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0);
});
};
const shuffle = (arr = []) => {
return sort(() => {
return Math.random() > 0.5;
}, [...arr]);
};
const pick = (count = 1, arr = []) => {
const a = shuffle([...arr]);
const mc = Math.max(1, count);
const c = Math.min(mc, a.length - 1);
return a.splice(0, c);
};
exports.clone = clone;
exports.compose = compose;
exports.pipe = pipe;
exports.clone = clone;
exports.copies = copies;
exports.unique = unique;
exports.isNull = isNull;
exports.isUndefined = isUndefined;
exports.isFunction = isFunction;
exports.isString = isString;
exports.isNumber = isNumber;
exports.isInteger = isInteger;
exports.curry = curry;
exports.equals = equals;
exports.escapeHTML = escapeHTML;
exports.format = format;
exports.genid = genid;
exports.hasProperty = hasProperty;
exports.isArray = isArray;
exports.isObject = isObject;
exports.isBoolean = isBoolean;
exports.isDate = isDate;
exports.isElement = isElement;
exports.isLetter = isLetter;
exports.isEmail = isEmail;
exports.isEmpty = isEmpty;
exports.hasProperty = hasProperty;
exports.equals = equals;
exports.encode = encode;
exports.decode = decode;
exports.trim = trim;
exports.isFunction = isFunction;
exports.isInteger = isInteger;
exports.isLetter = isLetter;
exports.isNull = isNull;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.isString = isString;
exports.isUndefined = isUndefined;
exports.local = local;
exports.md5 = md5;
exports.now = now;
exports.pick = pick;
exports.pipe = pipe;
exports.randint = randint;
exports.relativize = relativize;
exports.replaceAll = replaceAll;
exports.shuffle = shuffle;
exports.slugify = slugify;
exports.sort = sort;
exports.sortBy = sortBy;
exports.stripAccent = stripAccent;
exports.stripTags = stripTags;
exports.time = time;
exports.truncate = truncate;
exports.stripTags = stripTags;
exports.escapeHTML = escapeHTML;
exports.unescapeHTML = unescapeHTML;
exports.ucfirst = ucfirst;
exports.ucwords = ucwords;
exports.leftPad = leftPad;
exports.rightPad = rightPad;
exports.repeat = repeat;
exports.replaceAll = replaceAll;
exports.stripAccent = stripAccent;
exports.createId = createId;
exports.createAlias = createAlias;
exports.template = template;
exports.random = random;
exports.now = now;
exports.time = time;
exports.format = format;
exports.relativize = relativize;
exports.unescapeHTML = unescapeHTML;
exports.unique = unique;
exports.utc = utc;
exports.local = local;
exports.md5 = md5;
Object.defineProperty(exports, '__esModule', { value: true });
})));
}));

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

// bellajs@7.5.0, by @ndaidong - built on Mon, 17 Sep 2018 08:14:14 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.bella={})}(this,function(e){"use strict";const t=e=>({}).toString.call(e),r=e=>"[object Null]"===t(e),n=e=>"[object Undefined]"===t(e),l=e=>"[object String]"===t(e),i=e=>"[object Number]"===t(e),a=e=>Number.isInteger(e),o=e=>Array.isArray(e),u=e=>"[object Object]"===t(e)&&!o(e),s=e=>e instanceof Date&&!isNaN(e.valueOf()),c=e=>!e||n(e)||r(e)||l(e)&&""===e||o(e)&&"[]"===JSON.stringify(e)||u(e)&&"{}"===JSON.stringify(e),g=(e,t)=>!(!e||!t)&&Object.prototype.hasOwnProperty.call(e,t),p=(e,t)=>{let r=!0;if(c(e)&&c(t))return!0;if(s(e)&&s(t))return e.getTime()===t.getTime();if(i(e)&&i(t)||l(e)&&l(t))return e===t;if(o(e)&&o(t)){if(e.length!==t.length)return!1;if(e.length>0)for(let n=0,l=e.length;n<l;n++)if(!p(e[n],t[n])){r=!1;break}}else if(u(e)&&u(t)){let n=[],l=[];for(let t in e)g(e,t)&&n.push(t);for(let e in t)g(t,e)&&l.push(e);if(n.length!==l.length)return!1;for(let n in e)if(!g(t,n)||!p(e[n],t[n])){r=!1;break}}return r},f=Number.MAX_SAFE_INTEGER,h=(e,t)=>{if((!e||e<0)&&(e=0),t||(t=f),e===t)return t;e>t&&(e=Math.min(e,t),t=Math.max(e,t));let r=e,n=t-e+1;return Math.floor(Math.random()*n)+r},d=e=>{let t=i(e)?String(e):e;if(!l(t))throw new Error("InvalidInput: String required.");return t},m=(e,t=!1)=>{let r=d(e);return(r=r.replace(/^[\s\xa0]+|[\s\xa0]+$/g,""))&&t&&(r=r.replace(/\r?\n|\r/g," ").replace(/\s\s+|\r/g," ")),r},w=e=>{let t=d(e);return 1===t.length?t.toUpperCase():(t=t.toLowerCase()).charAt(0).toUpperCase()+t.slice(1)},y=(e,t=2,r="0")=>{let n=d(e);return n.length>=t?n:new Array(t-n.length+1).join(r)+n},b=(e,t,r)=>{let n=d(e);if(i(t)&&(t=String(t)),i(r)&&(r=String(r)),l(t)&&l(r)){let e=n.split(t);n=e.join(r)}else if(o(t)&&l(r))t.forEach(e=>{n=b(n,e,r)});else if(o(t)&&o(r)&&t.length===r.length){let e=t.length;if(e>0)for(let l=0;l<e;l++){let e=t[l],i=r[l];n=b(n,e,i)}}return n},j=e=>{let t=d(e),r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"};for(let e in r)if(g(r,e)){r[e].split("|").forEach(r=>{t=b(t,r,e)})}return t};const M=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],D=["January","February","March","April","May","June","July","August","September","October","November","December"],E=()=>new Date,I=()=>Date.now(),A=E().getTimezoneOffset(),S=(()=>{let e=Math.abs(A/60);return["GMT",A<0?"+":"-",y(e,4)].join("")})();let N=e=>String(e<10?"0"+e:e),O=(e,t="D, M d, Y h:i:s A")=>{let r=s(e)?e:new Date(e);if(!s(r))throw new Error("InvalidInput: Number or Date required.");if(!l(t))throw new Error("Invalid output pattern.");let n=t.match(/(\.*)a{1}(\.*)*/i),i=M,a=D,o={Y:()=>r.getFullYear(),y:()=>(o.Y()+"").slice(-2),F:()=>a[o.n()-1],M:()=>(o.F()+"").slice(0,3),m:()=>N(o.n()),n:()=>r.getMonth()+1,S:()=>(e=>{let t=e+" ",r=t.charAt(t.length-2);return t="1"===r?"st":"2"===r?"nd":"3"===r?"rd":"th"})(o.j()),j:()=>r.getDate(),d:()=>N(o.j()),t:()=>new Date(o.Y(),o.n(),0).getDate(),w:()=>r.getDay(),l:()=>i[o.w()],D:()=>(o.l()+"").slice(0,3),G:()=>r.getHours(),g:()=>o.G()%12||12,h:()=>N(n?o.g():o.G()),i:()=>N(r.getMinutes()),s:()=>N(r.getSeconds()),a:()=>o.G()>11?"pm":"am",A:()=>o.a().toUpperCase(),O:()=>S};return t.replace(/\.*\\?([a-z])/gi,(e,t)=>o[e]?o[e]():t)};const v=e=>{if(s(e))return new Date(e.valueOf());let t=e=>{let t=Object.create({});for(let r in e)g(e,r)&&(t[r]=v(e[r]));return t},r=e=>[...e].map(e=>o(e)?r(e):u(e)?t(e):v(e));return o(e)?r(e):u(e)?t(e):e},T=(e,t,r=!1,n=[])=>{for(let l in e)if(!(n.length>0&&n.includes(l))&&(!r||r&&t.hasOwnProperty(l))){let i=e[l],a=t[l];u(a)&&u(i)||o(a)&&o(i)?t[l]=T(i,t[l],r,n):t[l]=v(i)}return t};e.curry=(e=>{let t=e.length,r=(t,n)=>t>0?(...e)=>r(t-e.length,[...n,...e]):e(...n);return r(t,[])}),e.compose=((...e)=>e.reduce((e,t)=>r=>e(t(r)))),e.pipe=((...e)=>e.reduce((e,t)=>r=>t(e(r)))),e.clone=v,e.copies=T,e.unique=((e=[])=>[...new Set(e)]),e.isNull=r,e.isUndefined=n,e.isFunction=(e=>"[object Function]"===t(e)),e.isString=l,e.isNumber=i,e.isInteger=a,e.isArray=o,e.isObject=u,e.isBoolean=(e=>!0===e||!1===e),e.isDate=s,e.isElement=(e=>t(e).match(/^\[object HTML\w*Element]$/)),e.isLetter=(e=>{return l(e)&&/^[a-z]+$/i.test(e)}),e.isEmail=(e=>{return l(e)&&/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(e)}),e.isEmpty=c,e.hasProperty=g,e.equals=p,e.encode=(e=>{let t=d(e);return encodeURIComponent(t)}),e.decode=(e=>{let t=d(e);return decodeURIComponent(t.replace(/\+/g," "))}),e.trim=m,e.truncate=((e,t)=>{let r=d(e),n=t||140;if(r.length<=n)return r;let l=r.substring(0,n),i=l.split(" "),a="";return i.length>1?(i.pop(),(a+=i.join(" ")).length<r.length&&(a+="...")):a=(l=l.substring(0,n-3))+"...",a}),e.stripTags=(e=>{let t=d(e);return m(t.replace(/<.*?>/gi," ").replace(/\s\s+/g," "))}),e.escapeHTML=(e=>{return d(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}),e.unescapeHTML=(e=>{return d(e).replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")}),e.ucfirst=w,e.ucwords=(e=>{let t=[];return d(e).split(" ").forEach(e=>{t.push(w(e))}),t.join(" ")}),e.leftPad=y,e.rightPad=((e,t=2,r="0")=>{let n=d(e);return n.length>=t?n:n+new Array(t-n.length+1).join(r)}),e.repeat=((e,t)=>{let r=d(e);if(!a(t)||t<1)return r;if(r.length*t>=1<<28)throw new RangeError("Repeat count must not overflow maximum string size.");let n=[];return n.length=t,n.fill(r,0,t).join("")}),e.replaceAll=b,e.stripAccent=j,e.createId=((e,t="")=>{let r="abcdefghijklmnopqrstuvwxyz",n=[r,r.toUpperCase(),"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),l=n.length,i=Math.max(e||32,t.length),a=t;for(;a.length<i;){let e=h(0,l);a+=n.charAt(e)||""}return a}),e.createAlias=((e,t)=>{let r=m(j(e)),n=t||"-";return r.toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,n)}),e.template=(e=>({compile:t=>((e,t)=>{let r=[],n=(e,t,a)=>{a&&r.push(a);let s=[];for(let n in t)if(g(t,n)){let a=t[n];if(i(a)&&(a=String(a)),u(a)||o(a))s.push({key:n,data:a});else if(l(a)){a=b(a,["{","}"],["&#123;","&#125;"]);let t=r.concat([n]),l=new RegExp("{"+t.join(".")+"}","gi");e=e.replace(l,a)}}return s.length>0&&s.forEach(t=>{e=n(e,t.data,t.key)}),m(e,!0)};return t&&(l(t)||u(t)||o(t))?n(e,t):e})(e,t)})),e.random=h,e.now=E,e.time=I,e.format=O,e.relativize=((e=I())=>{let t=s(e)?e:new Date(e);if(!s(t))throw new Error("InvalidInput: Number or Date required.");let r=E()-t,n=parseInt(t,10);if(isNaN(n)&&(n=0),r<=n)return"Just now";let l=null,i={millisecond:1,second:1e3,minute:60,hour:60,day:24,month:30,year:12};for(let e in i){if(r<i[e])break;l=e,r/=i[e]}return 1!==(r=Math.floor(r))&&(l+="s"),[r,l].join(" ")+" ago"}),e.utc=((e=I())=>{let t=s(e)?e:new Date(e);if(!s(t))throw new Error("InvalidInput: Number or Date required.");let r=t.getMinutes(),n=new Date(t);return n.setMinutes(r+A),`${O(n,"D, j M Y h:i:s")} GMT+0000`}),e.local=((e=I())=>{let t=s(e)?e:new Date(e);if(!s(t))throw new Error("InvalidInput: Number or Date required.");return O(t,"D, j M Y h:i:s O")}),e.md5=(e=>{for(var t=[],r=0;r<64;)t[r]=0|4294967296*Math.abs(Math.sin(++r));var n,l,i,a,o=[],u=unescape(encodeURI(e)),s=u.length,c=[n=1732584193,l=-271733879,~n,~l];for(r=0;r<=s;)o[r>>2]|=(u.charCodeAt(r)||128)<<r++%4*8;for(o[e=16*(s+8>>6)+14]=8*s,r=0;r<e;r+=16){for(s=c,a=0;a<64;)s=[i=s[3],(n=0|s[1])+((i=s[0]+[n&(l=s[2])|~n&i,i&n|~i&l,n^l^i,l^(n|~i)][s=a>>4]+(t[a]+(0|o[[a,5*a+1,3*a+5,7*a][s]%16+r])))<<(s=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*s+a++%4])|i>>>32-s),n,l];for(a=4;a;)c[--a]=c[a]+s[a]}for(e="";a<32;)e+=(c[a>>3]>>4*(1^7&a++)&15).toString(16);return e}),Object.defineProperty(e,"__esModule",{value:!0})});
// bellajs@8.0.0rc1, by @ndaidong - built on Thu, 12 Sep 2019 23:48:47 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=e||self).bella={})}(this,(function(e){const t=e=>({}).toString.call(e),r=e=>"[object Null]"===t(e),n=e=>"[object Undefined]"===t(e),o=e=>"[object String]"===t(e),i=e=>"[object Number]"===t(e),a=e=>Array.isArray(e),s=e=>"[object Object]"===t(e)&&!a(e),l=e=>e instanceof Date&&!isNaN(e.valueOf()),c=e=>!e||n(e)||r(e)||o(e)&&""===e||a(e)&&"[]"===JSON.stringify(e)||s(e)&&"{}"===JSON.stringify(e),u=(e,t)=>!(!e||!t)&&Object.prototype.hasOwnProperty.call(e,t),f=(e,t)=>{let r=!0;if(c(e)&&c(t))return!0;if(l(e)&&l(t))return e.getTime()===t.getTime();if(i(e)&&i(t)||o(e)&&o(t))return e===t;if(a(e)&&a(t)){if(e.length!==t.length)return!1;if(e.length>0)for(let n=0,o=e.length;n<o;n++)if(!f(e[n],t[n])){r=!1;break}}else if(s(e)&&s(t)){const n=[],o=[];for(const t in e)u(e,t)&&n.push(t);for(const e in t)u(t,e)&&o.push(e);if(n.length!==o.length)return!1;for(const n in e)if(!u(t,n)||!f(e[n],t[n])){r=!1;break}}return r},g=Number.MAX_SAFE_INTEGER,p=(e,t)=>{if((!e||e<0)&&(e=0),t||(t=g),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},h=e=>{const t=i(e)?String(e):e;if(!o(t))throw new Error("InvalidInput: String required.");return t},d=e=>{let t=h(e);return 1===t.length?t.toUpperCase():(t=t.toLowerCase()).charAt(0).toUpperCase()+t.slice(1)},m=(e,t,r)=>{let n=h(e);if(i(t)&&(t=String(t)),i(r)&&(r=String(r)),o(t)&&o(r)){const e=n.split(t);n=e.join(r)}else if(a(t)&&o(r))t.forEach(e=>{n=m(n,e,r)});else if(a(t)&&a(r)&&t.length===r.length){const e=t.length;if(e>0)for(let o=0;o<e;o++){const e=t[o],i=r[o];n=m(n,e,i)}}return n},w=e=>{let t=h(e);const r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(e,r)=>{t=m(t,e,r)};for(const e in r)if(u(r,e)){r[e].split("|").forEach(t=>n(t,e))}return t},b=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],y=["January","February","March","April","May","June","July","August","September","October","November","December"],M=()=>new Date,j=()=>Date.now(),D=M().getTimezoneOffset(),S=(()=>{const e=Math.abs(D/60);return["GMT",D<0?"+":"-",String(e).padStart(4,"0")].join("")})(),N=e=>String(e<10?"0"+e:e),E=(e,t="D, M d, Y h:i:s A")=>{const r=l(e)?e:new Date(e);if(!l(r))throw new Error("InvalidInput: Number or Date required.");if(!o(t))throw new Error("Invalid output pattern.");const n=t.match(/(\.*)a{1}(\.*)*/i),i=b,a=y;let s={Y:()=>r.getFullYear(),y:()=>(s.Y()+"").slice(-2),F:()=>a[s.n()-1],M:()=>(s.F()+"").slice(0,3),m:()=>N(s.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"})(s.j()),j:()=>r.getDate(),d:()=>N(s.j()),t:()=>new Date(s.Y(),s.n(),0).getDate(),w:()=>r.getDay(),l:()=>i[s.w()],D:()=>(s.l()+"").slice(0,3),G:()=>r.getHours(),g:()=>s.G()%12||12,h:()=>N(n?s.g():s.G()),i:()=>N(r.getMinutes()),s:()=>N(r.getSeconds()),a:()=>s.G()>11?"pm":"am",A:()=>s.a().toUpperCase(),O:()=>S};return t.replace(/\.*\\?([a-z])/gi,(e,t)=>s[e]?s[e]():t)};const I=e=>{if(l(e))return new Date(e.valueOf());const t=e=>{const t=Object.create({});for(const r in e)u(e,r)&&(t[r]=I(e[r]));return t},r=e=>[...e].map(e=>a(e)?r(e):s(e)?t(e):I(e));return a(e)?r(e):s(e)?t(e):e},A=(e,t,r=!1,n=[])=>{for(const o in e)if(!(n.length>0&&n.includes(o))&&(!r||r&&u(t,o))){const i=e[o],l=t[o];s(l)&&s(i)||a(l)&&a(i)?t[o]=A(i,t[o],r,n):t[o]=I(i)}return t},O=(e,t=[])=>[...t].sort(e),v=(e=[])=>O(()=>Math.random()>.5,[...e]);e.clone=I,e.compose=(...e)=>e.reduce((e,t)=>r=>e(t(r))),e.copies=A,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=>{return h(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e.format=E,e.genid=(e,t="")=>{const r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),o=[r,n,"0123456789"].join("").split("").sort(()=>Math.random()>.5).join(""),i=o.length,a=Math.max(e||32,t.length);let s=t;for(;s.length<a;){const e=p(0,i);s+=o.charAt(e)||""}return s},e.hasProperty=u,e.isArray=a,e.isBoolean=e=>!0===e||!1===e,e.isDate=l,e.isElement=e=>t(e).match(/^\[object HTML\w*Element]$/),e.isEmail=e=>{return o(e)&&/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(e)},e.isEmpty=c,e.isFunction=e=>"[object Function]"===t(e),e.isInteger=e=>Number.isInteger(e),e.isLetter=e=>{return o(e)&&/^[a-z]+$/i.test(e)},e.isNull=r,e.isNumber=i,e.isObject=s,e.isString=o,e.isUndefined=n,e.local=(e=j())=>{const t=l(e)?e:new Date(e);if(!l(t))throw new Error("InvalidInput: Number or Date required.");return E(t,"D, j M Y h:i:s O")},e.md5=e=>{for(var t=[],r=0;r<64;)t[r]=0|4294967296*Math.abs(Math.sin(++r));var n,o,i,a,s=[],l=unescape(encodeURI(e)),c=l.length,u=[n=1732584193,o=-271733879,~n,~o];for(r=0;r<=c;)s[r>>2]|=(l.charCodeAt(r)||128)<<r++%4*8;for(s[e=16*(c+8>>6)+14]=8*c,r=0;r<e;r+=16){for(c=u,a=0;a<64;)c=[i=c[3],(n=0|c[1])+((i=c[0]+[n&(o=c[2])|~n&i,i&n|~i&o,n^o^i,o^(n|~i)][c=a>>4]+(t[a]+(0|s[[a,5*a+1,3*a+5,7*a][c]%16+r])))<<(c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*c+a++%4])|i>>>32-c),n,o];for(a=4;a;)u[--a]=u[a]+c[a]}for(e="";a<32;)e+=(u[a>>3]>>4*(1^7&a++)&15).toString(16);return e},e.now=M,e.pick=(e=1,t=[])=>{const r=v([...t]),n=Math.max(1,e),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=p,e.relativize=(e=j())=>{const t=l(e)?e:new Date(e);if(!l(t))throw new Error("InvalidInput: Number or Date required.");let r=M()-t,n=parseInt(t,10);if(isNaN(n)&&(n=0),r<=n)return"Just now";let o=null;const i={millisecond:1,second:1e3,minute:60,hour:60,day:24,month:30,year:12};for(const e in i){if(r<i[e])break;o=e,r/=i[e]}return 1!==(r=Math.floor(r))&&(o+="s"),[r,o].join(" ")+" ago"},e.replaceAll=m,e.shuffle=v,e.slugify=(e,t)=>{const r=t||"-";return w(e).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,r)},e.sort=O,e.sortBy=(e,t=1,r=[])=>O(r,(r,n)=>r[e]>n[e]?t:r[e]<n[e]?-1*t:0),e.stripAccent=w,e.stripTags=e=>{return h(e).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim()},e.time=j,e.truncate=(e,t)=>{const r=h(e),n=t||140;if(r.length<=n)return r;let o=r.substring(0,n);const i=o.split(" ");let a="";return i.length>1?(i.pop(),(a+=i.join(" ")).length<r.length&&(a+="...")):a=(o=o.substring(0,n-3))+"...",a},e.ucfirst=d,e.ucwords=e=>{const t=h(e).split(" "),r=[];return t.forEach(e=>{r.push(d(e))}),r.join(" ")},e.unescapeHTML=e=>{return h(e).replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")},e.unique=(e=[])=>[...new Set(e)],e.utc=(e=j())=>{const t=l(e)?e:new Date(e);if(!l(t))throw new Error("InvalidInput: Number or Date required.");const r=t.getMinutes(),n=new Date(t);return n.setMinutes(r+D),`${E(n,"D, j M Y h:i:s")} GMT+0000`},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"version": "7.5.0",
"version": "8.0.0rc1",
"name": "bellajs",

@@ -11,2 +11,3 @@ "description": "A useful helper for any javascript program",

"author": "@ndaidong",
"type": "module",
"main": "./dist/bella.js",

@@ -22,3 +23,3 @@ "module": "./src/main",

"pretest": "npm run lint && npm run build",
"test": "COVERALLS_REPO_TOKEN=Tl5oBwZaxoIDd9uRqe0bl6xMfmorjPuAP tap test/start.js --coverage --reporter=spec",
"test": "COVERALLS_REPO_TOKEN=Tl5oBwZaxoIDd9uRqe0bl6xMfmorjPuAP TZ=Asia/Ho_Chi_Minh tap test/start.js --coverage --reporter=spec",
"build": "gccmin -e src/main.js -n bella -o dist -p package.json",

@@ -28,11 +29,11 @@ "reset": "node reset"

"devDependencies": {
"coveralls": "^3.0.2",
"eslint": "^5.6.0",
"eslint-config-goes": "^1.0.0",
"gcc-min": "^7.0.1",
"is": "^3.2.1",
"jsdom": "^12.0.0",
"coveralls": "^3.0.6",
"eslint": "^6.3.0",
"eslint-config-goes": "^1.1.6",
"gcc-min": "^7.1.0",
"is": "^3.3.0",
"jsdom": "^15.1.1",
"jsdom-global": "^3.0.2",
"sinon": "^6.3.3",
"tap": "^12.0.1"
"sinon": "^7.4.2",
"tap": "^14.6.2"
},

@@ -39,0 +40,0 @@ "keywords": [

@@ -10,2 +10,4 @@ BellaJS

You may be interested in [BellaPy](https://github.com/ndaidong/bellapy) too.
# Contents

@@ -20,12 +22,17 @@

* [Other utils](#other-utils)
* [clone](#cloneanything-val)
* [copies](#copiesobject-source-object-target-boolean-requirematching-array-excepts)
* [createId](#createidnumber-length--string-prefix)
* [equals](#equalsanything-a-anything-b)
* [md5](#md5string-s)
* [random](#randomnumber-min--number-max)
* [unique](#uniquearray-a)
* [clone](#clone)
* [compose](#compose)
* [copies](#copies)
* [curry](#curryfn)
* [compose](#composef1-f2-fn)
* [pipe](#pipef1-f2-fn)
* [equals](#equals)
* [genid](#genid)
* [md5](#md5)
* [pick](#pick)
* [pipe](#pipe)
* [randint](#randint)
* [sort](#sort)
* [sortBy](#sortBy)
* [shuffle](#shuffle)
* [unique](#unique)
* [Test](#test)

@@ -40,3 +47,3 @@ * [License](#license)

```
npm install bellajs
npm i bellajs
```

@@ -50,3 +57,3 @@

- Also supports ES6 Module, CommonJS, AMD and UMD style.
- Load with ESM, CommonJS, AMD or UMD style

@@ -56,9 +63,15 @@

```
var bella = require('bellajs');
```js
const bella = require('bellajs');
// or:
// few methods only:
const {
isArray,
isString,
} = require('bellajs');
// es6 syntax:
import bella from 'bellajs';
// or import several methods only
// with tree shacking
import {

@@ -68,9 +81,2 @@ isArray,

} from 'bellajs';
// similar:
var {
isArray,
isString,
} = require('bellajs');
```

@@ -82,2 +88,3 @@

### DataType detection
- .isArray(Anything val)

@@ -100,5 +107,3 @@ - .isBoolean(Anything val)

### String manipulation
- .createAlias(String s)
- .encode(String s)
- .decode(String s)
- .ucfirst(String s)

@@ -108,57 +113,23 @@ - .ucwords(String s)

- .unescapeHTML(String s)
- .slugify(String s)
- .stripTags(String s)
- .stripAccent(String s)
- .trim(String s [, Boolean nospace])
- .truncate(String s, Number limit)
- .repeat(String s, Number times)
- .leftPad(String s, Number limit, String pad)
- .rightPad(String s, Number limit, String pad)
- .replaceAll(String s, String|Array search, String|Array replace)
### Template
- .template(String tpl)
Returns an object with .compile() method
### Date format
Example:
- `relativize([Date | Timestamp])`
- `format([Date | Timestamp] [, String pattern])`
- `local([Date | Timestamp])`
- `utc([Date | Timestamp])`
```
var tpl = [
'<article>',
'<a href="{link}">{title}</a>',
'<p>{content}</p>',
'<p>',
'<span>{author.name}</span>',
'<span>{author.email}</span>',
'</p>',
'</article>'
].join('');
Default pattern for `format()` method is `D, M d, Y H:i:s A`.
var data = {
title: 'Hello world',
link: 'http://google.com',
content: 'This is an interesting thing, is that right?',
author: {
name: 'Dong Nguyen',
email: 'ndaidong@gmail.com'
}
}
Pattern for `local()` and `utc()` is `D, j M Y h:i:s O`.
var html = bella.template(tpl).compile(data);
console.log(html);
Here are the available characters:
```
### Date format
- .relativize([Date | Timestamp])
- .format([Date | Timestamp] [, String pattern])
- .local([Date | Timestamp])
- .utc([Date | Timestamp])
Default pattern for `.format()` method is `D, M d, Y H:i:s A`.
Pattern for `.local()` and `.utc()` is `D, j M Y h:i:s O`.
Here are the available characters:
- Y: full year, ex: 2050

@@ -185,6 +156,7 @@ - y: short year, ex: 50

- O: timezone
```
Example:
```
```js
import {

@@ -208,7 +180,11 @@ relativize,

##### .clone(Anything val):
#### clone
```js
clone(Anything val)
```
Return a copy of val.
```
```js
let b = [

@@ -228,3 +204,3 @@ 1, 5, 0, 'a', -10, '-10', '',

```
```js
cb[7].a = 2;

@@ -238,3 +214,3 @@ cb[7].b = 'Noop';

```
```js
{

@@ -246,6 +222,50 @@ a: 1,

##### .copies(Object source, Object target[[, Boolean requireMatching], Array excepts]):
#### compose
Performs right-to-left function composition.
```js
compose(f1, f2, ...fN)
```
Examples:
```js
import {compose} from 'bellajs';
let f1 = (name) => {
return `f1 ${name}`;
};
let f2 = (name) => {
return `f2 ${name}`;
};
let f3 = (name) => {
return `f3 ${name}`;
};
let addF = compose(f1, f2, f3);
addF('Hello') // => 'f1 f2 f3 Hello'
let add1 = (num) => {
return num + 1;
};
let mult2 = (num) => {
return num * 2;
};
let add1AndMult2 = compose(add1, mult2);
add1AndMult2(3) // => 7
// because multiple to 2 first, then add 1 late => 3 * 2 + 1
```
#### copies
Copy the properties from *source* to *target*.
```js
copies(Object source, Object target[[, Boolean requireMatching], Array excepts])
```
- *requireMatching*: if true, BellaJS only copies the properties that are already exist in *target*.

@@ -256,3 +276,3 @@ - *excepts*: array of the properties properties in *source* that you don't want to copy.

```
```js
let a = {

@@ -285,3 +305,3 @@ name: 'Toto',

```
```js
{

@@ -304,16 +324,33 @@ level: 8,

##### .createId([Number length [, String prefix]])
#### curry
```js
curry(fn)
```
import {createId} from 'bellajs';
createId(); // => random 32 chars
createId(16); // => random 16 chars
createId(5); // => random 5 chars
createId(5, 'X_'); // => X_{random 3 chars}
Examples:
```js
import {curry} from 'bellajs';
let sum = curry((a, b, c) => {
return a + b + c;
});
sum(3)(2)(1) // => 6
sum(1)(2)(3) // => 6
sum(1, 2)(3) // => 6
sum(1)(2, 3) // => 6
sum(1, 2, 3) // => 6
```
##### .equals(Anything a, Anything b)
#### equals
```js
equals(Anything a, Anything b)
```
Examples:
```js
import {equals} from 'bellajs';

@@ -325,51 +362,65 @@

##### .md5(String s)
#### genid
```js
genid([Number length [, String prefix]])
```
import {md5} from 'bellajs';
md5('abc'); // => 900150983cd24fb0d6963f7d28e17f72
```
Examples:
##### .random([Number min [, Number max]])
```js
import {genid} from 'bellajs';
genid(); // => random 32 chars
genid(16); // => random 16 chars
genid(5); // => random 5 chars
genid(5, 'X_'); // => X_{random 3 chars}
```
import {random} from 'bellajs';
random(); // => a random integer
random(1, 5); // => a random integer between 3 and 5, including 1 and 5
#### md5
```js
md5(String s)
```
Examples:
##### .unique(Array a)
```js
import {md5} from 'bellajs';
md5('abc'); // => 900150983cd24fb0d6963f7d28e17f72
```
import {unique} from 'bellajs';
unique([1, 2, 3, 2, 3, 1, 5]); // => [ 1, 2, 3, 5 ]
```
#### pick
##### .curry(fn)
Randomly choose N elements from array.
```js
pick(Integer count, Array arr)
```
import {curry} from 'bellajs';
let sum = curry((a, b, c) => {
return a + b + c;
});
Examples:
sum(3)(2)(1) // => 6
sum(1)(2)(3) // => 6
sum(1, 2)(3) // => 6
sum(1)(2, 3) // => 6
sum(1, 2, 3) // => 6
```js
import {pick} from 'bellajs';
const arr = [1, 3, 8, 2, 5, 7]
pick(arr, 2); // --> [3, 5]
pick(arr, 2); // --> [8, 1]
```
##### .compose(f1, f2, ...fN)
#### pipe
Performs right-to-left function composition.
Performs left-to-right function composition.
```js
pipe(f1, f2, ...fN)
```
import {compose} from 'bellajs';
Examples:
```js
import {pipe} from 'bellajs';
let f1 = (name) => {

@@ -385,5 +436,5 @@ return `f1 ${name}`;

let addF = compose(f1, f2, f3);
let addF = pipe(f1, f2, f3);
addF('Hello') // => 'f1 f2 f3 Hello'
addF('Hello') // => 'f3 f2 f1 Hello'

@@ -398,53 +449,111 @@ let add1 = (num) => {

let add1AndMult2 = compose(add1, mult2);
add1AndMult2(3) // => 7
// because multiple to 2 first, then add 1 late => 3 * 2 + 1
let add1AndMult2 = pipe(add1, mult2);
add1AndMult2(3) // => 8
// because add 1 first, then multiple to 2 late => (3 + 1) * 2
```
##### .pipe(f1, f2, ...fN)
#### randint
Performs left-to-right function composition.
```js
randint([Number min [, Number max]])
```
Examples:
```js
import {randint} from 'bellajs';
randint(); // => a random integer
randint(1, 5); // => a random integer between 3 and 5, including 1 and 5
```
import {pipe} from 'bellajs';
let f1 = (name) => {
return `f1 ${name}`;
};
let f2 = (name) => {
return `f2 ${name}`;
};
let f3 = (name) => {
return `f3 ${name}`;
};
let addF = pipe(f1, f2, f3);
#### sort
addF('Hello') // => 'f3 f2 f1 Hello'
```js
sort(Array a, Number order)
```
let add1 = (num) => {
return num + 1;
};
Examples:
let mult2 = (num) => {
return num * 2;
};
```js
import {sort} from 'bellajs';
let add1AndMult2 = pipe(add1, mult2);
add1AndMult2(3) // => 8
// because add 1 first, then multiple to 2 late => (3 + 1) * 2
sort([3, 1, 5, 2], 1); // => [ 1, 2, 3, 5 ]
sort([3, 1, 5, 2], -1); // => [ 5, 3, 2, 1 ]
```
## Note
Some parts of `bella` have been split to separate modules, including:
#### sortBy
- bella.stabilize: [stabilize.js](https://www.npmjs.com/package/stabilize.js)
- bella.scheduler: [bella-scheduler](https://www.npmjs.com/package/bella-scheduler)
- bella.detector: [device-detector](https://www.npmjs.com/package/device-detector)
```js
sortBy(Array a, String property, Number order)
```
Examples:
```js
import {sortBy} from 'bellajs';
const players = [
{
name: 'Jerome Nash',
age: 24
},
{
name: 'Jackson Valdez',
age: 21
},
{
name: 'Benjamin Cole',
age: 23
},
{
name: 'Manuel Delgado',
age: 33
},
{
name: 'Caleb McKinney',
age: 28
}
];
const result = sortBy('age', -1, players);
console.log(result_)
```
#### shuffle
Shuffle an array.
```js
shuffle(Array arr)
```
Examples:
```js
import {shuffle} from 'bellajs';
shuffle([1, 3, 8, 2, 5, 7]);
```
#### unique
```js
unique(Array a)
```
Examples:
```js
import {unique} from 'bellajs';
unique([1, 2, 3, 2, 3, 1, 5]); // => [ 1, 2, 3, 5 ]
```
## Test
```
```bash
git clone https://github.com/ndaidong/bellajs.git

@@ -451,0 +560,0 @@ cd bellajs

@@ -14,4 +14,4 @@ /**

export const curry = (fn) => {
let totalArguments = fn.length;
let next = (argumentLength, rest) => {
const totalArguments = fn.length;
const next = (argumentLength, rest) => {
if (argumentLength > 0) {

@@ -41,5 +41,5 @@ return (...args) => {

let copyObject = (o) => {
let oo = Object.create({});
for (let k in o) {
const copyObject = (o) => {
const oo = Object.create({});
for (const k in o) {
if (hasProperty(o, k)) {

@@ -52,3 +52,3 @@ oo[k] = clone(o[k]);

let copyArray = (a) => {
const copyArray = (a) => {
return [...a].map((e) => {

@@ -77,9 +77,9 @@ if (isArray(e)) {

export const copies = (source, dest, matched = false, excepts = []) => {
for (let k in source) {
for (const k in source) {
if (excepts.length > 0 && excepts.includes(k)) {
continue; // eslint-disable-line no-continue
}
if (!matched || matched && dest.hasOwnProperty(k)) {
let oa = source[k];
let ob = dest[k];
if (!matched || matched && hasProperty(dest, k)) {
const oa = source[k];
const ob = dest[k];
if (isObject(ob) && isObject(oa) || isArray(ob) && isArray(oa)) {

@@ -99,2 +99,25 @@ dest[k] = copies(oa, dest[k], matched, excepts);

export const sort = (fn, arr = []) => {
return [...arr].sort(fn);
};
export const sortBy = (key, order = 1, arr = []) => {
return sort(arr, (m, n) => {
return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0);
});
};
export const shuffle = (arr = []) => {
return sort(() => {
return Math.random() > 0.5;
}, [...arr]);
};
export const pick = (count = 1, arr = []) => {
const a = shuffle([...arr]);
const mc = Math.max(1, count);
const c = Math.min(mc, a.length - 1);
return a.splice(0, c);
};
export * from './utils/detection';

@@ -101,0 +124,0 @@ export * from './utils/equals';

@@ -8,7 +8,3 @@ // utils / date

import {
leftPad,
} from './string';
const PATTERN = 'D, M d, Y h:i:s A';

@@ -36,15 +32,15 @@ const WEEKDAYS = [

const tz = (() => {
let z = Math.abs(tzone / 60);
let sign = tzone < 0 ? '+' : '-';
return ['GMT', sign, leftPad(z, 4)].join('');
const z = Math.abs(tzone / 60);
const sign = tzone < 0 ? '+' : '-';
return ['GMT', sign, String(z).padStart(4, '0')].join('');
})();
let _num = (n) => {
const _num = (n) => {
return String(n < 10 ? '0' + n : n);
};
let _ord = (day) => {
const _ord = (day) => {
let s = day + ' ';
let x = s.charAt(s.length - 2);
const x = s.charAt(s.length - 2);
if (x === '1') {

@@ -62,4 +58,4 @@ s = 'st';

export let format = (input, output = PATTERN) => {
let d = isDate(input) ? input : new Date(input);
export const format = (input, output = PATTERN) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {

@@ -73,7 +69,7 @@ throw new Error('InvalidInput: Number or Date required.');

let vchar = /\.*\\?([a-z])/gi;
let meridiem = output.match(/(\.*)a{1}(\.*)*/i);
const vchar = /\.*\\?([a-z])/gi;
const meridiem = output.match(/(\.*)a{1}(\.*)*/i);
let wn = WEEKDAYS;
let mn = MONTHS;
const wn = WEEKDAYS;
const mn = MONTHS;

@@ -148,3 +144,3 @@ /*eslint-disable */

let _term = (t, s) => {
const _term = (t, s) => {
return f[t] ? f[t]() : s;

@@ -156,4 +152,4 @@ };

export let relativize = (input = time()) => {
let d = isDate(input) ? input : new Date(input);
export const relativize = (input = time()) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {

@@ -172,3 +168,3 @@ throw new Error('InvalidInput: Number or Date required.');

let units = null;
let conversions = {
const conversions = {
millisecond: 1,

@@ -182,3 +178,3 @@ second: 1000,

};
for (let key in conversions) {
for (const key in conversions) {
if (delta < conversions[key]) {

@@ -198,9 +194,9 @@ break;

export let utc = (input = time()) => {
let d = isDate(input) ? input : new Date(input);
export const utc = (input = time()) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {
throw new Error('InvalidInput: Number or Date required.');
}
let dMinutes = d.getMinutes();
let dClone = new Date(d);
const dMinutes = d.getMinutes();
const dClone = new Date(d);
dClone.setMinutes(dMinutes + tzone);

@@ -210,4 +206,4 @@ return `${format(dClone, 'D, j M Y h:i:s')} GMT+0000`;

export let local = (input = time()) => {
let d = isDate(input) ? input : new Date(input);
export const local = (input = time()) => {
const d = isDate(input) ? input : new Date(input);
if (!isDate(d)) {

@@ -214,0 +210,0 @@ throw new Error('InvalidInput: Number or Date required.');

@@ -52,3 +52,3 @@ // utils / detection

export const isLetter = (val) => {
let re = /^[a-z]+$/i;
const re = /^[a-z]+$/i;
return isString(val) && re.test(val);

@@ -58,3 +58,3 @@ };

export const isEmail = (val) => {
let re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return isString(val) && re.test(val);

@@ -61,0 +61,0 @@ };

@@ -37,5 +37,5 @@ // utils / equals

} else if (isObject(a) && isObject(b)) {
let as = [];
let bs = [];
for (let k1 in a) {
const as = [];
const bs = [];
for (const k1 in a) {
if (hasProperty(a, k1)) {

@@ -45,3 +45,3 @@ as.push(k1);

}
for (let k2 in b) {
for (const k2 in b) {
if (hasProperty(b, k2)) {

@@ -54,3 +54,3 @@ bs.push(k2);

}
for (let k in a) {
for (const k in a) {
if (!hasProperty(b, k) || !equals(a[k], b[k])) {

@@ -57,0 +57,0 @@ re = false;

@@ -5,3 +5,3 @@ // utils / random

export const random = (min, max) => {
export const randint = (min, max) => {
if (!min || min < 0) {

@@ -20,6 +20,6 @@ min = 0;

}
let offset = min;
let range = max - min + 1;
const offset = min;
const range = max - min + 1;
return Math.floor(Math.random() * range) + offset;
};
// utils / string
import {
isObject,
isArray,
isString,
isNumber,
isInteger,
hasProperty,
} from './detection';
import {random} from './random';
import {randint} from './random';
const MAX_STRING = 1 << 28; // eslint-disable-line no-bitwise
const toString = (input) => {
let s = isNumber(input) ? String(input) : input;
const s = isNumber(input) ? String(input) : input;
if (!isString(s)) {

@@ -24,24 +20,5 @@ throw new Error('InvalidInput: String required.');

export const encode = (s) => {
let x = toString(s);
return encodeURIComponent(x);
};
export const decode = (s) => {
let x = toString(s);
return decodeURIComponent(x.replace(/\+/g, ' '));
};
export const trim = (s, all = false) => {
let x = toString(s);
x = x.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
if (x && all) {
x = x.replace(/\r?\n|\r/g, ' ').replace(/\s\s+|\r/g, ' ');
}
return x;
};
export const truncate = (s, l) => {
let o = toString(s);
let t = l || 140;
const o = toString(s);
const t = l || 140;
if (o.length <= t) {

@@ -51,4 +28,4 @@ return o;

let x = o.substring(0, t);
let a = x.split(' ');
let b = a.length;
const a = x.split(' ');
const b = a.length;
let r = '';

@@ -69,8 +46,8 @@ if (b > 1) {

export const stripTags = (s) => {
let x = toString(s);
return trim(x.replace(/<.*?>/gi, ' ').replace(/\s\s+/g, ' '));
const x = toString(s);
return x.replace(/<.*?>/gi, ' ').replace(/\s\s+/g, ' ').trim();
};
export const escapeHTML = (s) => {
let x = toString(s);
const x = toString(s);
return x.replace(/&/g, '&amp;')

@@ -83,3 +60,3 @@ .replace(/</g, '&lt;')

export const unescapeHTML = (s) => {
let x = toString(s);
const x = toString(s);
return x.replace(/&quot;/g, '"')

@@ -101,5 +78,5 @@ .replace(/&lt;/g, '<')

export const ucwords = (s) => {
let x = toString(s);
let c = x.split(' ');
let a = [];
const x = toString(s);
const c = x.split(' ');
const a = [];
c.forEach((w) => {

@@ -111,25 +88,2 @@ a.push(ucfirst(w));

export const leftPad = (s, size = 2, pad = '0') => {
let x = toString(s);
return x.length >= size ? x : new Array(size - x.length + 1).join(pad) + x;
};
export const rightPad = (s, size = 2, pad = '0') => {
let x = toString(s);
return x.length >= size ? x : x + new Array(size - x.length + 1).join(pad);
};
export const repeat = (s, m) => {
let x = toString(s);
if (!isInteger(m) || m < 1) {
return x;
}
if (x.length * m >= MAX_STRING) {
throw new RangeError(`Repeat count must not overflow maximum string size.`);
}
let a = [];
a.length = m;
return a.fill(x, 0, m).join('');
};
export const replaceAll = (s, a, b) => {

@@ -146,3 +100,3 @@ let x = toString(s);

if (isString(a) && isString(b)) {
let aa = x.split(a);
const aa = x.split(a);
x = aa.join(b);

@@ -154,7 +108,7 @@ } else if (isArray(a) && isString(b)) {

} else if (isArray(a) && isArray(b) && a.length === b.length) {
let k = a.length;
const k = a.length;
if (k > 0) {
for (let i = 0; i < k; i++) {
let aaa = a[i];
let bb = b[i];
const aaa = a[i];
const bb = b[i];
x = replaceAll(x, aaa, bb);

@@ -170,3 +124,3 @@ }

let map = {
const map = {
a: 'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä',

@@ -190,9 +144,9 @@ A: 'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä',

let updateS = (ai, key) => {
const updateS = (ai, key) => {
x = replaceAll(x, ai, key);
};
for (let key in map) {
for (const key in map) {
if (hasProperty(map, key)) {
let a = map[key].split('|');
const a = map[key].split('|');
a.forEach((item) => {

@@ -206,7 +160,7 @@ return updateS(item, key);

export const createId = (leng, prefix = '') => {
let lc = 'abcdefghijklmnopqrstuvwxyz';
let uc = lc.toUpperCase();
let nb = '0123456789';
let cand = [
export const genid = (leng, prefix = '') => {
const lc = 'abcdefghijklmnopqrstuvwxyz';
const uc = lc.toUpperCase();
const nb = '0123456789';
const cand = [
lc,

@@ -219,7 +173,7 @@ uc,

let t = cand.length;
let ln = Math.max(leng || 32, prefix.length);
const t = cand.length;
const ln = Math.max(leng || 32, prefix.length);
let s = prefix;
while (s.length < ln) {
let k = random(0, t);
const k = randint(0, t);
s += cand.charAt(k) || '';

@@ -230,5 +184,5 @@ }

export const createAlias = (s, delimiter) => {
let x = trim(stripAccent(s));
let d = delimiter || '-';
export const slugify = (s, delimiter) => {
const x = stripAccent(s).trim();
const d = delimiter || '-';
return x.toLowerCase()

@@ -240,54 +194,1 @@ .replace(/\W+/g, ' ')

// Define bella.template
const compile = (tpl, data) => {
let ns = [];
let c = (s, ctx, namespace) => {
if (namespace) {
ns.push(namespace);
}
let a = [];
for (let k in ctx) {
if (hasProperty(ctx, k)) {
let v = ctx[k];
if (isNumber(v)) {
v = String(v);
}
if (isObject(v) || isArray(v)) {
a.push({
key: k,
data: v,
});
} else if (isString(v)) {
v = replaceAll(v, [
'{',
'}',
], [
'&#123;',
'&#125;',
]);
let cns = ns.concat([k]);
let r = new RegExp('{' + cns.join('.') + '}', 'gi');
s = s.replace(r, v);
}
}
}
if (a.length > 0) {
a.forEach((item) => {
s = c(s, item.data, item.key);
});
}
return trim(s, true);
};
if (data && (isString(data) || isObject(data) || isArray(data))) {
return c(tpl, data);
}
return tpl;
};
export const template = (tpl) => {
return {
compile: (data) => {
return compile(tpl, data);
},
};
};

@@ -16,4 +16,4 @@ /**

let s = fs.readFileSync(proFile, 'utf8');
let a = s.split('\n');
const s = fs.readFileSync(proFile, 'utf8');
const a = s.split('\n');
assert.ok(s.length > 0 && a.length > 5, 'Production file must be not empty');

@@ -33,11 +33,11 @@

let s = fs.readFileSync(devFile, 'utf8');
let a = s.split('\n');
const s = fs.readFileSync(devFile, 'utf8');
const a = s.split('\n');
assert.ok(s.length > 0 && a.length > 1, 'Development file must be not empty');
let cmt = a[0];
let pack = `${pkgFake.name}@${pkgFake.version}`;
const cmt = a[0];
const pack = `${pkgFake.name}@${pkgFake.version}`;
assert.ok(cmt.includes(pack), 'Package must be presented with name and version');
let author = `${pkgFake.author}`;
const author = `${pkgFake.author}`;
assert.ok(cmt.includes(author), 'Package author must be correct');
let license = `${pkgFake.license}`;
const license = `${pkgFake.license}`;
assert.ok(cmt.includes(license), 'Package license must be correct');

@@ -44,0 +44,0 @@

@@ -25,8 +25,8 @@ /**

let checkDetection = (bella) => {
const checkDetection = (bella) => {
// isElement
test('Testing .isElement(Anything) method:', (assert) => {
let doc = window.document;
let el = doc.createElement('DIV');
let ra = bella.isElement(el);
const doc = window.document;
const el = doc.createElement('DIV');
const ra = bella.isElement(el);
assert.ok(ra, 'Fragment must be an element.');

@@ -47,4 +47,4 @@

].forEach((item) => {
let r = bella.isElement(item);
let x = stringify(item);
const r = bella.isElement(item);
const x = stringify(item);
assert.error(r, `"${x}" must be not element.`);

@@ -68,4 +68,4 @@ });

].forEach((item) => {
let r = bella.isArray(item);
let x = stringify(item);
const r = bella.isArray(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be an array.`);

@@ -87,4 +87,4 @@ });

].forEach((item) => {
let r = bella.isArray(item);
let x = stringify(item);
const r = bella.isArray(item);
const x = stringify(item);
assert.error(r, `"${x}" must be not array.`);

@@ -103,4 +103,4 @@ });

].forEach((item) => {
let r = bella.isObject(item);
let x = stringify(item);
const r = bella.isObject(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be an object.`);

@@ -119,4 +119,4 @@ });

].forEach((item) => {
let r = bella.isObject(item);
let x = stringify(item);
const r = bella.isObject(item);
const x = stringify(item);
assert.error(r, `"${x}" must be not object.`);

@@ -137,4 +137,4 @@ });

].forEach((item) => {
let r = bella.isString(item);
let x = stringify(item);
const r = bella.isString(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be an string.`);

@@ -151,4 +151,4 @@ });

].forEach((item) => {
let r = bella.isString(item);
let x = stringify(item);
const r = bella.isString(item);
const x = stringify(item);
assert.error(r, `"${x}" must be not string.`);

@@ -166,4 +166,4 @@ });

].forEach((item) => {
let r = bella.isBoolean(item);
let x = stringify(item);
const r = bella.isBoolean(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be true.`);

@@ -185,4 +185,4 @@ });

].forEach((item) => {
let r = bella.isBoolean(item);
let x = stringify(item);
const r = bella.isBoolean(item);
const x = stringify(item);
assert.error(r, `"${x}" must be false.`);

@@ -196,4 +196,4 @@ });

[new Date()].forEach((item) => {
let r = bella.isDate(item);
let x = stringify(item);
const r = bella.isDate(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be date.`);

@@ -215,4 +215,4 @@ });

].forEach((item) => {
let r = bella.isDate(item);
let x = stringify(item);
const r = bella.isDate(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be date.`);

@@ -230,4 +230,4 @@ });

].forEach((item) => {
let r = bella.isEmail(item);
let x = stringify(item);
const r = bella.isEmail(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be email.`);

@@ -245,4 +245,4 @@ });

].forEach((item) => {
let r = bella.isEmail(item);
let x = stringify(item);
const r = bella.isEmail(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be email.`);

@@ -264,4 +264,4 @@ });

].forEach((item) => {
let r = bella.isEmpty(item);
let x = stringify(item);
const r = bella.isEmpty(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be empty.`);

@@ -280,4 +280,4 @@ });

].forEach((item) => {
let r = bella.isEmpty(item);
let x = stringify(item);
const r = bella.isEmpty(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be empty.`);

@@ -295,4 +295,4 @@ });

].forEach((item) => {
let r = bella.isFunction(item);
let x = stringify(item);
const r = bella.isFunction(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be function.`);

@@ -316,4 +316,4 @@ });

].forEach((item) => {
let r = bella.isFunction(item);
let x = stringify(item);
const r = bella.isFunction(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be function.`);

@@ -332,4 +332,4 @@ });

].forEach((item) => {
let r = bella.isInteger(item);
let x = stringify(item);
const r = bella.isInteger(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be integer.`);

@@ -348,4 +348,4 @@ });

].forEach((item) => {
let r = bella.isInteger(item);
let x = stringify(item);
const r = bella.isInteger(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be integer.`);

@@ -364,4 +364,4 @@ });

].forEach((item) => {
let r = bella.isLetter(item);
let x = stringify(item);
const r = bella.isLetter(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be letter.`);

@@ -385,4 +385,4 @@ });

].forEach((item) => {
let r = bella.isLetter(item);
let x = stringify(item);
const r = bella.isLetter(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be letter.`);

@@ -404,4 +404,4 @@ });

].forEach((item) => {
let r = bella.isNumber(item);
let x = stringify(item);
const r = bella.isNumber(item);
const x = stringify(item);
assert.ok(r, `"${x}" must be number.`);

@@ -418,4 +418,4 @@ });

].forEach((item) => {
let r = bella.isNumber(item);
let x = stringify(item);
const r = bella.isNumber(item);
const x = stringify(item);
assert.error(r, `"${x}" must not be number.`);

@@ -428,3 +428,3 @@ });

test('Tesing .hasProperty(Object o, String propertyName) method:', (assert) => {
let sample = {
const sample = {
name: 'lemond',

@@ -437,3 +437,3 @@ age: 15,

let props = [
const props = [
'name',

@@ -446,7 +446,7 @@ 'age',

for (let i = 0; i < props.length; i++) {
let k = props[i];
const k = props[i];
assert.ok(bella.hasProperty(sample, k), `"${k}" must be recognized.`);
}
let fails = [
const fails = [
'class',

@@ -459,3 +459,3 @@ 'year',

for (let i = 0; i < fails.length; i++) {
let k = fails[i];
const k = fails[i];
assert.error(bella.hasProperty(sample, k), `"${k}" must be unrecognized.`);

@@ -471,4 +471,4 @@ }

test('Tesing .equals(Anything a, Anything b) method:', (assert) => {
let t = new Date();
let a1 = [
const t = new Date();
const a1 = [
{},

@@ -491,3 +491,3 @@ [],

];
let b1 = [
const b1 = [
{},

@@ -512,7 +512,7 @@ [],

for (let i = 0; i < a1.length; i++) {
let a = a1[i];
let b = b1[i];
let result = bella.equals(a, b);
let as = stringify(a);
let bs = stringify(b);
const a = a1[i];
const b = b1[i];
const result = bella.equals(a, b);
const as = stringify(a);
const bs = stringify(b);
assert.ok(result, `"${as}" must be equal to ${bs}.`);

@@ -522,5 +522,5 @@ }

let at = new Date();
let bt = new Date(at.getTime() - 1000);
let a2 = [
const at = new Date();
const bt = new Date(at.getTime() - 1000);
const a2 = [
{x: 5},

@@ -547,3 +547,3 @@ [

];
let b2 = [
const b2 = [
{},

@@ -568,7 +568,7 @@ ['ab'],

for (let i = 0; i < a2.length; i++) {
let a = a2[i];
let b = b2[i];
let result = bella.equals(a, b);
let as = stringify(a);
let bs = stringify(b);
const a = a2[i];
const b = b2[i];
const result = bella.equals(a, b);
const as = stringify(a);
const bs = stringify(b);
assert.error(result, `"${as}" must be not equal to ${bs}.`);

@@ -575,0 +575,0 @@ }

@@ -10,14 +10,7 @@ /**

let checkStringMethods = (bella) => {
const checkStringMethods = (bella) => {
test('With well-format string input:', (assert) => {
let methods = [
'encode',
'decode',
'repeat',
const methods = [
'ucfirst',
'ucwords',
'leftPad',
'rightPad',
'createAlias',
'trim',
'truncate',

@@ -29,2 +22,3 @@ 'stripTags',

'replaceAll',
'slugify',
];

@@ -39,68 +33,11 @@

test('With invalid string input:', (assert) => {
assert.throws(() => {
bella.repeat(new Function(), 5); // eslint-disable-line
}, new Error('InvalidInput: String required.'), 'It must throw an error.');
assert.end();
});
// repeat
test('Testing .repeat(String s, Number times) method', (assert) => {
let x = 'hi';
let a = bella.repeat(x, 5);
let e = 'hihihihihi';
assert.deepEquals(a, e, `bella.repeat(x, 5) must return "${e}"`);
assert.deepEquals(bella.repeat(x), x, `bella.repeat(x) must return "${e}"`);
assert.throws(() => {
bella.repeat(x, 268435456);
},
new RangeError(`Repeat count must not overflow maximum string size.`),
`bella.repeat(x, 268435456) must return RangeError`);
assert.end();
});
// encode
test('Testing .encode(String s) method', (assert) => {
let x = 'Hello world';
let a = bella.encode(x);
let e = 'Hello%20world';
assert.deepEquals(a, e, `bella.encode(x) must return ${e}`);
assert.end();
});
// decode
test('Testing .decode(String s) method', (assert) => {
let x = 'Hello%20world';
let a = bella.decode(x);
let e = 'Hello world';
assert.deepEquals(a, e, `bella.decode(x) must return ${e}`);
assert.end();
});
// trim
test('Testing .trim(String s) method', (assert) => {
let x = ' Hello world. This is my dog. ';
let a1 = bella.trim(x);
let e1 = 'Hello world. This is my dog.';
assert.deepEquals(a1, e1, `bella.trim(x) must return ${e1}`);
let a2 = bella.trim(x, true);
let e2 = 'Hello world. This is my dog.';
assert.deepEquals(a2, e2, `bella.trim(x, true) must return ${e2}`);
assert.end();
});
// truncate
test('Testing .truncate(String s) method', (assert) => {
let x = 'If a property is non-configurable, its writable attribute can only be changed to false.';
let a = bella.truncate(x, 60);
let e = 'If a property is non-configurable, its writable attribute...';
const x = 'If a property is non-configurable, its writable attribute can only be changed to false.';
const a = bella.truncate(x, 60);
const e = 'If a property is non-configurable, its writable attribute...';
assert.deepEquals(a, e, `bella.truncate('${x}', 60) must return "${e}"`);
assert.deepEquals(bella.truncate(x, 200), x, `bella.truncate('${x}', 200) must return "${x}"`);
let x1 = [
const x1 = [
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',

@@ -112,4 +49,4 @@ 'Lorem Ipsum has been the industry\'s standard dummy text ever since',

let a1 = bella.truncate(x1);
let e1 = [
const a1 = bella.truncate(x1);
const e1 = [
'Lorem Ipsum is simply dummy text of the printing and typesetting',

@@ -122,9 +59,9 @@ 'industry. Lorem Ipsum has been the industry\'s standard dummy text ever...',

let x2 = 'uyyiyirwqyiyiyrihklhkjhskdjfhkahfiusayiyfiudyiyqwiyriuqyiouroiuyi';
let a2 = bella.truncate(x2, 20);
let e2 = 'uyyiyirwqyiyiyrih...';
const x2 = 'uyyiyirwqyiyiyrihklhkjhskdjfhkahfiusayiyfiudyiyqwiyriuqyiouroiuyi';
const a2 = bella.truncate(x2, 20);
const e2 = 'uyyiyirwqyiyiyrih...';
assert.deepEquals(a2, e2, `bella.truncate('${x2}', 20) must return "${e2}"`);
let x3 = 'Lorem Ipsum is simply dummy text';
let a3 = bella.truncate(x3, 120);
const x3 = 'Lorem Ipsum is simply dummy text';
const a3 = bella.truncate(x3, 120);
assert.deepEquals(a3, x3, `bella.truncate('${x3}', 120) must return "${a3}"`);

@@ -137,5 +74,5 @@

test('Testing .stripTags(String s) method', (assert) => {
let x = '<a>Hello <b>world</b></a>';
let a1 = bella.stripTags(x);
let e1 = 'Hello world';
const x = '<a>Hello <b>world</b></a>';
const a1 = bella.stripTags(x);
const e1 = 'Hello world';
assert.deepEquals(a1, e1, `bella.stripTags('${x}') must return ${e1}`);

@@ -149,5 +86,5 @@

test('Testing .escapeHTML(String s) method', (assert) => {
let x = '<a>Hello <b>world</b></a>';
let a1 = bella.escapeHTML(x);
let e1 = '&lt;a&gt;Hello &lt;b&gt;world&lt;/b&gt;&lt;/a&gt;';
const x = '<a>Hello <b>world</b></a>';
const a1 = bella.escapeHTML(x);
const e1 = '&lt;a&gt;Hello &lt;b&gt;world&lt;/b&gt;&lt;/a&gt;';
assert.deepEquals(a1, e1, `bella.escapeHTML('${x}') must return ${e1}`);

@@ -159,5 +96,5 @@ assert.end();

test('Testing .unescapeHTML(String s) method', (assert) => {
let x = '&lt;a&gt;Hello &lt;b&gt;world&lt;/b&gt;&lt;/a&gt;';
let a1 = bella.unescapeHTML(x);
let e1 = '<a>Hello <b>world</b></a>';
const x = '&lt;a&gt;Hello &lt;b&gt;world&lt;/b&gt;&lt;/a&gt;';
const a1 = bella.unescapeHTML(x);
const e1 = '<a>Hello <b>world</b></a>';
assert.deepEquals(a1, e1, `bella.unescapeHTML('${x}') must return ${e1}`);

@@ -169,10 +106,10 @@ assert.end();

test('Testing .ucfirst(String s) method', (assert) => {
let x1 = 'HElLo wOrLd';
let a1 = bella.ucfirst(x1);
let e1 = 'Hello world';
const x1 = 'HElLo wOrLd';
const a1 = bella.ucfirst(x1);
const e1 = 'Hello world';
assert.deepEquals(a1, e1, `bella.ucfirst('${x1}') must return ${e1}`);
let x2 = 'a';
let a2 = bella.ucfirst(x2);
let e2 = 'A';
const x2 = 'a';
const a2 = bella.ucfirst(x2);
const e2 = 'A';
assert.deepEquals(a2, e2, `bella.ucfirst('${x2}') must return ${e2}`);

@@ -185,5 +122,5 @@

test('Testing .ucwords(String s) method', (assert) => {
let x = 'HElLo wOrLd';
let a1 = bella.ucwords(x);
let e1 = 'Hello World';
const x = 'HElLo wOrLd';
const a1 = bella.ucwords(x);
const e1 = 'Hello World';
assert.deepEquals(a1, e1, `bella.ucwords('${x}') must return ${e1}`);

@@ -193,89 +130,5 @@ assert.end();

// leftPad
test('Testing .leftPad(String s, String size, String pad) method', (assert) => {
let data = [
{
s: 7,
limit: 4,
pad: '0',
expect: '0007',
},
{
s: 123456,
limit: 5,
pad: '0',
expect: '123456',
},
{
s: 123456,
limit: 6,
pad: '0',
expect: '123456',
},
{
s: 123456,
limit: 7,
pad: '0',
expect: '0123456',
},
];
data.forEach((item) => {
let sample = item.s;
let limit = item.limit;
let pad = item.pad;
let expect = item.expect;
let result = bella.leftPad(sample, limit, pad);
assert.deepEquals(result, expect, `bella.leftPad('${sample}', ${limit}, ${pad}) must return ${expect}`);
});
assert.deepEquals(bella.leftPad(''), '00', 'bella.leftPad(\'\') must return "00"');
assert.end();
});
// rightPad
test('Testing .rightPad(String s, String size, String pad) method', (assert) => {
let data = [
{
s: 7,
limit: 4,
pad: '0',
expect: '7000',
},
{
s: 123456,
limit: 5,
pad: '0',
expect: '123456',
},
{
s: 123456,
limit: 6,
pad: '0',
expect: '123456',
},
{
s: 123456,
limit: 7,
pad: '0',
expect: '1234560',
},
];
data.forEach((item) => {
let sample = item.s;
let limit = item.limit;
let pad = item.pad;
let expect = item.expect;
let result = bella.rightPad(sample, limit, pad);
assert.deepEquals(result, expect, `bella.rightPad('${sample}', ${limit}, ${pad}) must return ${expect}`);
});
assert.deepEquals(bella.rightPad(''), '00', 'bella.rightPad(\'\') must return "00"');
assert.end();
});
// replaceAll
test('Testing .replaceAll(String s, String find, String replace) method', (assert) => {
let data = [
const data = [
{

@@ -357,9 +210,9 @@ input: {

data.forEach((useCase) => {
let input = useCase.input;
let a = input.a;
let b = input.b;
let c = input.c;
let e = useCase.expectation;
const input = useCase.input;
const a = input.a;
const b = input.b;
const c = input.c;
const e = useCase.expectation;
let result = bella.replaceAll(a, b, c);
const result = bella.replaceAll(a, b, c);
assert.deepEquals(result, e, `bella.replaceAll('${a}', ${b}, ${c}) must return ${e}`);

@@ -373,10 +226,10 @@ });

test('Testing .stripAccent(String s) method', (assert) => {
let x1 = 'Sur l\'année 2015 - ủ Ù ỹ Ỹ';
let a1 = bella.stripAccent(x1);
let e1 = 'Sur l\'annee 2015 - u U y Y';
const x1 = 'Sur l\'année 2015 - ủ Ù ỹ Ỹ';
const a1 = bella.stripAccent(x1);
const e1 = 'Sur l\'annee 2015 - u U y Y';
assert.deepEquals(a1, e1, `bella.stripAccent('${x1}') must return ${e1}`);
let x2 = 12897;
let a2 = bella.stripAccent(x2);
let e2 = '12897';
const x2 = 12897;
const a2 = bella.stripAccent(x2);
const e2 = '12897';
assert.deepEquals(a2, e2, `bella.stripAccent('${x2}') must return ${e2}`);

@@ -387,8 +240,8 @@

// createAlias
test('Testing .createAlias(String s) method', (assert) => {
let x = 'Sur l\'année 2015';
let a1 = bella.createAlias(x);
let e1 = 'sur-l-annee-2015';
assert.deepEquals(a1, e1, `bella.createAlias('${x}') must return ${e1}`);
// slugify
test('Testing .slugify(String s) method', (assert) => {
const x = 'Sur l\'année 2015';
const a1 = bella.slugify(x);
const e1 = 'sur-l-annee-2015';
assert.deepEquals(a1, e1, `bella.slugify('${x}') must return ${e1}`);

@@ -395,0 +248,0 @@ assert.end();

@@ -11,6 +11,6 @@ /**

// clone
let checkClone = (bella) => {
const checkClone = (bella) => {
test('Testing .clone(Object target) method', (assert) => {
assert.comment('Clone object');
let a = {
const a = {
level: 4,

@@ -28,3 +28,3 @@ IQ: 140,

let ca = bella.clone(a);
const ca = bella.clone(a);
assert.ok(bella.hasProperty(ca, 'level'), 'ca must have level');

@@ -38,3 +38,3 @@ assert.ok(bella.hasProperty(ca, 'IQ'), 'ca must have IQ');

assert.comment('Clone array');
let b = [
const b = [
1,

@@ -62,3 +62,3 @@ 5,

let cb = bella.clone(b);
const cb = bella.clone(b);
assert.ok(b.length === cb.length, 'cb.length === b.length');

@@ -65,0 +65,0 @@ assert.ok(bella.equals(b, cb), 'cb === b');

@@ -10,37 +10,37 @@ /**

let checkCompose = (bella) => {
let {compose} = bella;
const checkCompose = (bella) => {
const {compose} = bella;
let f1 = (name) => {
const f1 = (name) => {
return `f1 ${name}`;
};
let f2 = (name) => {
const f2 = (name) => {
return `f2 ${name}`;
};
let f3 = (name) => {
const f3 = (name) => {
return `f3 ${name}`;
};
let addDashes = compose(f1, f2, f3);
const addDashes = compose(f1, f2, f3);
let add3 = (num) => {
const add3 = (num) => {
return num + 3;
};
let mul6 = (num) => {
const mul6 = (num) => {
return num * 6;
};
let div2 = (num) => {
const div2 = (num) => {
return num / 2;
};
let sub5 = (num) => {
const sub5 = (num) => {
return num - 5;
};
let calculate = compose(sub5, div2, mul6, add3);
const calculate = compose(sub5, div2, mul6, add3);
test('Testing .compose() method', (assert) => {
let ex = 'f1 f2 f3 Alice';
const ex = 'f1 f2 f3 Alice';
assert.deepEquals(addDashes('Alice'), ex, `addDashes('Alice') must return "${ex}"`);

@@ -47,0 +47,0 @@

@@ -11,5 +11,5 @@ /**

// copies
let checkCopies = (bella) => {
const checkCopies = (bella) => {
test('Testing .copies(Object target) method', (assert) => {
let a = {
const a = {
name: 'Toto',

@@ -22,3 +22,3 @@ age: 30,

};
let b = {
const b = {
level: 4,

@@ -46,3 +46,3 @@ IQ: 140,

let c = {
const c = {
name: 'Kiwi',

@@ -52,3 +52,3 @@ age: 16,

};
let d = {
const d = {
name: 'Aline',

@@ -55,0 +55,0 @@ age: 20,

@@ -10,9 +10,9 @@ /**

let checkCurry = (bella) => {
let curry = bella.curry;
let isGreaterThan = curry((limit, value) => {
const checkCurry = (bella) => {
const curry = bella.curry;
const isGreaterThan = curry((limit, value) => {
return value > limit;
});
let sum3 = curry((a, b, c) => {
const sum3 = curry((a, b, c) => {
return a + b + c;

@@ -24,3 +24,3 @@ });

assert.deepEquals(isGreaterThan(30)(20), false, `isGreaterThan(30)(20) must return false`);
let greaterThanTen = isGreaterThan(10);
const greaterThanTen = isGreaterThan(10);
assert.deepEquals(greaterThanTen(20), true, `greaterThanTen(20) must return true`);

@@ -27,0 +27,0 @@

@@ -15,3 +15,4 @@ /**

let isSameTimes = (t1, t2) => {
const isSameTimes = (t1, t2) => {
return Math.abs(t1 - t2) < 5;

@@ -21,3 +22,3 @@ };

const checkDateMethods = (date) => {
let {
const {
format,

@@ -30,4 +31,4 @@ relativize,

test('Testing .time() method', (assert) => {
let t = (new Date()).getTime();
let b = time();
const t = (new Date()).getTime();
const b = time();
assert.ok(isSameTimes(t, b), 'Time must be the same');

@@ -38,4 +39,4 @@ assert.end();

test('Testing .date() method', (assert) => {
let t = new Date();
let b = now();
const t = new Date();
const b = now();
assert.ok(isSameTimes(t.getTime(), b.getTime()), 'Date must be the same');

@@ -46,4 +47,4 @@ assert.end();

test('With invalid date time input:', (assert) => {
let check = (t) => {
let err = new Error('InvalidInput: Number or Date required.');
const check = (t) => {
const err = new Error('InvalidInput: Number or Date required.');
assert.throws(() => {

@@ -68,5 +69,5 @@ console.log(format(t)); // eslint-disable-line no-console

test('Testing .format(Number timestamp, String pattern) method:', (assert) => {
let atime = 1455784100752;
const atime = 1455784100752;
let samples = [
const samples = [
{ouput: 'Y/m/d h:i:s', expectation: '2016/02/18 15:28:20'},

@@ -98,6 +99,6 @@ {ouput: 'Y/m/d h:i:s A', expectation: '2016/02/18 03:28:20 PM'},

samples.forEach((sample) => {
let tpl = sample.ouput;
let exp = sample.expectation;
let input = sample.input || atime;
let result = format(input, tpl);
const tpl = sample.ouput;
const exp = sample.expectation;
const input = sample.input || atime;
const result = format(input, tpl);
assert.deepEqual(result, exp, `"${tpl}" must return ${exp}`);

@@ -114,9 +115,9 @@ });

test('Testing .relativize(Number timestamp) method:', (assert) => {
let t = time();
let clock = sinon.useFakeTimers(t);
const t = time();
const clock = sinon.useFakeTimers(t);
// Just now
setTimeout(() => {
let r = relativize(t);
let e = 'Just now';
const r = relativize(t);
const e = 'Just now';
assert.deepEqual(r, e, `At the begin it must return ${e}`);

@@ -127,4 +128,4 @@ }, 0);

setTimeout(() => {
let r = relativize(t);
let e = '3 seconds ago';
const r = relativize(t);
const e = '3 seconds ago';
assert.deepEqual(r, e, `After 3 seconds must return ${e}`);

@@ -135,4 +136,4 @@ }, 3000);

setTimeout(() => {
let r = relativize(t);
let e = '2 minutes ago';
const r = relativize(t);
const e = '2 minutes ago';
assert.deepEqual(r, e, `Next 2 minutes must return ${e}`);

@@ -143,4 +144,4 @@ }, 2 * 6e4);

setTimeout(() => {
let r = relativize(t);
let e = '6 hours ago';
const r = relativize(t);
const e = '6 hours ago';
assert.deepEqual(r, e, `Next 6 hours must return ${e}`);

@@ -151,4 +152,4 @@ }, 6 * 60 * 6e4);

setTimeout(() => {
let r = relativize(t);
let e = '2 days ago';
const r = relativize(t);
const e = '2 days ago';
assert.deepEqual(r, e, `Next 2 days must return ${e}`);

@@ -167,5 +168,5 @@ }, 2 * 24 * 60 * 6e4);

test('Testing .utc(Number timestamp) method:', (assert) => {
let t = 1455784100752;
let r = utc(t);
let e = 'Thu, 18 Feb 2016 08:28:20 GMT+0000';
const t = 1455784100752;
const r = utc(t);
const e = 'Thu, 18 Feb 2016 08:28:20 GMT+0000';
assert.deepEqual(r, e, `.utc(${t}) must return ${e}`);

@@ -181,5 +182,5 @@

test('Testing .local(Number timestamp) method:', (assert) => {
let t = 1455784100000;
let r = local(t);
let e = 'Thu, 18 Feb 2016 15:28:20 GMT+0007';
const t = 1455784100000;
const r = local(t);
const e = 'Thu, 18 Feb 2016 15:28:20 GMT+0007';
assert.deepEqual(r, e, `.local(${t}) must return ${e}`);

@@ -186,0 +187,0 @@

@@ -11,7 +11,7 @@ /**

// md5
let checkMD5 = (bella) => {
const checkMD5 = (bella) => {
test('Testing .md5() method', (assert) => {
let arr = [];
const arr = [];
while (arr.length < 10) {
let k = bella.md5();
const k = bella.md5();
arr.push(k);

@@ -18,0 +18,0 @@ assert.deepEquals(k.length, 32, 'Returned value must be 32 chars');

@@ -10,37 +10,37 @@ /**

let checkPipe = (bella) => {
let {pipe} = bella;
const checkPipe = (bella) => {
const {pipe} = bella;
let f1 = (name) => {
const f1 = (name) => {
return `f1 ${name}`;
};
let f2 = (name) => {
const f2 = (name) => {
return `f2 ${name}`;
};
let f3 = (name) => {
const f3 = (name) => {
return `f3 ${name}`;
};
let addDashes = pipe(f1, f2, f3);
const addDashes = pipe(f1, f2, f3);
let add3 = (num) => {
const add3 = (num) => {
return num + 3;
};
let mul6 = (num) => {
const mul6 = (num) => {
return num * 6;
};
let div2 = (num) => {
const div2 = (num) => {
return num / 2;
};
let sub5 = (num) => {
const sub5 = (num) => {
return num - 5;
};
let calculate = pipe(add3, mul6, div2, sub5);
const calculate = pipe(add3, mul6, div2, sub5);
test('Testing .pipe() method', (assert) => {
let ex = 'f3 f2 f1 Alice';
const ex = 'f3 f2 f1 Alice';
assert.deepEquals(addDashes('Alice'), ex, `addDashes('Alice') must return "${ex}"`);

@@ -47,0 +47,0 @@

@@ -12,3 +12,3 @@ /**

// random
let checkRandom = (bella) => {
const checkRandom = (bella) => {
test('Testing .random() method', (assert) => {

@@ -19,3 +19,3 @@ const LIMIT = 5;

while (i1 < LIMIT) {
let a = bella.random(50, 70);
const a = bella.randint(50, 70);
assert.ok(is.number(a), `"${a}" must be number.`);

@@ -28,3 +28,3 @@ assert.ok(a >= 50 && a <= 70, 'bella.random(50, 70): 50 <= R <= 70');

while (i2 < LIMIT) {
let a = bella.random(70, 50);
const a = bella.randint(70, 50);
assert.ok(is.number(a), `"${a}" must be number.`);

@@ -37,3 +37,3 @@ assert.ok(a >= 50 && a <= 70, 'bella.random(70, 50): 50 <= R <= 70');

while (i3 < LIMIT) {
let a = bella.random(50);
const a = bella.randint(50);
assert.ok(is.number(a), `"${a}" must be number.`);

@@ -46,3 +46,3 @@ assert.ok(a >= 50 && a <= 9007199254740991, 'bella.random(50): 50 <= R <= 9007199254740991');

while (i4 < LIMIT) {
let a = bella.random();
const a = bella.randint();
assert.ok(is.number(a), `"${a}" must be number.`);

@@ -53,4 +53,21 @@ assert.ok(a >= 0 && a <= 9007199254740991, 'With no parameter, 0 <= R <= 9007199254740991.');

let x = bella.random(70, 70);
const x = bella.randint(70, 70);
assert.equals(70, x, 'bella.random(70, 70): R must be 70');
assert.comment('Test shuffle() method');
const arr = [1, 4, 9, 18, 55, 64, 2, 7, 33, 8, 11, 44, 99, 15, 35, 64, 12, 27, 13, 28];
const arrs = bella.shuffle(arr);
assert.ok(bella.isArray(arrs), 'Result of shuffle must be an array');
assert.ok(arrs.length === arr.length, 'Shuffled array must has same length as original');
assert.ok(arrs !== arr, 'Shuffled array must be different from original');
assert.comment('Test pick() method');
const arr2 = [1, 4, 9, 18, 55, 64, 2, 7, 33, 8, 11, 44, 99, 15, 35, 64, 12, 27, 13, 28];
const arrs2 = bella.pick(5, arr2);
const arrs3 = bella.pick(5, arr2);
assert.ok(bella.isArray(arrs2), 'Result of pick must be an array');
assert.ok(arrs2.length === 5, 'Picked array must has same length as request');
assert.ok(arrs3.length === 5, 'Picked array must has same length as request');
assert.ok(arrs3 !== arrs2, 'Picked array must be different from others');
assert.end();

@@ -57,0 +74,0 @@ });

@@ -11,7 +11,7 @@ /**

// unique
let checkUnique = (bella) => {
const checkUnique = (bella) => {
test('Testing .unique() method', (assert) => {
let arr = [1, 1, 2, 2, 3, 4, 5, 5, 6, 3, 5, 4];
const arr = [1, 1, 2, 2, 3, 4, 5, 5, 6, 3, 5, 4];
let uniqArr = bella.unique(arr);
const uniqArr = bella.unique(arr);
assert.deepEquals(uniqArr.length, 6, 'Unique version must have 6 items');

@@ -18,0 +18,0 @@

@@ -20,7 +20,6 @@ /**

'string',
'template',
];
dirs.forEach((dir) => {
let where = './test/specs/' + dir;
const where = './test/specs/' + dir;
if (existsSync(where)) {

@@ -27,0 +26,0 @@ readdirSync(where).forEach((file) => {

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