Comparing version 9.3.0 to 10.0.0
/** | ||
* bellajs@9.3.0 | ||
* built on: Sat, 01 May 2021 14:55:33 GMT | ||
* bellajs@10.0.0 | ||
* built on: Thu, 02 Dec 2021 10:57:05 GMT | ||
* repository: https://github.com/ndaidong/bellajs | ||
@@ -12,110 +12,97 @@ * maintainer: @ndaidong | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bella = {})); | ||
}(this, (function (exports) { | ||
})(this, (function (exports) { | ||
const ob2Str = (val) => { | ||
return {}.toString.call(val); | ||
return {}.toString.call(val) | ||
}; | ||
const isInteger = (val) => { | ||
return Number.isInteger(val); | ||
return Number.isInteger(val) | ||
}; | ||
const isArray = (val) => { | ||
return Array.isArray(val); | ||
return Array.isArray(val) | ||
}; | ||
const isString = (val) => { | ||
return String(val) === val; | ||
return String(val) === val | ||
}; | ||
const isNumber = (val) => { | ||
return Number(val) === val; | ||
return Number(val) === val | ||
}; | ||
const isBoolean = (val) => { | ||
return Boolean(val) === val; | ||
return Boolean(val) === val | ||
}; | ||
const isNull = (val) => { | ||
return ob2Str(val) === '[object Null]'; | ||
return ob2Str(val) === '[object Null]' | ||
}; | ||
const isUndefined = (val) => { | ||
return ob2Str(val) === '[object Undefined]'; | ||
return ob2Str(val) === '[object Undefined]' | ||
}; | ||
const isNil = (val) => { | ||
return isUndefined(val) || isNull(val) | ||
}; | ||
const isFunction = (val) => { | ||
return ob2Str(val) === '[object Function]'; | ||
return ob2Str(val) === '[object Function]' | ||
}; | ||
const isObject = (val) => { | ||
return ob2Str(val) === '[object Object]' && !isArray(val); | ||
return ob2Str(val) === '[object Object]' && !isArray(val) | ||
}; | ||
const isDate = (val) => { | ||
return val instanceof Date && !isNaN(val.valueOf()); | ||
return val instanceof Date && !isNaN(val.valueOf()) | ||
}; | ||
const isElement = (v) => { | ||
return ob2Str(v).match(/^\[object HTML\w*Element]$/) !== null; | ||
return ob2Str(v).match(/^\[object HTML\w*Element]$/) !== null | ||
}; | ||
const isLetter = (val) => { | ||
const re = /^[a-z]+$/i; | ||
return isString(val) && re.test(val); | ||
return isString(val) && re.test(val) | ||
}; | ||
const isEmail = (val) => { | ||
const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | ||
return isString(val) && re.test(val); | ||
return isString(val) && re.test(val) | ||
}; | ||
const isNil = (val) => { | ||
return isUndefined(val) || isNull(val); | ||
}; | ||
const isEmpty = (val) => { | ||
return !val || isNil(val) || | ||
isString(val) && val === '' || | ||
isArray(val) && val.length === 0 || | ||
isObject(val) && Object.keys(val).length === 0; | ||
(isString(val) && val === '') || | ||
(isArray(val) && val.length === 0) || | ||
(isObject(val) && Object.keys(val).length === 0) | ||
}; | ||
const hasProperty = (ob, k) => { | ||
if (!ob || !k) { | ||
return false; | ||
return false | ||
} | ||
return Object.prototype.hasOwnProperty.call(ob, k); | ||
return Object.prototype.hasOwnProperty.call(ob, k) | ||
}; | ||
const equals = (a, b) => { | ||
let re = true; | ||
if (isEmpty(a) && isEmpty(b)) { | ||
return true; | ||
return true | ||
} | ||
if (isDate(a) && isDate(b)) { | ||
return a.getTime() === b.getTime(); | ||
return a.getTime() === b.getTime() | ||
} | ||
if (isNumber(a) && isNumber(b) || isString(a) && isString(b)) { | ||
return a === b; | ||
} | ||
if (isArray(a) && isArray(b)) { | ||
if (a.length !== b.length) { | ||
return false; | ||
return false | ||
} | ||
if (a.length > 0) { | ||
for (let i = 0, l = a.length; i < l; i++) { | ||
if (!equals(a[i], b[i])) { | ||
re = false; | ||
break; | ||
} | ||
let re = true; | ||
for (let i = 0; i < a.length; i++) { | ||
if (!equals(a[i], b[i])) { | ||
re = false; | ||
break | ||
} | ||
} | ||
} else if (isObject(a) && isObject(b)) { | ||
const as = []; | ||
const bs = []; | ||
for (const k1 in a) { | ||
if (hasProperty(a, k1)) { | ||
as.push(k1); | ||
} | ||
return re | ||
} | ||
if (isObject(a) && isObject(b)) { | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false | ||
} | ||
for (const k2 in b) { | ||
if (hasProperty(b, k2)) { | ||
bs.push(k2); | ||
} | ||
} | ||
if (as.length !== bs.length) { | ||
return false; | ||
} | ||
let re = true; | ||
for (const k in a) { | ||
if (!hasProperty(b, k) || !equals(a[k], b[k])) { | ||
re = false; | ||
break; | ||
break | ||
} | ||
} | ||
return re | ||
} | ||
return re; | ||
return a === b | ||
}; | ||
@@ -132,3 +119,3 @@ | ||
if (min === max) { | ||
return max; | ||
return max | ||
} | ||
@@ -141,3 +128,3 @@ if (min > max) { | ||
const range = max - min + 1; | ||
return Math.floor(Math.random() * range) + offset; | ||
return Math.floor(Math.random() * range) + offset | ||
}; | ||
@@ -148,5 +135,5 @@ | ||
if (!isString(s)) { | ||
throw new Error('InvalidInput: String required.'); | ||
throw new Error('InvalidInput: String required.') | ||
} | ||
return s; | ||
return s | ||
}; | ||
@@ -157,3 +144,3 @@ const truncate = (s, l) => { | ||
if (o.length <= t) { | ||
return o; | ||
return o | ||
} | ||
@@ -174,3 +161,3 @@ let x = o.substring(0, t); | ||
} | ||
return r; | ||
return r | ||
}; | ||
@@ -181,3 +168,3 @@ const stripTags = (s) => { | ||
.replace(/\s\s+/g, ' ') | ||
.trim(); | ||
.trim() | ||
}; | ||
@@ -189,3 +176,3 @@ const escapeHTML = (s) => { | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
.replace(/"/g, '"') | ||
}; | ||
@@ -197,12 +184,12 @@ const unescapeHTML = (s) => { | ||
.replace(/>/g, '>') | ||
.replace(/&/g, '&'); | ||
.replace(/&/g, '&') | ||
}; | ||
const ucfirst = (s) => { | ||
const x = toString(s).toLowerCase(); | ||
return x.length > 1 ? x.charAt(0).toUpperCase() + x.slice(1) : x.toUpperCase(); | ||
return x.length > 1 ? x.charAt(0).toUpperCase() + x.slice(1) : x.toUpperCase() | ||
}; | ||
const ucwords = (s) => { | ||
return toString(s).split(' ').map((w) => { | ||
return ucfirst(w); | ||
}).join(' '); | ||
return ucfirst(w) | ||
}).join(' ') | ||
}; | ||
@@ -234,3 +221,3 @@ const replaceAll = (s, a, b) => { | ||
} | ||
return x; | ||
return x | ||
}; | ||
@@ -255,3 +242,3 @@ const stripAccent = (s) => { | ||
y: 'ý|ỳ|ỷ|ỹ|ỵ', | ||
Y: 'Ý|Ỳ|Ỷ|Ỹ|Ỵ', | ||
Y: 'Ý|Ỳ|Ỷ|Ỹ|Ỵ' | ||
}; | ||
@@ -265,7 +252,7 @@ const updateS = (ai, key) => { | ||
a.forEach((item) => { | ||
return updateS(item, key); | ||
return updateS(item, key) | ||
}); | ||
} | ||
} | ||
return x; | ||
return x | ||
}; | ||
@@ -279,5 +266,5 @@ const genid = (leng, prefix = '') => { | ||
uc, | ||
nb, | ||
nb | ||
].join('').split('').sort(() => { | ||
return Math.random() > 0.5; | ||
return Math.random() > 0.5 | ||
}).join(''); | ||
@@ -291,3 +278,3 @@ const t = cand.length; | ||
} | ||
return s; | ||
return s | ||
}; | ||
@@ -300,3 +287,3 @@ const slugify = (s, delimiter = '-') => { | ||
.replace(/\s+/g, ' ') | ||
.replace(/\s/g, delimiter); | ||
.replace(/\s/g, delimiter) | ||
}; | ||
@@ -306,3 +293,3 @@ | ||
const WEEKDAYS = [ | ||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', | ||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' | ||
]; | ||
@@ -312,9 +299,9 @@ const MONTHS = [ | ||
'May', 'June', 'July', 'August', | ||
'September', 'October', 'November', 'December', | ||
'September', 'October', 'November', 'December' | ||
]; | ||
const now = () => { | ||
return new Date(); | ||
return new Date() | ||
}; | ||
const time = () => { | ||
return Date.now(); | ||
return Date.now() | ||
}; | ||
@@ -325,6 +312,6 @@ const tzone = now().getTimezoneOffset(); | ||
const sign = tzone < 0 ? '+' : '-'; | ||
return ['GMT', sign, String(z).padStart(4, '0')].join(''); | ||
return ['GMT', sign, String(z).padStart(4, '0')].join('') | ||
})(); | ||
const _num = (n) => { | ||
return String(n < 10 ? '0' + n : n); | ||
return String(n < 10 ? '0' + n : n) | ||
}; | ||
@@ -343,3 +330,3 @@ const _ord = (day) => { | ||
} | ||
return s; | ||
return s | ||
}; | ||
@@ -349,7 +336,4 @@ const toDateString = (input, output = PATTERN) => { | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
if (!isString(output)) { | ||
throw new Error('Invalid output pattern.'); | ||
} | ||
const vchar = /\.*\\?([a-z])/gi; | ||
@@ -359,71 +343,71 @@ const meridiem = output.match(/(\.*)a{1}(\.*)*/i); | ||
const mn = MONTHS; | ||
let f = { | ||
Y() { | ||
return d.getFullYear(); | ||
const f = { | ||
Y () { | ||
return d.getFullYear() | ||
}, | ||
y() { | ||
return (f.Y() + '').slice(-2); | ||
y () { | ||
return (f.Y() + '').slice(-2) | ||
}, | ||
F() { | ||
return mn[f.n() - 1]; | ||
F () { | ||
return mn[f.n() - 1] | ||
}, | ||
M() { | ||
return (f.F() + '').slice(0, 3); | ||
M () { | ||
return (f.F() + '').slice(0, 3) | ||
}, | ||
m() { | ||
return _num(f.n()); | ||
m () { | ||
return _num(f.n()) | ||
}, | ||
n() { | ||
return d.getMonth() + 1; | ||
n () { | ||
return d.getMonth() + 1 | ||
}, | ||
S() { | ||
return _ord(f.j()); | ||
S () { | ||
return _ord(f.j()) | ||
}, | ||
j() { | ||
return d.getDate(); | ||
j () { | ||
return d.getDate() | ||
}, | ||
d() { | ||
return _num(f.j()); | ||
d () { | ||
return _num(f.j()) | ||
}, | ||
t() { | ||
return new Date(f.Y(), f.n(), 0).getDate(); | ||
t () { | ||
return new Date(f.Y(), f.n(), 0).getDate() | ||
}, | ||
w() { | ||
return d.getDay(); | ||
w () { | ||
return d.getDay() | ||
}, | ||
l() { | ||
return wn[f.w()]; | ||
l () { | ||
return wn[f.w()] | ||
}, | ||
D() { | ||
return (f.l() + '').slice(0, 3); | ||
D () { | ||
return (f.l() + '').slice(0, 3) | ||
}, | ||
G() { | ||
return d.getHours(); | ||
G () { | ||
return d.getHours() | ||
}, | ||
g() { | ||
return f.G() % 12 || 12; | ||
g () { | ||
return f.G() % 12 || 12 | ||
}, | ||
h() { | ||
return _num(meridiem ? f.g() : f.G()); | ||
h () { | ||
return _num(meridiem ? f.g() : f.G()) | ||
}, | ||
i() { | ||
return _num(d.getMinutes()); | ||
i () { | ||
return _num(d.getMinutes()) | ||
}, | ||
s() { | ||
return _num(d.getSeconds()); | ||
s () { | ||
return _num(d.getSeconds()) | ||
}, | ||
a() { | ||
return f.G() > 11 ? 'pm' : 'am'; | ||
a () { | ||
return f.G() > 11 ? 'pm' : 'am' | ||
}, | ||
A() { | ||
return f.a().toUpperCase(); | ||
A () { | ||
return f.a().toUpperCase() | ||
}, | ||
O() { | ||
return tz; | ||
O () { | ||
return tz | ||
} | ||
}; | ||
const _term = (t, s) => { | ||
return f[t] ? f[t]() : s; | ||
return f[t] ? f[t]() : s | ||
}; | ||
return output.replace(vchar, _term); | ||
return output.replace(vchar, _term) | ||
}; | ||
@@ -433,3 +417,3 @@ const toRelativeTime = (input = time()) => { | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
@@ -442,3 +426,3 @@ let delta = now() - d; | ||
if (delta <= nowThreshold) { | ||
return 'Just now'; | ||
return 'Just now' | ||
} | ||
@@ -453,7 +437,7 @@ let units = null; | ||
month: 30, | ||
year: 12, | ||
year: 12 | ||
}; | ||
for (const key in conversions) { | ||
if (delta < conversions[key]) { | ||
break; | ||
break | ||
} else { | ||
@@ -468,3 +452,3 @@ units = key; | ||
} | ||
return [delta, units].join(' ') + ' ago'; | ||
return [delta, units].join(' ') + ' ago' | ||
}; | ||
@@ -474,3 +458,3 @@ const toUTCDateString = (input = time()) => { | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
@@ -480,3 +464,3 @@ const dMinutes = d.getMinutes(); | ||
dClone.setMinutes(dMinutes + tzone); | ||
return `${toDateString(dClone, 'D, j M Y h:i:s')} GMT+0000`; | ||
return `${toDateString(dClone, 'D, j M Y h:i:s')} GMT+0000` | ||
}; | ||
@@ -486,5 +470,5 @@ const toLocalDateString = (input = time()) => { | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
return toDateString(d, 'D, j M Y h:i:s O'); | ||
return toDateString(d, 'D, j M Y h:i:s O') | ||
}; | ||
@@ -552,15 +536,18 @@ | ||
return (...args) => { | ||
return next(argumentLength - args.length, [...rest, ...args]); | ||
}; | ||
return next(argumentLength - args.length, [...rest, ...args]) | ||
} | ||
} | ||
return fn(...rest); | ||
return fn(...rest) | ||
}; | ||
return next(totalArguments, []); | ||
return next(totalArguments, []) | ||
}; | ||
const compose = (...fns) => { | ||
return fns.reduce((f, g) => (x) => f(g(x))); | ||
return fns.reduce((f, g) => (x) => f(g(x))) | ||
}; | ||
const pipe = (...fns) => { | ||
return fns.reduce((f, g) => (x) => g(f(x))); | ||
return fns.reduce((f, g) => (x) => g(f(x))) | ||
}; | ||
const defineProp = (ob, key, val, config = {}) => { | ||
@@ -570,3 +557,3 @@ const { | ||
configurable = false, | ||
enumerable = false, | ||
enumerable = false | ||
} = config; | ||
@@ -577,25 +564,26 @@ Object.defineProperty(ob, key, { | ||
configurable, | ||
enumerable, | ||
enumerable | ||
}); | ||
}; | ||
const maybe = (val) => { | ||
const __val = val; | ||
const isNil = () => { | ||
return __val === null || __val === undefined; | ||
return __val === null || __val === undefined | ||
}; | ||
const value = () => { | ||
return __val; | ||
return __val | ||
}; | ||
const getElse = (fn) => { | ||
return maybe(__val || fn()); | ||
return maybe(__val || fn()) | ||
}; | ||
const filter = (fn) => { | ||
return maybe(fn(__val) === true ? __val : null); | ||
return maybe(fn(__val) === true ? __val : null) | ||
}; | ||
const map = (fn) => { | ||
return maybe(isNil() ? null : fn(__val)); | ||
return maybe(isNil() ? null : fn(__val)) | ||
}; | ||
const output = Object.create({}); | ||
defineProp(output, '__value__', __val, {enumerable: true}); | ||
defineProp(output, '__type__', 'Maybe', {enumerable: true}); | ||
defineProp(output, '__value__', __val, { enumerable: true }); | ||
defineProp(output, '__type__', 'Maybe', { enumerable: true }); | ||
defineProp(output, 'isNil', isNil); | ||
@@ -606,12 +594,13 @@ defineProp(output, 'value', value); | ||
defineProp(output, 'else', getElse); | ||
return output; | ||
return output | ||
}; | ||
const clone = (val, history = null) => { | ||
const stack = history || new Set(); | ||
if (stack.has(val)) { | ||
return val; | ||
return val | ||
} | ||
stack.add(val); | ||
if (isDate(val)) { | ||
return new Date(val.valueOf()); | ||
return new Date(val.valueOf()) | ||
} | ||
@@ -625,3 +614,3 @@ const copyObject = (o) => { | ||
} | ||
return oo; | ||
return oo | ||
}; | ||
@@ -631,16 +620,16 @@ const copyArray = (a) => { | ||
if (isArray(e)) { | ||
return copyArray(e); | ||
return copyArray(e) | ||
} else if (isObject(e)) { | ||
return copyObject(e); | ||
return copyObject(e) | ||
} | ||
return clone(e, stack); | ||
}); | ||
return clone(e, stack) | ||
}) | ||
}; | ||
if (isArray(val)) { | ||
return copyArray(val); | ||
return copyArray(val) | ||
} | ||
if (isObject(val)) { | ||
return copyObject(val); | ||
return copyObject(val) | ||
} | ||
return val; | ||
return val | ||
}; | ||
@@ -650,8 +639,8 @@ const copies = (source, dest, matched = false, excepts = []) => { | ||
if (excepts.length > 0 && excepts.includes(k)) { | ||
continue; | ||
continue | ||
} | ||
if (!matched || matched && hasProperty(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)) { | ||
if ((isObject(ob) && isObject(oa)) || (isArray(ob) && isArray(oa))) { | ||
dest[k] = copies(oa, dest[k], matched, excepts); | ||
@@ -663,30 +652,37 @@ } else { | ||
} | ||
return dest; | ||
return dest | ||
}; | ||
const unique = (arr = []) => { | ||
return [...new Set(arr)]; | ||
return [...new Set(arr)] | ||
}; | ||
const fnSort = (a, b) => { | ||
return a > b ? 1 : a < b ? -1 : 0; | ||
return a > b ? 1 : a < b ? -1 : 0 | ||
}; | ||
const sort = (arr = [], fn = fnSort) => { | ||
const sort = (arr = [], sorting) => { | ||
const tmp = [...arr]; | ||
const fn = sorting || fnSort; | ||
tmp.sort(fn); | ||
return tmp; | ||
return tmp | ||
}; | ||
const sortBy = (key, order = 1, arr = []) => { | ||
const sortBy = (arr = [], order = 1, key) => { | ||
return sort(arr, (m, n) => { | ||
return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0); | ||
}); | ||
return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0) | ||
}) | ||
}; | ||
const shuffle = (arr = []) => { | ||
return sort([...arr], () => { | ||
return Math.random() > 0.5; | ||
}); | ||
const input = [...arr]; | ||
const output = []; | ||
let inputLen = input.length; | ||
while (inputLen > 0) { | ||
const index = Math.floor(Math.random() * inputLen); | ||
output.push(input.splice(index, 1)[0]); | ||
inputLen--; | ||
} | ||
return output | ||
}; | ||
const pick = (count = 1, arr = []) => { | ||
const a = shuffle([...arr]); | ||
const pick = (arr = [], count = 1) => { | ||
const a = shuffle(arr); | ||
const mc = Math.max(1, count); | ||
const c = Math.min(mc, a.length - 1); | ||
return a.splice(0, c); | ||
return a.splice(0, c) | ||
}; | ||
@@ -743,2 +739,2 @@ | ||
}))); | ||
})); |
@@ -1,2 +0,2 @@ | ||
// bellajs@9.3.0, by @ndaidong - built on Sat, 01 May 2021 14:55:33 GMT - published under MIT license | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bella={})}(this,(function(e){const t=e=>({}.toString.call(e)),r=e=>Array.isArray(e),n=e=>String(e)===e,o=e=>Number(e)===e,i=e=>"[object Null]"===t(e),a=e=>"[object Undefined]"===t(e),s=e=>"[object Object]"===t(e)&&!r(e),l=e=>e instanceof Date&&!isNaN(e.valueOf()),u=e=>a(e)||i(e),c=e=>!e||u(e)||n(e)&&""===e||r(e)&&0===e.length||s(e)&&0===Object.keys(e).length,g=(e,t)=>!(!e||!t)&&Object.prototype.hasOwnProperty.call(e,t),f=(e,t)=>{let i=!0;if(c(e)&&c(t))return!0;if(l(e)&&l(t))return e.getTime()===t.getTime();if(o(e)&&o(t)||n(e)&&n(t))return e===t;if(r(e)&&r(t)){if(e.length!==t.length)return!1;if(e.length>0)for(let r=0,n=e.length;r<n;r++)if(!f(e[r],t[r])){i=!1;break}}else if(s(e)&&s(t)){const r=[],n=[];for(const t in e)g(e,t)&&r.push(t);for(const e in t)g(t,e)&&n.push(e);if(r.length!==n.length)return!1;for(const r in e)if(!g(t,r)||!f(e[r],t[r])){i=!1;break}}return i},p=Number.MAX_SAFE_INTEGER,h=(e,t)=>{if((!e||e<0)&&(e=0),t||(t=p),e===t)return t;e>t&&(e=Math.min(e,t),t=Math.max(e,t));const r=e,n=t-e+1;return Math.floor(Math.random()*n)+r},d=e=>{const t=o(e)?String(e):e;if(!n(t))throw new Error("InvalidInput: String required.");return t},m=e=>{const t=d(e).toLowerCase();return t.length>1?t.charAt(0).toUpperCase()+t.slice(1):t.toUpperCase()},b=(e,t,i)=>{let a=d(e);if(o(t)&&(t=String(t)),o(i)&&(i=String(i)),n(t)&&n(i)){const e=a.split(t);a=e.join(i)}else if(r(t)&&n(i))t.forEach((e=>{a=b(a,e,i)}));else if(r(t)&&r(i)&&t.length===i.length){const e=t.length;if(e>0)for(let r=0;r<e;r++){const e=t[r],n=i[r];a=b(a,e,n)}}return a},w=e=>{let t=d(e);const r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(e,r)=>{t=b(t,e,r)};for(const e in r)if(g(r,e)){r[e].split("|").forEach((t=>n(t,e)))}return t},y=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],M=["January","February","March","April","May","June","July","August","September","October","November","December"],j=()=>new Date,D=()=>Date.now(),S=j().getTimezoneOffset(),I=(()=>{const e=Math.abs(S/60);return["GMT",S<0?"+":"-",String(e).padStart(4,"0")].join("")})(),N=e=>String(e<10?"0"+e:e),v=(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(!n(t))throw new Error("Invalid output pattern.");const o=t.match(/(\.*)a{1}(\.*)*/i),i=y,a=M;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",t})(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(o?s.g():s.G()),i:()=>N(r.getMinutes()),s:()=>N(r.getSeconds()),a:()=>s.G()>11?"pm":"am",A:()=>s.a().toUpperCase(),O:()=>I};return t.replace(/\.*\\?([a-z])/gi,((e,t)=>s[e]?s[e]():t))};const A=(e,t,r,n={})=>{const{writable:o=!1,configurable:i=!1,enumerable:a=!1}=n;Object.defineProperty(e,t,{value:r,writable:o,configurable:i,enumerable:a})},E=e=>{const t=e,r=()=>null==t,n=Object.create({});return A(n,"__value__",t,{enumerable:!0}),A(n,"__type__","Maybe",{enumerable:!0}),A(n,"isNil",r),A(n,"value",(()=>t)),A(n,"map",(e=>E(r()?null:e(t)))),A(n,"if",(e=>E(!0===e(t)?t:null))),A(n,"else",(e=>E(t||e()))),n},O=(e,t=null)=>{const n=t||new Set;if(n.has(e))return e;if(n.add(e),l(e))return new Date(e.valueOf());const o=e=>{const t=Object.create({});for(const r in e)g(e,r)&&(t[r]=O(e[r],n));return t},i=e=>[...e].map((e=>r(e)?i(e):s(e)?o(e):O(e,n)));return r(e)?i(e):s(e)?o(e):e},T=(e,t,n=!1,o=[])=>{for(const i in e)if(!(o.length>0&&o.includes(i))&&(!n||n&&g(t,i))){const a=e[i],l=t[i];s(l)&&s(a)||r(l)&&r(a)?t[i]=T(a,t[i],n,o):t[i]=O(a)}return t},_=(e,t)=>e>t?1:e<t?-1:0,q=(e=[],t=_)=>{const r=[...e];return r.sort(t),r},C=(e=[])=>q([...e],(()=>Math.random()>.5));e.clone=O,e.compose=(...e)=>e.reduce(((e,t)=>r=>e(t(r)))),e.copies=T,e.curry=e=>{const t=e.length,r=(t,n)=>t>0?(...e)=>r(t-e.length,[...n,...e]):e(...n);return r(t,[])},e.equals=f,e.escapeHTML=e=>d(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),e.genid=(e,t="")=>{const r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),o=[r,n,"0123456789"].join("").split("").sort((()=>Math.random()>.5)).join(""),i=o.length,a=Math.max(e||32,t.length);let s=t;for(;s.length<a;){const e=h(0,i);s+=o.charAt(e)||""}return s},e.hasProperty=g,e.isArray=r,e.isBoolean=e=>Boolean(e)===e,e.isDate=l,e.isElement=e=>null!==t(e).match(/^\[object HTML\w*Element]$/),e.isEmail=e=>n(e)&&/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(e),e.isEmpty=c,e.isFunction=e=>"[object Function]"===t(e),e.isInteger=e=>Number.isInteger(e),e.isLetter=e=>n(e)&&/^[a-z]+$/i.test(e),e.isNil=u,e.isNull=i,e.isNumber=o,e.isObject=s,e.isString=n,e.isUndefined=a,e.maybe=E,e.md5=e=>{for(var t=[],r=0;r<64;)t[r]=0|4294967296*Math.abs(Math.sin(++r));for(var n,o,i,a,s=[],l=decodeURIComponent(encodeURI(e)),u=l.length,c=[n=1732584193,o=-271733879,~n,~o],g=0;g<=u;)s[g>>2]|=(l.charCodeAt(g)||128)<<g++%4*8;for(s[e=16*(u+8>>6)+14]=8*u,g=0;g<e;g+=16){for(u=c,a=0;a<64;)u=[i=u[3],(n=0|u[1])+((i=u[0]+[n&(o=u[2])|~n&i,i&n|~i&o,n^o^i,o^(n|~i)][u=a>>4]+(t[a]+(0|s[[a,5*a+1,3*a+5,7*a][u]%16+g])))<<(u=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*u+a++%4])|i>>>32-u),n,o];for(a=4;a;)c[--a]=c[a]+u[a]}for(e="";a<32;)e+=(c[a>>3]>>4*(1^7&a++)&15).toString(16);return e},e.now=j,e.pick=(e=1,t=[])=>{const r=C([...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=h,e.replaceAll=b,e.shuffle=C,e.slugify=(e,t="-")=>w(e).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,t),e.sort=q,e.sortBy=(e,t=1,r=[])=>q(r,((r,n)=>r[e]>n[e]?t:r[e]<n[e]?-1*t:0)),e.stripAccent=w,e.stripTags=e=>d(e).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),e.time=D,e.toDateString=v,e.toLocalDateString=(e=D())=>{const t=l(e)?e:new Date(e);if(!l(t))throw new Error("InvalidInput: Number or Date required.");return v(t,"D, j M Y h:i:s O")},e.toRelativeTime=(e=D())=>{const t=l(e)?e:new Date(e);if(!l(t))throw new Error("InvalidInput: Number or Date required.");let r=j()-t,n=parseInt(t,10);if(isNaN(n)&&(n=0),r<=n)return"Just now";let o=null;const 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 r=Math.floor(r),1!==r&&(o+="s"),[r,o].join(" ")+" ago"},e.toUTCDateString=(e=D())=>{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+S),`${v(n,"D, j M Y h:i:s")} GMT+0000`},e.truncate=(e,t)=>{const r=d(e),n=t||140;if(r.length<=n)return r;let o=r.substring(0,n);const i=o.split(" ");let a="";return i.length>1?(i.pop(),a+=i.join(" "),a.length<r.length&&(a+="...")):(o=o.substring(0,n-3),a=o+"..."),a},e.ucfirst=m,e.ucwords=e=>d(e).split(" ").map((e=>m(e))).join(" "),e.unescapeHTML=e=>d(e).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),e.unique=(e=[])=>[...new Set(e)],Object.defineProperty(e,"__esModule",{value:!0})})); | ||
// bellajs@10.0.0, by @ndaidong - built on Thu, 02 Dec 2021 10:57:05 GMT - published under MIT license | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bella={})}(this,(function(e){const t=e=>({}.toString.call(e)),r=e=>Array.isArray(e),n=e=>String(e)===e,o=e=>Number(e)===e,a=e=>"[object Null]"===t(e),i=e=>"[object Undefined]"===t(e),s=e=>i(e)||a(e),l=e=>"[object Object]"===t(e)&&!r(e),c=e=>e instanceof Date&&!isNaN(e.valueOf()),u=e=>!e||s(e)||n(e)&&""===e||r(e)&&0===e.length||l(e)&&0===Object.keys(e).length,g=(e,t)=>!(!e||!t)&&Object.prototype.hasOwnProperty.call(e,t),f=(e,t)=>{if(u(e)&&u(t))return!0;if(c(e)&&c(t))return e.getTime()===t.getTime();if(r(e)&&r(t)){if(e.length!==t.length)return!1;let r=!0;for(let n=0;n<e.length;n++)if(!f(e[n],t[n])){r=!1;break}return r}if(l(e)&&l(t)){if(Object.keys(e).length!==Object.keys(t).length)return!1;let r=!0;for(const n in e)if(!g(t,n)||!f(e[n],t[n])){r=!1;break}return r}return e===t},p=Number.MAX_SAFE_INTEGER,h=(e,t)=>{if((!e||e<0)&&(e=0),t||(t=p),e===t)return t;e>t&&(e=Math.min(e,t),t=Math.max(e,t));const r=e,n=t-e+1;return Math.floor(Math.random()*n)+r},d=e=>{const t=o(e)?String(e):e;if(!n(t))throw new Error("InvalidInput: String required.");return t},m=e=>{const t=d(e).toLowerCase();return t.length>1?t.charAt(0).toUpperCase()+t.slice(1):t.toUpperCase()},b=(e,t,a)=>{let i=d(e);if(o(t)&&(t=String(t)),o(a)&&(a=String(a)),n(t)&&n(a)){const e=i.split(t);i=e.join(a)}else if(r(t)&&n(a))t.forEach((e=>{i=b(i,e,a)}));else if(r(t)&&r(a)&&t.length===a.length){const e=t.length;if(e>0)for(let r=0;r<e;r++){const e=t[r],n=a[r];i=b(i,e,n)}}return i},y=e=>{let t=d(e);const r={a:"á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä",A:"Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä",c:"ç",C:"Ç",d:"đ",D:"Đ",e:"é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ë",E:"É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ë",i:"í|ì|ỉ|ĩ|ị|ï|î",I:"Í|Ì|Ỉ|Ĩ|Ị|Ï|Î",o:"ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ö",O:"Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ô|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ö",u:"ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|û",U:"Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Û",y:"ý|ỳ|ỷ|ỹ|ỵ",Y:"Ý|Ỳ|Ỷ|Ỹ|Ỵ"},n=(e,r)=>{t=b(t,e,r)};for(const e in r)if(g(r,e)){r[e].split("|").forEach((t=>n(t,e)))}return t},w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],M=["January","February","March","April","May","June","July","August","September","October","November","December"],j=()=>new Date,D=()=>Date.now(),S=j().getTimezoneOffset(),N=(()=>{const e=Math.abs(S/60);return["GMT",S<0?"+":"-",String(e).padStart(4,"0")].join("")})(),O=e=>String(e<10?"0"+e:e),I=(e,t="D, M d, Y h:i:s A")=>{const r=c(e)?e:new Date(e);if(!c(r))throw new Error("InvalidInput: Number or Date required.");const n=t.match(/(\.*)a{1}(\.*)*/i),o=w,a=M,i={Y:()=>r.getFullYear(),y:()=>(i.Y()+"").slice(-2),F:()=>a[i.n()-1],M:()=>(i.F()+"").slice(0,3),m:()=>O(i.n()),n:()=>r.getMonth()+1,S:()=>(e=>{let t=e+" ";const r=t.charAt(t.length-2);return t="1"===r?"st":"2"===r?"nd":"3"===r?"rd":"th",t})(i.j()),j:()=>r.getDate(),d:()=>O(i.j()),t:()=>new Date(i.Y(),i.n(),0).getDate(),w:()=>r.getDay(),l:()=>o[i.w()],D:()=>(i.l()+"").slice(0,3),G:()=>r.getHours(),g:()=>i.G()%12||12,h:()=>O(n?i.g():i.G()),i:()=>O(r.getMinutes()),s:()=>O(r.getSeconds()),a:()=>i.G()>11?"pm":"am",A:()=>i.a().toUpperCase(),O:()=>N};return t.replace(/\.*\\?([a-z])/gi,((e,t)=>i[e]?i[e]():t))};const v=(e,t,r,n={})=>{const{writable:o=!1,configurable:a=!1,enumerable:i=!1}=n;Object.defineProperty(e,t,{value:r,writable:o,configurable:a,enumerable:i})},A=e=>{const t=e,r=()=>null==t,n=Object.create({});return v(n,"__value__",t,{enumerable:!0}),v(n,"__type__","Maybe",{enumerable:!0}),v(n,"isNil",r),v(n,"value",(()=>t)),v(n,"map",(e=>A(r()?null:e(t)))),v(n,"if",(e=>A(!0===e(t)?t:null))),v(n,"else",(e=>A(t||e()))),n},T=(e,t=null)=>{const n=t||new Set;if(n.has(e))return e;if(n.add(e),c(e))return new Date(e.valueOf());const o=e=>{const t=Object.create({});for(const r in e)g(e,r)&&(t[r]=T(e[r],n));return t},a=e=>[...e].map((e=>r(e)?a(e):l(e)?o(e):T(e,n)));return r(e)?a(e):l(e)?o(e):e},E=(e,t,n=!1,o=[])=>{for(const a in e)if(!(o.length>0&&o.includes(a))&&(!n||n&&g(t,a))){const i=e[a],s=t[a];l(s)&&l(i)||r(s)&&r(i)?t[a]=E(i,t[a],n,o):t[a]=T(i)}return t},_=(e,t)=>e>t?1:e<t?-1:0,q=(e=[],t)=>{const r=[...e],n=t||_;return r.sort(n),r},C=(e=[])=>{const t=[...e],r=[];let n=t.length;for(;n>0;){const e=Math.floor(Math.random()*n);r.push(t.splice(e,1)[0]),n--}return r};e.clone=T,e.compose=(...e)=>e.reduce(((e,t)=>r=>e(t(r)))),e.copies=E,e.curry=e=>{const t=e.length,r=(t,n)=>t>0?(...e)=>r(t-e.length,[...n,...e]):e(...n);return r(t,[])},e.equals=f,e.escapeHTML=e=>d(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),e.genid=(e,t="")=>{const r="abcdefghijklmnopqrstuvwxyz",n=r.toUpperCase(),o=[r,n,"0123456789"].join("").split("").sort((()=>Math.random()>.5)).join(""),a=o.length,i=Math.max(e||32,t.length);let s=t;for(;s.length<i;){const e=h(0,a);s+=o.charAt(e)||""}return s},e.hasProperty=g,e.isArray=r,e.isBoolean=e=>Boolean(e)===e,e.isDate=c,e.isElement=e=>null!==t(e).match(/^\[object HTML\w*Element]$/),e.isEmail=e=>n(e)&&/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(e),e.isEmpty=u,e.isFunction=e=>"[object Function]"===t(e),e.isInteger=e=>Number.isInteger(e),e.isLetter=e=>n(e)&&/^[a-z]+$/i.test(e),e.isNil=s,e.isNull=a,e.isNumber=o,e.isObject=l,e.isString=n,e.isUndefined=i,e.maybe=A,e.md5=e=>{for(var t=[],r=0;r<64;)t[r]=0|4294967296*Math.abs(Math.sin(++r));for(var n,o,a,i,s=[],l=decodeURIComponent(encodeURI(e)),c=l.length,u=[n=1732584193,o=-271733879,~n,~o],g=0;g<=c;)s[g>>2]|=(l.charCodeAt(g)||128)<<g++%4*8;for(s[e=16*(c+8>>6)+14]=8*c,g=0;g<e;g+=16){for(c=u,i=0;i<64;)c=[a=c[3],(n=0|c[1])+((a=c[0]+[n&(o=c[2])|~n&a,a&n|~a&o,n^o^a,o^(n|~a)][c=i>>4]+(t[i]+(0|s[[i,5*i+1,3*i+5,7*i][c]%16+g])))<<(c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*c+i++%4])|a>>>32-c),n,o];for(i=4;i;)u[--i]=u[i]+c[i]}for(e="";i<32;)e+=(u[i>>3]>>4*(1^7&i++)&15).toString(16);return e},e.now=j,e.pick=(e=[],t=1)=>{const r=C(e),n=Math.max(1,t),o=Math.min(n,r.length-1);return r.splice(0,o)},e.pipe=(...e)=>e.reduce(((e,t)=>r=>t(e(r)))),e.randint=h,e.replaceAll=b,e.shuffle=C,e.slugify=(e,t="-")=>y(e).trim().toLowerCase().replace(/\W+/g," ").replace(/\s+/g," ").replace(/\s/g,t),e.sort=q,e.sortBy=(e=[],t=1,r)=>q(e,((e,n)=>e[r]>n[r]?t:e[r]<n[r]?-1*t:0)),e.stripAccent=y,e.stripTags=e=>d(e).replace(/<.*?>/gi," ").replace(/\s\s+/g," ").trim(),e.time=D,e.toDateString=I,e.toLocalDateString=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");return I(t,"D, j M Y h:i:s O")},e.toRelativeTime=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");let r=j()-t,n=parseInt(t,10);if(isNaN(n)&&(n=0),r<=n)return"Just now";let o=null;const a={millisecond:1,second:1e3,minute:60,hour:60,day:24,month:30,year:12};for(const e in a){if(r<a[e])break;o=e,r/=a[e]}return r=Math.floor(r),1!==r&&(o+="s"),[r,o].join(" ")+" ago"},e.toUTCDateString=(e=D())=>{const t=c(e)?e:new Date(e);if(!c(t))throw new Error("InvalidInput: Number or Date required.");const r=t.getMinutes(),n=new Date(t);return n.setMinutes(r+S),`${I(n,"D, j M Y h:i:s")} GMT+0000`},e.truncate=(e,t)=>{const r=d(e),n=t||140;if(r.length<=n)return r;let o=r.substring(0,n);const a=o.split(" ");let i="";return a.length>1?(a.pop(),i+=a.join(" "),i.length<r.length&&(i+="...")):(o=o.substring(0,n-3),i=o+"..."),i},e.ucfirst=m,e.ucwords=e=>d(e).split(" ").map((e=>m(e))).join(" "),e.unescapeHTML=e=>d(e).replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),e.unique=(e=[])=>[...new Set(e)],Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"version": "9.3.0", | ||
"version": "10.0.0", | ||
"name": "bellajs", | ||
@@ -18,6 +18,5 @@ "description": "A useful helper for any javascript program", | ||
"scripts": { | ||
"lint": "eslint ./src", | ||
"lint": "standard ./src", | ||
"pretest": "npm run lint && npm run build", | ||
"test": "tap tests/start.js --coverage --reporter=spec --coverage-report=html --no-browser --functions=95 --statements=95 --branches=85", | ||
"citest": "tap tests/start.js --coverage --reporter=spec --coverage-report=lcov --no-browser --functions=95 --statements=95 --branches=85", | ||
"test": "NODE_ENV=test jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles --env=jsdom", | ||
"build": "gccmin -e src/main.js -n bella -o dist -p package.json", | ||
@@ -27,10 +26,15 @@ "reset": "node reset" | ||
"devDependencies": { | ||
"eslint-config-goes": "^1.2.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.16.0", | ||
"gcc-min": "^7.3.0", | ||
"is": "^3.3.0", | ||
"jsdom": "^16.5.3", | ||
"jsdom-global": "^3.0.2", | ||
"sinon": "^10.0.0", | ||
"tap": "^15.0.6" | ||
"jest": "^27.3.1" | ||
}, | ||
"babel": { | ||
"env": { | ||
"test": { | ||
"plugins": [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
] | ||
} | ||
} | ||
}, | ||
"keywords": [ | ||
@@ -37,0 +41,0 @@ "detection", |
474
README.md
@@ -10,2 +10,3 @@ BellaJS | ||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ndaidong_bellajs&metric=alert_status)](https://sonarcloud.io/dashboard?id=ndaidong_bellajs) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
@@ -17,20 +18,11 @@ You may be interested in [BellaPy](https://github.com/ndaidong/bellapy) too. | ||
* [Setup](#setup) | ||
* [APIs](#apis) | ||
* [DataType detection](#datatype-detection) | ||
* [Date format](#date-format) | ||
* [String manipulation](#string-manipulation) | ||
* [Date format](#date-format) | ||
* [Other utils](#other-utils) | ||
* [Data handling](#data-handling) | ||
* [clone](#clone) | ||
* [compose](#compose) | ||
* [copies](#copies) | ||
* [curry](#curryfn) | ||
* [equals](#equals) | ||
* [genid](#genid) | ||
* [maybe](#maybe) | ||
* [md5](#md5) | ||
* [Array utils](#array-utils) | ||
* [pick](#pick) | ||
* [pipe](#pipe) | ||
* [randint](#randint) | ||
* [sort](#sort) | ||
@@ -40,2 +32,12 @@ * [sortBy](#sortBy) | ||
* [unique](#unique) | ||
* [Functional utils](#functional-utils) | ||
* [curry](#curryfn) | ||
* [compose](#compose) | ||
* [pipe](#pipe) | ||
* [maybe](#maybe) | ||
* [Other utils](#other-utils) | ||
* [equals](#equals) | ||
* [randint](#randint) | ||
* [genid](#genid) | ||
* [md5](#md5) | ||
@@ -77,3 +79,3 @@ * [Test](#test) | ||
// with tree shacking | ||
// or | ||
import { | ||
@@ -105,14 +107,2 @@ isArray, | ||
### String manipulation | ||
- .ucfirst(String s) | ||
- .ucwords(String s) | ||
- .escapeHTML(String s) | ||
- .unescapeHTML(String s) | ||
- .slugify(String s) | ||
- .stripTags(String s) | ||
- .stripAccent(String s) | ||
- .truncate(String s, Number limit) | ||
- .replaceAll(String s, String|Array search, String|Array replace) | ||
### Date format | ||
@@ -163,14 +153,27 @@ | ||
toUTCDateString | ||
} from 'bellajs'; | ||
} from 'bellajs' | ||
let t = 1509628030108; | ||
const t = 1509628030108 | ||
toRelativeTime(t); //=> 2 seconds ago | ||
toDateString(t, 'Y/m/d h:i:s'); //=> 2017/11/02 20:07:10 | ||
toLocalDateString(t); //=> Thu, 2 Nov 2017 20:07:10 GMT+0007 | ||
toUTCDateString(t); //=> Thu, 2 Nov 2017 13:07:10 GMT+0000 | ||
toRelativeTime(t) // => 2 seconds ago | ||
toDateString(t, 'Y/m/d h:i:s') // => 2017/11/02 20:07:10 | ||
toLocalDateString(t) // => Thu, 2 Nov 2017 20:07:10 GMT+0007 | ||
toUTCDateString(t) // => Thu, 2 Nov 2017 13:07:10 GMT+0000 | ||
``` | ||
### Other utils | ||
### String manipulation | ||
- .ucfirst(String s) | ||
- .ucwords(String s) | ||
- .escapeHTML(String s) | ||
- .unescapeHTML(String s) | ||
- .slugify(String s) | ||
- .stripTags(String s) | ||
- .stripAccent(String s) | ||
- .truncate(String s, Number limit) | ||
- .replaceAll(String s, String|Array search, String|Array replace) | ||
### Data handling | ||
#### clone | ||
@@ -185,3 +188,3 @@ | ||
```js | ||
let b = [ | ||
const b = [ | ||
1, 5, 0, 'a', -10, '-10', '', | ||
@@ -192,6 +195,6 @@ { | ||
} | ||
]; | ||
] | ||
let cb = bella.clone(b); | ||
console.log(cb); | ||
const cb = bella.clone(b) | ||
console.log(cb) | ||
``` | ||
@@ -202,6 +205,6 @@ | ||
```js | ||
cb[7].a = 2; | ||
cb[7].b = 'Noop'; | ||
cb[7].a = 2 | ||
cb[7].b = 'Noop' | ||
console.log(b[7]); | ||
console.log(b[7]) | ||
``` | ||
@@ -218,42 +221,2 @@ | ||
#### 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 | ||
@@ -273,3 +236,3 @@ | ||
```js | ||
let a = { | ||
const a = { | ||
name: 'Toto', | ||
@@ -281,4 +244,4 @@ age: 30, | ||
} | ||
}; | ||
let b = { | ||
} | ||
const b = { | ||
level: 4, | ||
@@ -294,6 +257,6 @@ IQ: 140, | ||
} | ||
}; | ||
} | ||
bella.copies(a, b); | ||
console.log(b); | ||
bella.copies(a, b) | ||
console.log(b) | ||
``` | ||
@@ -321,6 +284,10 @@ | ||
#### curry | ||
### Array utils | ||
#### pick | ||
Randomly choose N elements from array. | ||
```js | ||
curry(fn) | ||
pick(Array arr [, Integer count = 1]) | ||
``` | ||
@@ -331,19 +298,16 @@ | ||
```js | ||
import {curry} from 'bellajs'; | ||
import { pick } 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 | ||
const arr = [1, 3, 8, 2, 5, 7] | ||
pick(arr, 2) // --> [3, 5] | ||
pick(arr, 2) // --> [8, 1] | ||
pick(arr) // --> [3] | ||
pick(arr) // --> [7] | ||
``` | ||
#### equals | ||
#### sort | ||
```js | ||
equals(Anything a, Anything b) | ||
sort(Array a [, Function compare]) | ||
``` | ||
@@ -354,12 +318,16 @@ | ||
```js | ||
import {equals} from 'bellajs'; | ||
import { sort } from 'bellajs' | ||
equals({}, {}); // => true | ||
equals(0, 1); // => false | ||
const fn = (a, b) => { | ||
return a < b ? 1 : a > b ? -1 : 0 | ||
} | ||
sort([3, 1, 5, 2], fn) // => [ 1, 2, 3, 5 ] | ||
sort([3, 1, 5, 2], fn) // => [ 5, 3, 2, 1 ] | ||
``` | ||
#### genid | ||
#### sortBy | ||
```js | ||
genid([Number length [, String prefix]]) | ||
sortBy(Array a, Number order, String property) | ||
``` | ||
@@ -370,68 +338,68 @@ | ||
```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 { 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(players, -1, 'age') | ||
console.log(result) | ||
``` | ||
#### maybe | ||
#### shuffle | ||
Shuffle an array. | ||
```js | ||
maybe(Anything val) | ||
shuffle(Array arr) | ||
``` | ||
Return a static variant of `Maybe` monad. | ||
Examples: | ||
```js | ||
import {maybe} from 'bellajs'; | ||
import { shuffle } from 'bellajs' | ||
const plus5 = x => x + 5; | ||
const minus2 = x => x - 2; | ||
const isNumber = x => Number(x) === x; | ||
const toString = x => 'The value is ' + String(x); | ||
const getDefault = () => 'This is default value'; | ||
shuffle([1, 3, 8, 2, 5, 7]) | ||
``` | ||
maybe(5) | ||
.map(plus5) | ||
.map(minus2) | ||
.value() // 8 | ||
#### unique | ||
maybe('noop') | ||
.map(plus5) | ||
.map(minus2) | ||
.value() // null | ||
```js | ||
unique(Array a) | ||
``` | ||
maybe(5) | ||
.if(isNumber) | ||
.map(plus5) | ||
.map(minus2) | ||
.else(getDefault) | ||
.map(toString) | ||
.value() // 'The value is 8' | ||
Examples: | ||
maybe() | ||
.if(isNumber) | ||
.map(plus5) | ||
.map(minus2) | ||
.map(toString) | ||
.value() // null | ||
```js | ||
import { unique } from 'bellajs' | ||
maybe() | ||
.if(isNumber) | ||
.map(plus5) | ||
.map(minus2) | ||
.else(getDefault) | ||
.map(toString) | ||
.value() // 'This is default value' | ||
unique([1, 2, 3, 2, 3, 1, 5]) // => [ 1, 2, 3, 5 ] | ||
``` | ||
#### md5 | ||
### Functional utils | ||
#### curry | ||
```js | ||
md5(String s) | ||
curry(fn) | ||
``` | ||
@@ -442,13 +410,21 @@ | ||
```js | ||
import {md5} from 'bellajs'; | ||
import { curry } from 'bellajs' | ||
md5('abc'); // => 900150983cd24fb0d6963f7d28e17f72 | ||
const 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 | ||
``` | ||
#### pick | ||
#### compose | ||
Randomly choose N elements from array. | ||
Performs right-to-left function composition. | ||
```js | ||
pick(Integer count, Array arr) | ||
compose(f1, f2, ...fN) | ||
``` | ||
@@ -459,9 +435,32 @@ | ||
```js | ||
import {pick} from 'bellajs'; | ||
import {compose} from 'bellajs' | ||
const arr = [1, 3, 8, 2, 5, 7] | ||
pick(arr, 2); // --> [3, 5] | ||
pick(arr, 2); // --> [8, 1] | ||
const f1 = (name) => { | ||
return `f1 ${name}` | ||
} | ||
const f2 = (name) => { | ||
return `f2 ${name}` | ||
} | ||
const f3 = (name) => { | ||
return `f3 ${name}` | ||
} | ||
const addF = compose(f1, f2, f3) | ||
addF('Hello') // => 'f1 f2 f3 Hello' | ||
const add1 = (num) => { | ||
return num + 1 | ||
} | ||
const mult2 = (num) => { | ||
return num * 2 | ||
} | ||
const add1AndMult2 = compose(add1, mult2) | ||
add1AndMult2(3) // => 7 | ||
// because multiple to 2 first, then add 1 late => 3 * 2 + 1 | ||
``` | ||
#### pipe | ||
@@ -478,27 +477,27 @@ | ||
```js | ||
import {pipe} from 'bellajs'; | ||
import { pipe } from 'bellajs' | ||
let f1 = (name) => { | ||
return `f1 ${name}`; | ||
}; | ||
let f2 = (name) => { | ||
return `f2 ${name}`; | ||
}; | ||
let f3 = (name) => { | ||
return `f3 ${name}`; | ||
}; | ||
const f1 = (name) => { | ||
return `f1 ${name}` | ||
} | ||
const f2 = (name) => { | ||
return `f2 ${name}` | ||
} | ||
const f3 = (name) => { | ||
return `f3 ${name}` | ||
} | ||
let addF = pipe(f1, f2, f3); | ||
const addF = pipe(f1, f2, f3) | ||
addF('Hello') // => 'f3 f2 f1 Hello' | ||
let add1 = (num) => { | ||
return num + 1; | ||
}; | ||
const add1 = (num) => { | ||
return num + 1 | ||
} | ||
let mult2 = (num) => { | ||
return num * 2; | ||
}; | ||
const mult2 = (num) => { | ||
return num * 2 | ||
} | ||
let add1AndMult2 = pipe(add1, mult2); | ||
const add1AndMult2 = pipe(add1, mult2) | ||
add1AndMult2(3) // => 8 | ||
@@ -508,21 +507,61 @@ // because add 1 first, then multiple to 2 late => (3 + 1) * 2 | ||
#### randint | ||
#### maybe | ||
```js | ||
randint([Number min [, Number max]]) | ||
maybe(Anything val) | ||
``` | ||
Return a static variant of `Maybe` monad. | ||
Examples: | ||
```js | ||
import {randint} from 'bellajs'; | ||
import { maybe } from 'bellajs' | ||
randint(); // => a random integer | ||
randint(1, 5); // => a random integer between 3 and 5, including 1 and 5 | ||
const plus5 = x => x + 5 | ||
const minus2 = x => x - 2 | ||
const isNumber = x => Number(x) === x | ||
const toString = x => 'The value is ' + String(x) | ||
const getDefault = () => 'This is default value' | ||
maybe(5) | ||
.map(plus5) | ||
.map(minus2) | ||
.value() // 8 | ||
maybe('noop') | ||
.map(plus5) | ||
.map(minus2) | ||
.value() // null | ||
maybe(5) | ||
.if(isNumber) | ||
.map(plus5) | ||
.map(minus2) | ||
.else(getDefault) | ||
.map(toString) | ||
.value() // 'The value is 8' | ||
maybe() | ||
.if(isNumber) | ||
.map(plus5) | ||
.map(minus2) | ||
.map(toString) | ||
.value() // null | ||
maybe() | ||
.if(isNumber) | ||
.map(plus5) | ||
.map(minus2) | ||
.else(getDefault) | ||
.map(toString) | ||
.value() // 'This is default value' | ||
``` | ||
#### sort | ||
### Other utils | ||
#### equals | ||
```js | ||
sort(Array a [, Function compare]) | ||
equals(Anything a, Anything b) | ||
``` | ||
@@ -533,16 +572,12 @@ | ||
```js | ||
import {sort} from 'bellajs'; | ||
import { equals } from 'bellajs' | ||
const fn = (a, b) => { | ||
return a < b ? 1 : a > b ? -1 : 0; | ||
}; | ||
sort([3, 1, 5, 2], fn); // => [ 1, 2, 3, 5 ] | ||
sort([3, 1, 5, 2], fn); // => [ 5, 3, 2, 1 ] | ||
equals({}, {}) // => true | ||
equals(0, 1) // => false | ||
``` | ||
#### sortBy | ||
#### randint | ||
```js | ||
sortBy(String property, Number order, Array a) | ||
randint([Number min [, Number max]]) | ||
``` | ||
@@ -553,38 +588,12 @@ | ||
```js | ||
import { randint } from 'bellajs' | ||
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) | ||
randint() // => a random integer | ||
randint(1, 5) // => a random integer between 3 and 5, including 1 and 5 | ||
``` | ||
#### shuffle | ||
#### genid | ||
Shuffle an array. | ||
```js | ||
shuffle(Array arr) | ||
genid([Number length [, String prefix]]) | ||
``` | ||
@@ -595,11 +604,15 @@ | ||
```js | ||
import {shuffle} from 'bellajs'; | ||
import { genid } from 'bellajs' | ||
shuffle([1, 3, 8, 2, 5, 7]); | ||
genid() // => random 32 chars | ||
genid(16) // => random 16 chars | ||
genid(5) // => random 5 chars | ||
genid(5, 'X_') // => X_{random 3 chars} | ||
``` | ||
#### unique | ||
#### md5 | ||
```js | ||
unique(Array a) | ||
md5(String s) | ||
``` | ||
@@ -610,7 +623,8 @@ | ||
```js | ||
import {unique} from 'bellajs'; | ||
import { md5 } from 'bellajs' | ||
unique([1, 2, 3, 2, 3, 1, 5]); // => [ 1, 2, 3, 5 ] | ||
md5('abc') // => 900150983cd24fb0d6963f7d28e17f72 | ||
``` | ||
## Test | ||
@@ -617,0 +631,0 @@ |
22
reset.js
@@ -5,6 +5,6 @@ #!/usr/bin/env node | ||
existsSync, | ||
unlinkSync, | ||
} = require('fs'); | ||
unlinkSync | ||
} = require('fs') | ||
const {execSync} = require('child_process'); | ||
const { execSync } = require('child_process') | ||
@@ -17,4 +17,4 @@ const dirs = [ | ||
'node_modules', | ||
'.nuxt', | ||
]; | ||
'.nuxt' | ||
] | ||
@@ -25,13 +25,13 @@ const files = [ | ||
'package-lock.json', | ||
'coverage.lcov', | ||
]; | ||
'coverage.lcov' | ||
] | ||
dirs.forEach((d) => { | ||
execSync(`rm -rf ${d}`); | ||
}); | ||
execSync(`rm -rf ${d}`) | ||
}) | ||
files.forEach((f) => { | ||
if (existsSync(f)) { | ||
unlinkSync(f); | ||
unlinkSync(f) | ||
} | ||
}); | ||
}) |
195
src/main.js
@@ -10,91 +10,28 @@ /** | ||
isDate, | ||
hasProperty, | ||
} from './utils/detection'; | ||
isNil, | ||
hasProperty | ||
} from './utils/detection' | ||
export const curry = (fn) => { | ||
const totalArguments = fn.length; | ||
const next = (argumentLength, rest) => { | ||
if (argumentLength > 0) { | ||
return (...args) => { | ||
return next(argumentLength - args.length, [...rest, ...args]); | ||
}; | ||
} | ||
return fn(...rest); | ||
}; | ||
return next(totalArguments, []); | ||
}; | ||
export const compose = (...fns) => { | ||
return fns.reduce((f, g) => (x) => f(g(x))); | ||
}; | ||
export const pipe = (...fns) => { | ||
return fns.reduce((f, g) => (x) => g(f(x))); | ||
}; | ||
const defineProp = (ob, key, val, config = {}) => { | ||
const { | ||
writable = false, | ||
configurable = false, | ||
enumerable = false, | ||
} = config; | ||
Object.defineProperty(ob, key, { | ||
value: val, | ||
writable, | ||
configurable, | ||
enumerable, | ||
}); | ||
}; | ||
export const maybe = (val) => { | ||
const __val = val; | ||
const isNil = () => { | ||
return __val === null || __val === undefined; | ||
}; | ||
const value = () => { | ||
return __val; | ||
}; | ||
const getElse = (fn) => { | ||
return maybe(__val || fn()); | ||
}; | ||
const filter = (fn) => { | ||
return maybe(fn(__val) === true ? __val : null); | ||
}; | ||
const map = (fn) => { | ||
return maybe(isNil() ? null : fn(__val)); | ||
}; | ||
const output = Object.create({}); | ||
defineProp(output, '__value__', __val, {enumerable: true}); | ||
defineProp(output, '__type__', 'Maybe', {enumerable: true}); | ||
defineProp(output, 'isNil', isNil); | ||
defineProp(output, 'value', value); | ||
defineProp(output, 'map', map); | ||
defineProp(output, 'if', filter); | ||
defineProp(output, 'else', getElse); | ||
return output; | ||
}; | ||
export const clone = (val, history = null) => { | ||
const stack = history || new Set(); | ||
const stack = history || new Set() | ||
if (stack.has(val)) { | ||
return val; | ||
return val | ||
} | ||
stack.add(val); | ||
stack.add(val) | ||
if (isDate(val)) { | ||
return new Date(val.valueOf()); | ||
return new Date(val.valueOf()) | ||
} | ||
const copyObject = (o) => { | ||
const oo = Object.create({}); | ||
const oo = Object.create({}) | ||
for (const k in o) { | ||
if (hasProperty(o, k)) { | ||
oo[k] = clone(o[k], stack); | ||
oo[k] = clone(o[k], stack) | ||
} | ||
} | ||
return oo; | ||
}; | ||
return oo | ||
} | ||
@@ -104,78 +41,92 @@ const copyArray = (a) => { | ||
if (isArray(e)) { | ||
return copyArray(e); | ||
return copyArray(e) | ||
} else if (isObject(e)) { | ||
return copyObject(e); | ||
return copyObject(e) | ||
} | ||
return clone(e, stack); | ||
}); | ||
}; | ||
return clone(e, stack) | ||
}) | ||
} | ||
if (isArray(val)) { | ||
return copyArray(val); | ||
return copyArray(val) | ||
} | ||
if (isObject(val)) { | ||
return copyObject(val); | ||
return copyObject(val) | ||
} | ||
return val; | ||
}; | ||
return val | ||
} | ||
export const copies = (source, dest, matched = false, excepts = []) => { | ||
for (const k in source) { | ||
if (excepts.length > 0 && excepts.includes(k)) { | ||
continue; // eslint-disable-line no-continue | ||
continue // eslint-disable-line no-continue | ||
} | ||
if (!matched || matched && hasProperty(dest, k)) { | ||
const oa = source[k]; | ||
const ob = dest[k]; | ||
if (isObject(ob) && isObject(oa) || isArray(ob) && isArray(oa)) { | ||
dest[k] = copies(oa, dest[k], matched, excepts); | ||
if (!matched || (matched && hasProperty(dest, k))) { | ||
const oa = source[k] | ||
const ob = dest[k] | ||
if ((isObject(ob) && isObject(oa)) || (isArray(ob) && isArray(oa))) { | ||
dest[k] = copies(oa, dest[k], matched, excepts) | ||
} else { | ||
dest[k] = clone(oa); | ||
dest[k] = clone(oa) | ||
} | ||
} | ||
} | ||
return dest; | ||
}; | ||
return dest | ||
} | ||
export const unique = (arr = []) => { | ||
return [...new Set(arr)]; | ||
}; | ||
return [...new Set(arr)] | ||
} | ||
const fnSort = (a, b) => { | ||
return a > b ? 1 : a < b ? -1 : 0; | ||
}; | ||
return a > b ? 1 : (a < b ? -1 : 0) | ||
} | ||
export const sort = (arr = [], fn = fnSort) => { | ||
const tmp = [...arr]; | ||
tmp.sort(fn); | ||
return tmp; | ||
}; | ||
export const sort = (arr = [], sorting = null) => { | ||
const tmp = [...arr] | ||
const fn = sorting || fnSort | ||
tmp.sort(fn) | ||
return tmp | ||
} | ||
export const sortBy = (key, order = 1, arr = []) => { | ||
export const sortBy = (arr = [], order = 1, key = '') => { | ||
if (isNil(key)) { | ||
return arr | ||
} | ||
return sort(arr, (m, n) => { | ||
return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0); | ||
}); | ||
}; | ||
return m[key] > n[key] ? order : (m[key] < n[key] ? (-1 * order) : 0) | ||
}) | ||
} | ||
export const shuffle = (arr = []) => { | ||
return sort([...arr], () => { | ||
return Math.random() > 0.5; | ||
}); | ||
}; | ||
const input = [...arr] | ||
const output = [] | ||
let inputLen = input.length | ||
while (inputLen > 0) { | ||
const index = Math.floor(Math.random() * inputLen) | ||
output.push(input.splice(index, 1)[0]) | ||
inputLen-- | ||
} | ||
return output | ||
} | ||
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 const pick = (arr = [], count = 1) => { | ||
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'; | ||
export * from './utils/equals'; | ||
export * from './utils/string'; | ||
export * from './utils/random'; | ||
export * from './utils/date'; | ||
export * from './utils/md5'; | ||
export * from './utils/detection' | ||
export * from './utils/equals' | ||
export * from './utils/string' | ||
export * from './utils/random' | ||
export * from './utils/date' | ||
export * from './utils/md5' | ||
export * from './utils/curry' | ||
export * from './utils/compose' | ||
export * from './utils/pipe' | ||
export * from './utils/maybe' |
// utils / date | ||
import { | ||
isDate, | ||
isString, | ||
} from './detection'; | ||
isDate | ||
} from './detection' | ||
const PATTERN = 'D, M d, Y h:i:s A'; | ||
const PATTERN = 'D, M d, Y h:i:s A' | ||
const WEEKDAYS = [ | ||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', | ||
]; | ||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' | ||
] | ||
@@ -17,147 +15,141 @@ const MONTHS = [ | ||
'May', 'June', 'July', 'August', | ||
'September', 'October', 'November', 'December', | ||
]; | ||
'September', 'October', 'November', 'December' | ||
] | ||
export const now = () => { | ||
return new Date(); | ||
}; | ||
return new Date() | ||
} | ||
export const time = () => { | ||
return Date.now(); | ||
}; | ||
return Date.now() | ||
} | ||
const tzone = now().getTimezoneOffset(); | ||
const tzone = now().getTimezoneOffset() | ||
const tz = (() => { | ||
const z = Math.abs(tzone / 60); | ||
const sign = tzone < 0 ? '+' : '-'; | ||
return ['GMT', sign, String(z).padStart(4, '0')].join(''); | ||
})(); | ||
const z = Math.abs(tzone / 60) | ||
const sign = tzone < 0 ? '+' : '-' | ||
return ['GMT', sign, String(z).padStart(4, '0')].join('') | ||
})() | ||
const _num = (n) => { | ||
return String(n < 10 ? '0' + n : n); | ||
}; | ||
return String(n < 10 ? '0' + n : n) | ||
} | ||
const _ord = (day) => { | ||
let s = day + ' '; | ||
const x = s.charAt(s.length - 2); | ||
let s = day + ' ' | ||
const x = s.charAt(s.length - 2) | ||
if (x === '1') { | ||
s = 'st'; | ||
s = 'st' | ||
} else if (x === '2') { | ||
s = 'nd'; | ||
s = 'nd' | ||
} else if (x === '3') { | ||
s = 'rd'; | ||
s = 'rd' | ||
} else { | ||
s = 'th'; | ||
s = 'th' | ||
} | ||
return s; | ||
}; | ||
return s | ||
} | ||
export const toDateString = (input, output = PATTERN) => { | ||
const d = isDate(input) ? input : new Date(input); | ||
const d = isDate(input) ? input : new Date(input) | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
if (!isString(output)) { | ||
throw new Error('Invalid output pattern.'); | ||
} | ||
const vchar = /\.*\\?([a-z])/gi | ||
const meridiem = output.includes('a') || output.includes('A') | ||
const vchar = /\.*\\?([a-z])/gi; | ||
const meridiem = output.match(/(\.*)a{1}(\.*)*/i); | ||
const wn = WEEKDAYS | ||
const mn = MONTHS | ||
const wn = WEEKDAYS; | ||
const mn = MONTHS; | ||
/*eslint-disable */ | ||
let f = { | ||
Y() { | ||
return d.getFullYear(); // 2015 | ||
const f = { | ||
Y () { | ||
return d.getFullYear() // 2015 | ||
}, | ||
y() { | ||
return (f.Y() + '').slice(-2); // 15 | ||
y () { | ||
return (f.Y() + '').slice(-2) // 15 | ||
}, | ||
F() { | ||
return mn[f.n() - 1]; // August | ||
F () { | ||
return mn[f.n() - 1] // August | ||
}, | ||
M() { | ||
return (f.F() + '').slice(0, 3); // Aug | ||
M () { | ||
return (f.F() + '').slice(0, 3) // Aug | ||
}, | ||
m() { | ||
return _num(f.n()); // 08 | ||
m () { | ||
return _num(f.n()) // 08 | ||
}, | ||
n() { | ||
return d.getMonth() + 1; // 8 | ||
n () { | ||
return d.getMonth() + 1 // 8 | ||
}, | ||
S() { | ||
return _ord(f.j()); // st, nd, rd, th | ||
S () { | ||
return _ord(f.j()) // st, nd, rd, th | ||
}, | ||
j() { | ||
return d.getDate(); // 3 | ||
j () { | ||
return d.getDate() // 3 | ||
}, | ||
d() { | ||
return _num(f.j()); // 03 | ||
d () { | ||
return _num(f.j()) // 03 | ||
}, | ||
t() { | ||
return new Date(f.Y(), f.n(), 0).getDate(); // date in year | ||
t () { | ||
return new Date(f.Y(), f.n(), 0).getDate() // date in year | ||
}, | ||
w() { | ||
return d.getDay(); // weekday in number | ||
w () { | ||
return d.getDay() // weekday in number | ||
}, | ||
l() { | ||
return wn[f.w()]; // Sunday, Monday | ||
l () { | ||
return wn[f.w()] // Sunday, Monday | ||
}, | ||
D() { | ||
return (f.l() + '').slice(0, 3); // Sun, Mon | ||
D () { | ||
return (f.l() + '').slice(0, 3) // Sun, Mon | ||
}, | ||
G() { | ||
return d.getHours(); // 0 - 24 | ||
G () { | ||
return d.getHours() // 0 - 24 | ||
}, | ||
g() { | ||
return f.G() % 12 || 12; // 0 - 12 | ||
g () { | ||
return f.G() % 12 || 12 // 0 - 12 | ||
}, | ||
h() { | ||
return _num(meridiem ? f.g() : f.G()); // 00 - 12 or 00 - 24 | ||
h () { | ||
return _num(meridiem ? f.g() : f.G()) // 00 - 12 or 00 - 24 | ||
}, | ||
i() { | ||
return _num(d.getMinutes()); // 00 - 59 | ||
i () { | ||
return _num(d.getMinutes()) // 00 - 59 | ||
}, | ||
s() { | ||
return _num(d.getSeconds()); // 00 - 59 | ||
s () { | ||
return _num(d.getSeconds()) // 00 - 59 | ||
}, | ||
a() { | ||
return f.G() > 11 ? 'pm' : 'am'; // am, pm | ||
a () { | ||
return f.G() > 11 ? 'pm' : 'am' // am, pm | ||
}, | ||
A() { | ||
return f.a().toUpperCase(); // AM, PM | ||
A () { | ||
return f.a().toUpperCase() // AM, PM | ||
}, | ||
O() { | ||
return tz; | ||
O () { | ||
return tz | ||
} | ||
}; | ||
} | ||
/* eslint-enable */ | ||
const _term = (t, s) => { | ||
return f[t] ? f[t]() : s; | ||
}; | ||
return f[t] ? f[t]() : s | ||
} | ||
return output.replace(vchar, _term); | ||
}; | ||
return output.replace(vchar, _term) | ||
} | ||
export const toRelativeTime = (input = time()) => { | ||
const d = isDate(input) ? input : new Date(input); | ||
const d = isDate(input) ? input : new Date(input) | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
let delta = now() - d; | ||
let nowThreshold = parseInt(d, 10); | ||
let delta = now() - d | ||
let nowThreshold = parseInt(d, 10) | ||
if (isNaN(nowThreshold)) { | ||
nowThreshold = 0; | ||
nowThreshold = 0 | ||
} | ||
if (delta <= nowThreshold) { | ||
return 'Just now'; | ||
return 'Just now' | ||
} | ||
let units = null; | ||
let units = null | ||
const conversions = { | ||
@@ -170,36 +162,36 @@ millisecond: 1, | ||
month: 30, | ||
year: 12, | ||
}; | ||
year: 12 | ||
} | ||
for (const key in conversions) { | ||
if (delta < conversions[key]) { | ||
break; | ||
break | ||
} else { | ||
units = key; | ||
delta /= conversions[key]; | ||
units = key | ||
delta /= conversions[key] | ||
} | ||
} | ||
delta = Math.floor(delta); | ||
delta = Math.floor(delta) | ||
if (delta !== 1) { | ||
units += 's'; | ||
units += 's' | ||
} | ||
return [delta, units].join(' ') + ' ago'; | ||
}; | ||
return [delta, units].join(' ') + ' ago' | ||
} | ||
export const toUTCDateString = (input = time()) => { | ||
const d = isDate(input) ? input : new Date(input); | ||
const d = isDate(input) ? input : new Date(input) | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
const dMinutes = d.getMinutes(); | ||
const dClone = new Date(d); | ||
dClone.setMinutes(dMinutes + tzone); | ||
return `${toDateString(dClone, 'D, j M Y h:i:s')} GMT+0000`; | ||
}; | ||
const dMinutes = d.getMinutes() | ||
const dClone = new Date(d) | ||
dClone.setMinutes(dMinutes + tzone) | ||
return `${toDateString(dClone, 'D, j M Y h:i:s')} GMT+0000` | ||
} | ||
export const toLocalDateString = (input = time()) => { | ||
const d = isDate(input) ? input : new Date(input); | ||
const d = isDate(input) ? input : new Date(input) | ||
if (!isDate(d)) { | ||
throw new Error('InvalidInput: Number or Date required.'); | ||
throw new Error('InvalidInput: Number or Date required.') | ||
} | ||
return toDateString(d, 'D, j M Y h:i:s O'); | ||
}; | ||
return toDateString(d, 'D, j M Y h:i:s O') | ||
} |
// utils / detection | ||
const ob2Str = (val) => { | ||
return {}.toString.call(val); | ||
}; | ||
return {}.toString.call(val) | ||
} | ||
export const isInteger = (val) => { | ||
return Number.isInteger(val); | ||
}; | ||
return Number.isInteger(val) | ||
} | ||
export const isArray = (val) => { | ||
return Array.isArray(val); | ||
}; | ||
return Array.isArray(val) | ||
} | ||
export const isString = (val) => { | ||
return String(val) === val; | ||
}; | ||
return String(val) === val | ||
} | ||
export const isNumber = (val) => { | ||
return Number(val) === val; | ||
}; | ||
return Number(val) === val | ||
} | ||
export const isBoolean = (val) => { | ||
return Boolean(val) === val; | ||
}; | ||
return Boolean(val) === val | ||
} | ||
export const isNull = (val) => { | ||
return ob2Str(val) === '[object Null]'; | ||
}; | ||
return ob2Str(val) === '[object Null]' | ||
} | ||
export const isUndefined = (val) => { | ||
return ob2Str(val) === '[object Undefined]'; | ||
}; | ||
return ob2Str(val) === '[object Undefined]' | ||
} | ||
export const isNil = (val) => { | ||
return isUndefined(val) || isNull(val) | ||
} | ||
export const isFunction = (val) => { | ||
return ob2Str(val) === '[object Function]'; | ||
}; | ||
return ob2Str(val) === '[object Function]' | ||
} | ||
export const isObject = (val) => { | ||
return ob2Str(val) === '[object Object]' && !isArray(val); | ||
}; | ||
return ob2Str(val) === '[object Object]' && !isArray(val) | ||
} | ||
export const isDate = (val) => { | ||
return val instanceof Date && !isNaN(val.valueOf()); | ||
}; | ||
return val instanceof Date && !isNaN(val.valueOf()) | ||
} | ||
export const isElement = (v) => { | ||
return ob2Str(v).match(/^\[object HTML\w*Element]$/) !== null; | ||
}; | ||
return ob2Str(v).match(/^\[object HTML\w*Element]$/) !== null | ||
} | ||
export const isLetter = (val) => { | ||
const re = /^[a-z]+$/i; | ||
return isString(val) && re.test(val); | ||
}; | ||
const re = /^[a-z]+$/i | ||
return isString(val) && re.test(val) | ||
} | ||
export const isEmail = (val) => { | ||
const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | ||
return isString(val) && re.test(val); | ||
}; | ||
const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i | ||
return isString(val) && re.test(val) | ||
} | ||
export const isNil = (val) => { | ||
return isUndefined(val) || isNull(val); | ||
}; | ||
export const isEmpty = (val) => { | ||
return !val || isNil(val) || | ||
isString(val) && val === '' || | ||
isArray(val) && val.length === 0 || | ||
isObject(val) && Object.keys(val).length === 0; | ||
}; | ||
(isString(val) && val === '') || | ||
(isArray(val) && val.length === 0) || | ||
(isObject(val) && Object.keys(val).length === 0) | ||
} | ||
export const hasProperty = (ob, k) => { | ||
if (!ob || !k) { | ||
return false; | ||
return false | ||
} | ||
return Object.prototype.hasOwnProperty.call(ob, k); | ||
}; | ||
return Object.prototype.hasOwnProperty.call(ob, k) | ||
} |
@@ -7,55 +7,40 @@ // utils / equals | ||
isArray, | ||
isString, | ||
isNumber, | ||
isDate, | ||
hasProperty, | ||
} from './detection'; | ||
hasProperty | ||
} from './detection' | ||
export const equals = (a, b) => { | ||
let re = true; | ||
if (isEmpty(a) && isEmpty(b)) { | ||
return true; | ||
return true | ||
} | ||
if (isDate(a) && isDate(b)) { | ||
return a.getTime() === b.getTime(); | ||
return a.getTime() === b.getTime() | ||
} | ||
if (isNumber(a) && isNumber(b) || isString(a) && isString(b)) { | ||
return a === b; | ||
} | ||
if (isArray(a) && isArray(b)) { | ||
if (a.length !== b.length) { | ||
return false; | ||
return false | ||
} | ||
if (a.length > 0) { | ||
for (let i = 0, l = a.length; i < l; i++) { | ||
if (!equals(a[i], b[i])) { | ||
re = false; | ||
break; | ||
} | ||
let re = true | ||
for (let i = 0; i < a.length; i++) { | ||
if (!equals(a[i], b[i])) { | ||
re = false | ||
break | ||
} | ||
} | ||
} else if (isObject(a) && isObject(b)) { | ||
const as = []; | ||
const bs = []; | ||
for (const k1 in a) { | ||
if (hasProperty(a, k1)) { | ||
as.push(k1); | ||
} | ||
return re | ||
} | ||
if (isObject(a) && isObject(b)) { | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false | ||
} | ||
for (const k2 in b) { | ||
if (hasProperty(b, k2)) { | ||
bs.push(k2); | ||
} | ||
} | ||
if (as.length !== bs.length) { | ||
return false; | ||
} | ||
let re = true | ||
for (const k in a) { | ||
if (!hasProperty(b, k) || !equals(a[k], b[k])) { | ||
re = false; | ||
break; | ||
re = false | ||
break | ||
} | ||
} | ||
return re | ||
} | ||
return re; | ||
}; | ||
return a === b | ||
} |
@@ -70,2 +70,2 @@ // utils / md5 | ||
/* eslint-enable*/ | ||
/* eslint-enable */ |
// utils / random | ||
const MAX_NUMBER = Number.MAX_SAFE_INTEGER; | ||
const MAX_NUMBER = Number.MAX_SAFE_INTEGER | ||
export const randint = (min, max) => { | ||
if (!min || min < 0) { | ||
min = 0; | ||
min = 0 | ||
} | ||
if (!max) { | ||
max = MAX_NUMBER; | ||
max = MAX_NUMBER | ||
} | ||
if (min === max) { | ||
return max; | ||
return max | ||
} | ||
if (min > max) { | ||
min = Math.min(min, max); | ||
max = Math.max(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; | ||
}; | ||
const offset = min | ||
const range = max - min + 1 | ||
return Math.floor(Math.random() * range) + offset | ||
} |
@@ -7,37 +7,37 @@ // utils / string | ||
isNumber, | ||
hasProperty, | ||
} from './detection'; | ||
hasProperty | ||
} from './detection' | ||
import {randint} from './random'; | ||
import { randint } from './random' | ||
const toString = (input) => { | ||
const s = isNumber(input) ? String(input) : input; | ||
const s = isNumber(input) ? String(input) : input | ||
if (!isString(s)) { | ||
throw new Error('InvalidInput: String required.'); | ||
throw new Error('InvalidInput: String required.') | ||
} | ||
return s; | ||
}; | ||
return s | ||
} | ||
export const truncate = (s, l) => { | ||
const o = toString(s); | ||
const t = l || 140; | ||
const o = toString(s) | ||
const t = l || 140 | ||
if (o.length <= t) { | ||
return o; | ||
return o | ||
} | ||
let x = o.substring(0, t); | ||
const a = x.split(' '); | ||
const b = a.length; | ||
let r = ''; | ||
let x = o.substring(0, t) | ||
const a = x.split(' ') | ||
const b = a.length | ||
let r = '' | ||
if (b > 1) { | ||
a.pop(); | ||
r += a.join(' '); | ||
a.pop() | ||
r += a.join(' ') | ||
if (r.length < o.length) { | ||
r += '...'; | ||
r += '...' | ||
} | ||
} else { | ||
x = x.substring(0, t - 3); | ||
r = x + '...'; | ||
x = x.substring(0, t - 3) | ||
r = x + '...' | ||
} | ||
return r; | ||
}; | ||
return r | ||
} | ||
@@ -48,64 +48,64 @@ export const stripTags = (s) => { | ||
.replace(/\s\s+/g, ' ') | ||
.trim(); | ||
}; | ||
.trim() | ||
} | ||
export const escapeHTML = (s) => { | ||
const x = toString(s); | ||
const x = toString(s) | ||
return x.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
}; | ||
.replace(/"/g, '"') | ||
} | ||
export const unescapeHTML = (s) => { | ||
const x = toString(s); | ||
const x = toString(s) | ||
return x.replace(/"/g, '"') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/&/g, '&'); | ||
}; | ||
.replace(/&/g, '&') | ||
} | ||
export const ucfirst = (s) => { | ||
const x = toString(s).toLowerCase(); | ||
return x.length > 1 ? x.charAt(0).toUpperCase() + x.slice(1) : x.toUpperCase(); | ||
}; | ||
const x = toString(s).toLowerCase() | ||
return x.length > 1 ? x.charAt(0).toUpperCase() + x.slice(1) : x.toUpperCase() | ||
} | ||
export const ucwords = (s) => { | ||
return toString(s).split(' ').map((w) => { | ||
return ucfirst(w); | ||
}).join(' '); | ||
}; | ||
return ucfirst(w) | ||
}).join(' ') | ||
} | ||
export const replaceAll = (s, a, b) => { | ||
let x = toString(s); | ||
let x = toString(s) | ||
if (isNumber(a)) { | ||
a = String(a); | ||
a = String(a) | ||
} | ||
if (isNumber(b)) { | ||
b = String(b); | ||
b = String(b) | ||
} | ||
if (isString(a) && isString(b)) { | ||
const aa = x.split(a); | ||
x = aa.join(b); | ||
const aa = x.split(a) | ||
x = aa.join(b) | ||
} else if (isArray(a) && isString(b)) { | ||
a.forEach((v) => { | ||
x = replaceAll(x, v, b); | ||
}); | ||
x = replaceAll(x, v, b) | ||
}) | ||
} else if (isArray(a) && isArray(b) && a.length === b.length) { | ||
const k = a.length; | ||
const k = a.length | ||
if (k > 0) { | ||
for (let i = 0; i < k; i++) { | ||
const aaa = a[i]; | ||
const bb = b[i]; | ||
x = replaceAll(x, aaa, bb); | ||
const aaa = a[i] | ||
const bb = b[i] | ||
x = replaceAll(x, aaa, bb) | ||
} | ||
} | ||
} | ||
return x; | ||
}; | ||
return x | ||
} | ||
export const stripAccent = (s) => { | ||
let x = toString(s); | ||
let x = toString(s) | ||
@@ -128,41 +128,41 @@ const map = { | ||
y: 'ý|ỳ|ỷ|ỹ|ỵ', | ||
Y: 'Ý|Ỳ|Ỷ|Ỹ|Ỵ', | ||
}; | ||
Y: 'Ý|Ỳ|Ỷ|Ỹ|Ỵ' | ||
} | ||
const updateS = (ai, key) => { | ||
x = replaceAll(x, ai, key); | ||
}; | ||
x = replaceAll(x, ai, key) | ||
} | ||
for (const key in map) { | ||
if (hasProperty(map, key)) { | ||
const a = map[key].split('|'); | ||
const a = map[key].split('|') | ||
a.forEach((item) => { | ||
return updateS(item, key); | ||
}); | ||
return updateS(item, key) | ||
}) | ||
} | ||
} | ||
return x; | ||
}; | ||
return x | ||
} | ||
export const genid = (leng, prefix = '') => { | ||
const lc = 'abcdefghijklmnopqrstuvwxyz'; | ||
const uc = lc.toUpperCase(); | ||
const nb = '0123456789'; | ||
const lc = 'abcdefghijklmnopqrstuvwxyz' | ||
const uc = lc.toUpperCase() | ||
const nb = '0123456789' | ||
const cand = [ | ||
lc, | ||
uc, | ||
nb, | ||
nb | ||
].join('').split('').sort(() => { | ||
return Math.random() > 0.5; | ||
}).join(''); | ||
return Math.random() > 0.5 | ||
}).join('') | ||
const t = cand.length; | ||
const ln = Math.max(leng || 32, prefix.length); | ||
let s = prefix; | ||
const t = cand.length | ||
const ln = Math.max(leng || 32, prefix.length) | ||
let s = prefix | ||
while (s.length < ln) { | ||
const k = randint(0, t); | ||
s += cand.charAt(k) || ''; | ||
const k = randint(0, t) | ||
s += cand.charAt(k) || '' | ||
} | ||
return s; | ||
}; | ||
return s | ||
} | ||
@@ -175,3 +175,3 @@ export const slugify = (s, delimiter = '-') => { | ||
.replace(/\s+/g, ' ') | ||
.replace(/\s/g, delimiter); | ||
}; | ||
.replace(/\s/g, delimiter) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
617
2
2
98432
32
2512