Comparing version 4.1.5 to 5.0.0
{ | ||
"version": "4.1.5", | ||
"version": "5.0.0", | ||
"name": "bellajs", | ||
@@ -16,11 +16,20 @@ "description": "A useful helper for any javascript program", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --reporter nyan --timeout 5000", | ||
"coverage": "./node_modules/.bin/nyc --require traceur mocha", | ||
"report": "./node_modules/.bin/nyc report --reporter=lcov" | ||
"test": "./node_modules/.bin/tape test/start.js | tap-spec", | ||
"coverage": "./node_modules/.bin/nyc tape test/start.js | tap-spec", | ||
"report": "npm run coverage && ./node_modules/.bin/nyc report --reporter=lcov", | ||
"coveralls": "npm run report && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls", | ||
"build": "node build/minify" | ||
}, | ||
"devDependencies": { | ||
"chai": "latest", | ||
"mocha": "latest", | ||
"chance": "latest", | ||
"cheerio": "latest", | ||
"colors": "latest", | ||
"coveralls": "latest", | ||
"is": "latest", | ||
"mkdirp": "latest", | ||
"nyc": "latest", | ||
"traceur": "latest" | ||
"request": "latest", | ||
"sinon": "latest", | ||
"tap-spec": "latest", | ||
"tape": "latest" | ||
}, | ||
@@ -27,0 +36,0 @@ "keywords": [ |
152
README.md
@@ -7,2 +7,4 @@ bella.js | ||
[](https://badge.fury.io/js/bellajs)  | ||
[](https://coveralls.io/github/ndaidong/bella.js?branch=master) | ||
 | ||
@@ -13,14 +15,9 @@ # Contents | ||
* [Setup](#setup) | ||
* [Usage](#usage) | ||
* [Methods](#methods) | ||
* [DataType detection](#datatype-detection) | ||
* [String manipulation](#string-manipulation) | ||
* [Template manipulation](#template-manipulation) | ||
* [Array & Object](#array--object) | ||
* [DateTime](#datetime) | ||
* [Scheduler](#scheduler) | ||
* [Cookies accessing](#cookies-accessing) | ||
* [DOM & Event manipulation](#dom--event-manipulation) | ||
* [Other methods](#other-methods) | ||
* [Properties](#properties) | ||
* [APIs](#apis) | ||
* [DataType detection](#datatype-detection) | ||
* [String manipulation](#string-manipulation) | ||
* [Template manipulation](#template-manipulation) | ||
* [Array & Object](#array--object) | ||
* [DateTime](#datetime) | ||
* [Scheduler](#scheduler) | ||
* [Test](#test) | ||
@@ -31,2 +28,8 @@ | ||
#### v5.0.0 - Apr 18, 2016 | ||
- Build with Google Closure compiler | ||
- Refactor scheduler's features | ||
- Rewrite in ES6 syntax | ||
- Remove browser side features | ||
#### v4.1.5 - Mar 18, 2016 | ||
@@ -135,6 +138,4 @@ - Implement nyc/istanbul to check test coverage | ||
# Usage | ||
# APIs | ||
## Methods | ||
### DataType detection | ||
@@ -407,117 +408,3 @@ - Bella.isArray(Anything val) | ||
The following sub objects are not available in Node.js environment. | ||
### Cookies accessing | ||
- Bella.cookie.set(String name, String value, String expires, String domain, String path) | ||
- Bella.cookie.get(String name) | ||
- Bella.cookie.unset(String name) | ||
The keywords "name", "value", "expires", "domain" and "path" are steadfast. | ||
Bella.cookie.set also accepts an object. Its first two parameters are required, while the third parameter is a string in the format of "N units", such as 2d (2 days), 6h (6 hours), -30m (30 minutes ago), etc... | ||
Examples: | ||
``` | ||
// set a cookie | ||
Bella.cookie.set('userid', 'A98kja8967jkqwKOL'); | ||
// another way | ||
Bella.cookie.set({ | ||
name: 'userid', | ||
value: 'A98kja8967jkqwKOL' | ||
}); | ||
// get its value | ||
var userid = Bella.cookie.get('userid'); | ||
// unset it | ||
Bella.cookie.unset('userid'); | ||
``` | ||
### DOM & Event manipulation | ||
- Bella.dom.ready(Function callback) | ||
- Bella.dom.one(String selectors) | ||
- Bella.dom.all(String selectors) | ||
- Bella.dom.get(String ID) | ||
- Bella.dom.add(Element|String tag [, Element parent]) | ||
- Bella.dom.create(Element dom) | ||
- Bella.event.on(String|Element s, String eventName, Function callback) | ||
- Bella.event.off(String|Element s, String eventName, Function callback) | ||
- Bella.event.simulate(String|Element s, String eventName) | ||
- Bella.event.stop(Event e) | ||
- Bella.event.detect(Event e) | ||
The HTML DOM Element returned by Bella.dom's methods have several helpful functions as below: | ||
- hasClass(String className) | ||
- addClass(String className) | ||
- removeClass(String className) | ||
- toggleClass(String className) | ||
- html([String html]) | ||
- empty() | ||
- destroy() | ||
Using native selector, BellaJS DOM is faster than many other DOM manipulation libraries: http://jsperf.com/bellajs-dom/2 | ||
Examples: | ||
``` | ||
Bella.dom.ready(function(){ | ||
// Add a new element to document.body | ||
var container = Bella.dom.add('DIV'); | ||
// then add a DIV element into container | ||
var div1 = Bella.dom.add('DIV', container); | ||
// then add a class "sub-item" to child DIV | ||
div1.addClass('sub-item'); | ||
// more a child DIV | ||
var div2 = Bella.dom.add('DIV', container); | ||
// also add a class "sub-item" | ||
div2.addClass('sub-item'); | ||
// now, we can extract list of elements by class name: | ||
var subItems = Bella.dom.all('.sub-item'); | ||
console.log(subItems); | ||
// create a button | ||
var btn = Bella.dom.add('BUTTON'); | ||
// set label | ||
btn.html('Say Hello!'); | ||
// set an event listener | ||
Bella.event.on(btn, 'click', function(){ | ||
alert('Hello! How it\'s going?'); | ||
}); | ||
// simulate a click event on there (it works as same as jQuery.trigger method) | ||
Bella.event.simulate(btn, 'click'); | ||
}); | ||
``` | ||
### Other methods | ||
- Bella.getMousePosition(event) // browser only | ||
- Bella.getWindowSize // browser only | ||
## Properties | ||
- Bella.id | ||
- Bella.hostname // browser only | ||
# Test | ||
@@ -531,9 +418,4 @@ | ||
// test | ||
npm run build | ||
npm test | ||
// test coverage | ||
npm run coverage | ||
// generate coverage report | ||
npm run report | ||
``` | ||
@@ -540,0 +422,0 @@ |
1864
src/bella.js
@@ -6,15 +6,15 @@ /** | ||
(function init(context) { | ||
'use strict'; | ||
var Bella = { | ||
ENV: 'browser' | ||
(() => { | ||
var ENV = typeof module !== 'undefined' && module.exports ? 'node' : 'browser'; | ||
var B = { | ||
ENV: ENV | ||
}; | ||
if (typeof module !== 'undefined' && module.exports) { | ||
Bella.ENV = 'node'; | ||
} | ||
function tof(v) { | ||
var ots = Object.prototype.toString; | ||
var s = typeof v; | ||
var tof = (v) => { | ||
let ots = Object.prototype.toString; | ||
let s = typeof v; | ||
if (s === 'object') { | ||
@@ -45,3 +45,3 @@ if (v) { | ||
} | ||
return 'null'; | ||
return 'object'; | ||
} else if (s === 'function' && typeof v.call === 'undefined') { | ||
@@ -51,128 +51,452 @@ return 'object'; | ||
return s; | ||
} | ||
}; | ||
function isDef(val) { | ||
var isDef = (val) => { | ||
return tof(val) !== 'undefined'; | ||
} | ||
function isNull(val) { | ||
}; | ||
var isNull = (val) => { | ||
return tof(val) === null || val === null; | ||
} | ||
}; | ||
function isString(val) { | ||
var isString = (val) => { | ||
return !isNull(val) && tof(val) === 'string'; | ||
} | ||
function isNumber(val) { | ||
}; | ||
var isNumber = (val) => { | ||
return val !== '' && !isNull(val) && isDef(val) && !isNaN(val) && tof(val) === 'number'; | ||
} | ||
function isInteger(val) { | ||
}; | ||
var isInteger = (val) => { | ||
return isNumber(val) && isFinite(val) && Math.floor(val) === val; | ||
} | ||
function isBoolean(val) { | ||
}; | ||
var isBoolean = (val) => { | ||
return val === true || val === false; | ||
} | ||
function isArray(val) { | ||
}; | ||
var isArray = (val) => { | ||
return !isNull(val) && tof(val) === 'array'; | ||
} | ||
function isFunction(val) { | ||
}; | ||
var isObject = (val) => { | ||
return !isNull(val) && tof(val) === 'object'; | ||
}; | ||
var isDate = (val) => { | ||
return val instanceof Date && !isNaN(val.valueOf()); | ||
}; | ||
var isFunction = (val) => { | ||
return !isNull(val) && tof(val) === 'function'; | ||
} | ||
function isElement(val) { | ||
}; | ||
var isElement = (val) => { | ||
if (val && ENV === 'node' && val._root) { | ||
return true; | ||
} | ||
return !isNull(val) && tof(val) === 'element'; | ||
} | ||
function isObject(val) { | ||
return !isNull(val) && typeof val === 'object'; | ||
} | ||
function isDate(val) { | ||
return val instanceof Date && !isNaN(val.valueOf()); | ||
} | ||
function isEmpty(val) { | ||
return !isDef(val) || isNull(val) || | ||
isString(val) && val === '' || | ||
isArray(val) && JSON.stringify(val) === '[]' || | ||
isObject(val) && JSON.stringify(val) === '{}'; | ||
} | ||
function isLetter(val) { | ||
var re = /^[a-z]+$/i; | ||
}; | ||
var isLetter = (val) => { | ||
let re = /^[a-z]+$/i; | ||
return isString(val) && re.test(val); | ||
} | ||
function isEmail(val) { | ||
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | ||
}; | ||
var isEmail = (val) => { | ||
let re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | ||
return isString(val) && re.test(val); | ||
} | ||
function isGeneratedKey(val) { | ||
var re = /^[A-Z0-9]+$/i; | ||
}; | ||
var isGeneratedKey = (val) => { | ||
let re = /^[A-Z0-9]+$/i; | ||
return isString(val) && re.test(val); | ||
} | ||
}; | ||
var isEmpty = (val) => { | ||
return !isDef(val) || isNull(val) | ||
|| isString(val) && val === '' | ||
|| isArray(val) && JSON.stringify(val) === '[]' | ||
|| isObject(val) && JSON.stringify(val) === '{}'; | ||
}; | ||
var hasProperty = (ob, k) => { | ||
if (!ob || !k) { | ||
return false; | ||
} | ||
let r = true; | ||
if (!isDef(ob[k])) { | ||
r = k in ob; | ||
} | ||
return r; | ||
}; | ||
var equals = (a, b) => { | ||
let re = true; | ||
if (isEmpty(a) && isEmpty(b)) { | ||
return true; | ||
} | ||
if (isDate(a) && isDate(b)) { | ||
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; | ||
} | ||
if (a.length > 0) { | ||
for (let i = 0, l = a.length; i < l; i++) { | ||
if (!equals(a[i], b[i])) { | ||
re = false; | ||
break; | ||
} | ||
} | ||
} | ||
} else if (isObject(a) && isObject(b)) { | ||
let as = [], bs = []; | ||
for (let k1 in a) { | ||
if (hasProperty(a, k1)) { | ||
as.push(k1); | ||
} | ||
} | ||
for (let k2 in b) { | ||
if (hasProperty(b, k2)) { | ||
bs.push(k2); | ||
} | ||
} | ||
if (as.length !== bs.length) { | ||
return false; | ||
} | ||
for (let k in a) { | ||
if (!hasProperty(b, k) || !equals(a[k], b[k])) { | ||
re = false; | ||
break; | ||
} | ||
} | ||
} | ||
return re; | ||
}; | ||
Bella.isDef = isDef; | ||
Bella.isNull = isNull; | ||
Bella.isEmpty = isEmpty; | ||
Bella.isBoolean = isBoolean; | ||
Bella.isArray = isArray; | ||
Bella.isString = isString; | ||
Bella.isNumber = isNumber; | ||
Bella.isFunction = isFunction; | ||
Bella.isElement = isElement; | ||
Bella.isObject = isObject; | ||
Bella.isDate = isDate; | ||
Bella.isLetter = isLetter; | ||
Bella.isInteger = isInteger; | ||
Bella.isEmail = isEmail; | ||
Bella.isGeneratedKey = isGeneratedKey; | ||
B.isDef = isDef; | ||
B.isNull = isNull; | ||
B.isString = isString; | ||
B.isNumber = isNumber; | ||
B.isInteger = isInteger; | ||
B.isBoolean = isBoolean; | ||
B.isArray = isArray; | ||
B.isObject = isObject; | ||
B.isDate = isDate; | ||
B.isFunction = isFunction; | ||
B.isElement = isElement; | ||
B.isEmpty = isEmpty; | ||
B.isLetter = isLetter; | ||
B.isEmail = isEmail; | ||
B.isGeneratedKey = isGeneratedKey; | ||
B.hasProperty = hasProperty; | ||
B.equals = equals; | ||
function createId(leng, prefix) { | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
var createId = (leng, prefix) => { | ||
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
chars += chars.toLowerCase(); | ||
chars += '0123456789'; | ||
var t = chars.length; | ||
var px = prefix || ''; | ||
var ln = Math.max(leng || 32, px.length); | ||
var s = px; | ||
let t = chars.length; | ||
let px = prefix || ''; | ||
let ln = Math.max(leng || 32, px.length); | ||
let s = px; | ||
while (s.length < ln) { | ||
var k = Math.floor(Math.random() * t); | ||
let k = Math.floor(Math.random() * t); | ||
s += chars.charAt(k) || ''; | ||
} | ||
return s; | ||
} | ||
}; | ||
Bella.id = createId(32); | ||
Bella.createId = createId; | ||
var random = (min, max) => { | ||
if (!min || min < 0) { | ||
min = 0; | ||
} | ||
if (!max) { | ||
max = 9007199254740991; | ||
} | ||
if (min === max) { | ||
return max; | ||
} | ||
if (min > max) { | ||
min = Math.min(min, max); | ||
max = Math.max(min, max); | ||
} | ||
let offset = min; | ||
let range = max - min + 1; | ||
let rd = Math.floor(Math.random() * range) + offset; | ||
return rd; | ||
}; | ||
var max = (a) => { | ||
return isArray(a) ? Math.max.apply({}, a) : a; | ||
}; | ||
// string | ||
Bella.encode = function encode(s) { | ||
s = String(s); | ||
var min = (a) => { | ||
return isArray(a) ? Math.min.apply({}, a) : a; | ||
}; | ||
var empty = (a) => { | ||
if (isArray(a)) { | ||
for (let i = a.length - 1; i >= 0; i--) { | ||
a[i] = null; | ||
delete a[i]; | ||
} | ||
a.length = 0; | ||
} else if (isObject(a)) { | ||
for (let k in a) { | ||
if (B.hasProperty(a, k)) { | ||
a[k] = null; | ||
delete a[k]; | ||
} | ||
} | ||
} else if (isString(a)) { | ||
a = ''; | ||
} else if (isElement(a)) { | ||
a.innerHTML = ''; | ||
} | ||
return a; | ||
}; | ||
var unique = (a) => { | ||
if (isArray(a)) { | ||
let r = []; | ||
for (let i = 0; i < a.length; i++) { | ||
if (r.indexOf(a[i]) === -1) { | ||
r.push(a[i]); | ||
} | ||
} | ||
return r; | ||
} | ||
return a || []; | ||
}; | ||
var contains = (a, el, key) => { | ||
if (isArray(a)) { | ||
for (let i = 0; i < a.length; i++) { | ||
var val = a[i]; | ||
if (key && val[key] === el[key] || val === el) { | ||
return true; | ||
} | ||
} | ||
} else if (isObject(a) && isString(el)) { | ||
return hasProperty(a, el); | ||
} else if (isString(a) && isString(el)) { | ||
return a.includes(el); | ||
} | ||
return false; | ||
}; | ||
var first = (a) => { | ||
return a[0]; | ||
}; | ||
var last = (a) => { | ||
return a[a.length - 1]; | ||
}; | ||
var getIndex = (item, arr) => { | ||
let r = -1; | ||
for (let i = 0; i < arr.length; i++) { | ||
if (arr[i] === item) { | ||
r = i; | ||
break; | ||
} | ||
} | ||
return r; | ||
}; | ||
var getLastIndex = (item, arr) => { | ||
let r = -1; | ||
for (let i = arr.length - 1; i >= 0; i--) { | ||
if (arr[i] === item) { | ||
r = i; | ||
break; | ||
} | ||
} | ||
return r; | ||
}; | ||
var clone = (obj) => { | ||
if (!isObject(obj) && !isArray(obj) && !isDate(obj)) { | ||
return obj; | ||
} | ||
if (isDate(obj)) { | ||
let copy1 = new Date(); | ||
copy1.setTime(obj.getTime()); | ||
return copy1; | ||
} | ||
if (isArray(obj)) { | ||
let copy2 = [], arr = obj.slice(0); | ||
for (let i = 0, len = arr.length; i < len; ++i) { | ||
copy2[i] = clone(arr[i]); | ||
} | ||
return copy2; | ||
} | ||
if (isObject(obj)) { | ||
let copy = {}; | ||
for (let attr in obj) { | ||
if (attr === 'clone') { | ||
continue; | ||
} | ||
if (obj.hasOwnProperty(attr)) { | ||
copy[attr] = clone(obj[attr]); | ||
} | ||
} | ||
return copy; | ||
} | ||
return obj; | ||
}; | ||
var copies = (source, dest, matched, excepts) => { | ||
let mt = matched || false; | ||
let ex = excepts || []; | ||
for (let k in source) { | ||
if (ex.length > 0 && contains(ex, k)) { | ||
continue; | ||
} | ||
if (!mt || mt && dest.hasOwnProperty(k)) { | ||
let oa = source[k]; | ||
let ob = dest[k]; | ||
if (isObject(ob) && isObject(oa) || isArray(ob) && isArray(oa)) { | ||
dest[k] = copies(oa, dest[k], mt, ex); | ||
} else { | ||
dest[k] = oa; | ||
} | ||
} | ||
} | ||
return dest; | ||
}; | ||
var sort = (arr, opts) => { | ||
let a = []; | ||
let one = {}; | ||
let o = opts || 1; | ||
if (isArray(arr) && arr.length > 0) { | ||
a = clone(arr); | ||
one = a[0]; | ||
if (o === 1 || o === -1) { | ||
a.sort((m, n) => { | ||
return m > n ? o : m < n ? -1 * o : 0; | ||
}); | ||
} else if (isString(o) && hasProperty(one, o)) { | ||
a.sort((m, n) => { | ||
return m[o] > n[o] ? 1 : m[o] < n[o] ? -1 : 0; | ||
}); | ||
} else if (isObject(o)) { | ||
for (let key in o) { | ||
if (hasProperty(one, key)) { | ||
let order = o[key] === -1 ? -1 : 1; | ||
/*eslint-disable*/ | ||
a.sort((m, n) => { | ||
return (m[key] > n[key]) ? order : (m[key] < n[key] ? (-1 * order) : 0); | ||
}); | ||
/*eslint-enable*/ | ||
} | ||
} | ||
} | ||
} | ||
return a; | ||
}; | ||
var shuffle = (arr) => { | ||
let a = clone(arr); | ||
let j, x, i; | ||
for (i = a.length - 1; i >= 0; i--) { | ||
j = Math.floor(Math.random() * i); | ||
x = a[i - 1]; | ||
a[i - 1] = a[j]; | ||
a[j] = x; | ||
} | ||
return a; | ||
}; | ||
var pick = (arr, count) => { | ||
let c = count ? Math.min(count, arr.length) : 1; | ||
if (c < 1) { | ||
c = 1; | ||
} | ||
if (c >= arr.length) { | ||
return arr; | ||
} | ||
if (c === 1) { | ||
let ri = random(0, arr.length - 1); | ||
return arr[ri]; | ||
} | ||
let ab = [], ba = clone(arr); | ||
while (ab.length < c) { | ||
let i = random(0, ba.length - 1); | ||
ab.push(ba[i]); | ||
ba.splice(i, 1); | ||
} | ||
return ab; | ||
}; | ||
var debounce = (fn, wait, immediate) => { | ||
let timeout; | ||
return () => { | ||
let later = () => { | ||
timeout = null; | ||
if (!immediate) { | ||
fn(); | ||
} | ||
}; | ||
let callNow = immediate && !timeout; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait || 200); | ||
if (callNow) { | ||
fn(); | ||
} | ||
}; | ||
}; | ||
var throttle = (fn, wait) => { | ||
return debounce(fn, wait, true); | ||
}; | ||
B.id = createId(); | ||
B.createId = createId; | ||
B.random = random; | ||
B.min = min; | ||
B.max = max; | ||
B.unique = unique; | ||
B.contains = contains; | ||
B.first = first; | ||
B.last = last; | ||
B.getIndex = getIndex; | ||
B.getLastIndex = getLastIndex; | ||
B.sort = sort; | ||
B.shuffle = shuffle; | ||
B.pick = pick; | ||
B.empty = empty; | ||
B.copies = copies; | ||
B.clone = clone; | ||
B.debounce = debounce; | ||
B.throttle = throttle; | ||
/*eslint-disable*/ | ||
/** https://github.com/jbt/js-crypto */ | ||
B.md5 = function() {for(var m=[],l=0;64>l;)m[l]=0|4294967296*Math.abs(Math.sin(++l));return function(c) {var e,g,f,a,h=[];c=unescape(encodeURI(c));for(var b=c.length,k=[e=1732584193,g=-271733879,~e,~g],d=0;d<=b;)h[d>>2]|=(c.charCodeAt(d)||128)<<8*(d++%4);h[c=16*(b+8>>6)+14]=8*b;for(d=0;d<c;d+=16) {b=k;for(a=0;64>a;)b=[f=b[3],(e=b[1]|0)+((f=b[0]+[e&(g=b[2])|~e&f,f&e|~f&g,e^g^f,g^(e|~f)][b=a>>4]+(m[a]+(h[[a,5*a+1,3*a+5,7*a][b]%16+d]|0)))<<(b=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*b+a++%4])|f>>>32-b),e,g];for(a=4;a;)k[--a]=k[a]+b[a]}for(c="";32>a;)c+=(k[a>>3]>>4*(1^a++&7)&15).toString(16);return c}}(); | ||
/*eslint-enable*/ | ||
var encode = (s) => { | ||
return isString(s) ? encodeURIComponent(s) : ''; | ||
}; | ||
Bella.decode = function decode(s) { | ||
s = String(s); | ||
var decode = (s) => { | ||
return isString(s) ? decodeURIComponent(s.replace(/\+/g, ' ')) : ''; | ||
}; | ||
Bella.trim = function trim(s) { | ||
s = String(s); | ||
return s && isString(s) ? s.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '') : s || ''; | ||
}; | ||
Bella.truncate = function truncate(s, l) { | ||
s = String(s); | ||
if (!s || !isString(s)) { | ||
var trim = (s, all) => { | ||
if (!isString(s)) { | ||
return ''; | ||
} | ||
s = Bella.trim(s); | ||
let x = s ? s.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '') : s || ''; | ||
if (x && all) { | ||
return x.replace(/\r?\n|\r/g, ' ').replace(/\s\s+|\r/g, ' '); | ||
} | ||
return x; | ||
}; | ||
if (s === '') { | ||
var truncate = (s, l) => { | ||
s = trim(s); | ||
if (!s) { | ||
return s; | ||
} | ||
var t = l || 140; | ||
let t = l || 140; | ||
if (s.length <= t) { | ||
return s; | ||
} | ||
var x = s.substring(0, t); | ||
var a = x.split(' '), b = a.length, r = ''; | ||
let x = s.substring(0, t); | ||
let a = x.split(' '), b = a.length, r = ''; | ||
if (b > 1) { | ||
@@ -186,3 +510,3 @@ a.pop(); | ||
x = x.substring(0, t - 3); | ||
r += '...'; | ||
r = x + '...'; | ||
} | ||
@@ -192,7 +516,9 @@ return r; | ||
Bella.stripTags = function stripTags(s) { | ||
s = String(s); | ||
var r = isString(s) ? s.replace(/<.*?>/gi, ' ') : ''; | ||
var stripTags = (s) => { | ||
if (!isString(s)) { | ||
return ''; | ||
} | ||
let r = s.replace(/<.*?>/gi, ' '); | ||
if (r) { | ||
r = Bella.trim(r.replace(/\s\s+/g, ' ')); | ||
r = trim(r.replace(/\s\s+/g, ' ')); | ||
} | ||
@@ -202,4 +528,3 @@ return r; | ||
Bella.escapeHTML = function escapeHTML(s) { | ||
s = String(s); | ||
var escapeHTML = (s) => { | ||
if (!isString(s)) { | ||
@@ -211,4 +536,3 @@ return ''; | ||
Bella.unescapeHTML = function unescapeHTML(s) { | ||
s = String(s); | ||
var unescapeHTML = (s) => { | ||
if (!isString(s)) { | ||
@@ -220,14 +544,14 @@ return ''; | ||
Bella.strtolower = function strtolower(s) { | ||
s = String(s); | ||
var strtolower = (s) => { | ||
return isString(s) ? s.toLowerCase() : ''; | ||
}; | ||
Bella.strtoupper = function strtoupper(s) { | ||
s = String(s); | ||
var strtoupper = (s) => { | ||
return isString(s) ? s.toUpperCase() : ''; | ||
}; | ||
Bella.ucfirst = function ucfirst(s) { | ||
s = String(s); | ||
var ucfirst = (s) => { | ||
if (!isString(s)) { | ||
return ''; | ||
} | ||
if (s.length === 1) { | ||
@@ -240,40 +564,36 @@ return s.toUpperCase(); | ||
Bella.ucwords = function ucwords(s) { | ||
s = String(s); | ||
if (isString(s)) { | ||
var c = s.split(' '), a = []; | ||
c.forEach(function fix(w) { | ||
a.push(Bella.ucfirst(w)); | ||
}); | ||
return a.join(' '); | ||
var ucwords = (s) => { | ||
if (!isString(s)) { | ||
return ''; | ||
} | ||
return s; | ||
let c = s.split(' '), a = []; | ||
c.forEach((w) => { | ||
a.push(ucfirst(w)); | ||
}); | ||
return a.join(' '); | ||
}; | ||
Bella.leftPad = function leftPad(s, size, spad) { | ||
s = String(s); | ||
if (isString(s)) { | ||
var g = spad || '0'; | ||
var o = String(s); | ||
var z = size || 2; | ||
return o.length >= z ? o : new Array(z - o.length + 1).join(g) + o; | ||
} | ||
return ''; | ||
var leftPad = (s, size, spad) => { | ||
let o = String(s); | ||
let z = size || 2; | ||
let g = spad || '0'; | ||
return o.length >= z ? o : new Array(z - o.length + 1).join(g) + o; | ||
}; | ||
Bella.rightPad = function rightPad(s, size, spad) { | ||
s = String(s); | ||
if (isString(s)) { | ||
var g = spad || '0'; | ||
var o = String(s); | ||
var z = size || 2; | ||
return o.length >= z ? o : o + new Array(z - o.length + 1).join(g); | ||
} | ||
return ''; | ||
var rightPad = (s, size, spad) => { | ||
let o = String(s); | ||
let z = size || 2; | ||
let g = spad || '0'; | ||
return o.length >= z ? o : o + new Array(z - o.length + 1).join(g); | ||
}; | ||
Bella.replaceAll = function replaceAll(s, a, b) { | ||
if (!isString(s)) { | ||
var replaceAll = (s, a, b) => { | ||
if (isNumber(s)) { | ||
s = String(s); | ||
} | ||
if (!s || !isString(s)) { | ||
return ''; | ||
} | ||
if (isNumber(a)) { | ||
@@ -287,14 +607,14 @@ a = String(a); | ||
if (isString(a) && isString(b)) { | ||
var aa = s.split(a); | ||
let aa = s.split(a); | ||
s = aa.join(b); | ||
} else if (isArray(a) && isString(b)) { | ||
a.forEach(function fix(v) { | ||
s = Bella.replaceAll(s, v, b); | ||
a.forEach((v) => { | ||
s = replaceAll(s, v, b); | ||
}); | ||
} else if (isArray(a) && isArray(b) && a.length === b.length) { | ||
var k = a.length; | ||
let k = a.length; | ||
if (k > 0) { | ||
for (var i = 0; i < k; i++) { | ||
var aaa = a[i], bb = b[i]; | ||
s = Bella.replaceAll(s, aaa, bb); | ||
for (let i = 0; i < k; i++) { | ||
let aaa = a[i], bb = b[i]; | ||
s = replaceAll(s, aaa, bb); | ||
} | ||
@@ -306,5 +626,10 @@ } | ||
Bella.stripAccent = function stripAccent(s) { | ||
s = String(s); | ||
var map = { | ||
var stripAccent = (s) => { | ||
if (isNumber(s)) { | ||
return String(s); | ||
} | ||
if (!isString(s)) { | ||
return ''; | ||
} | ||
let map = { | ||
a: 'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|ä', | ||
@@ -327,7 +652,7 @@ A: 'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Ä', | ||
}; | ||
for (var key in map) { | ||
if (Bella.hasProperty(map, key)) { | ||
var a = map[key].split('|'); | ||
for (var i = 0; i < a.length; i++) { | ||
s = Bella.replaceAll(s, a[i], key); | ||
for (let key in map) { | ||
if (hasProperty(map, key)) { | ||
let a = map[key].split('|'); | ||
for (let i = 0; i < a.length; i++) { | ||
s = replaceAll(s, a[i], key); | ||
} | ||
@@ -339,9 +664,9 @@ } | ||
Bella.createAlias = function createAlias(s, delimiter) { | ||
var createAlias = (s, delimiter) => { | ||
s = String(s); | ||
var x = Bella.stripAccent(s); | ||
let x = stripAccent(s); | ||
if (x) { | ||
var d = delimiter || '-'; | ||
x = Bella.strtolower(x); | ||
x = Bella.trim(x); | ||
let d = delimiter || '-'; | ||
x = strtolower(x); | ||
x = trim(x); | ||
x = x.replace(/\W+/g, ' '); | ||
@@ -354,18 +679,21 @@ x = x.replace(/\s+/g, ' '); | ||
Bella.compile = function comp(tpl, data) { | ||
var ns = []; | ||
function compile(s, ctx, namespace) { | ||
var template = (tpl, data) => { | ||
let ns = []; | ||
let compile = (s, ctx, namespace) => { | ||
if (namespace) { | ||
ns.push(namespace); | ||
} | ||
var a = []; | ||
for (var k in ctx) { | ||
if (Bella.hasProperty(ctx, k)) { | ||
var v = ctx[k]; | ||
let a = []; | ||
for (let k in ctx) { | ||
if (hasProperty(ctx, k)) { | ||
let v = ctx[k]; | ||
if (isObject(v) || isArray(v)) { | ||
a.push({ key: k, data: v }); | ||
a.push({ | ||
key: k, | ||
data: v | ||
}); | ||
} else if (isString(v)) { | ||
v = Bella.replaceAll(v, [ '{', '}' ], [ '{', '}' ]); | ||
var cns = ns.concat([ k ]); | ||
var r = new RegExp('{' + cns.join('.') + '}', 'gi'); | ||
v = replaceAll(v, [ '{', '}' ], [ '{', '}' ]); | ||
let cns = ns.concat([ k ]); | ||
let r = new RegExp('{' + cns.join('.') + '}', 'gi'); | ||
s = s.replace(r, v); | ||
@@ -376,8 +704,8 @@ } | ||
if (a.length > 0) { | ||
a.forEach(function fix(item) { | ||
a.forEach((item) => { | ||
s = compile(s, item.data, item.key); | ||
}); | ||
} | ||
return s; | ||
} | ||
return trim(s, true); | ||
}; | ||
if (data && (isString(data) || isObject(data) || isArray(data))) { | ||
@@ -389,630 +717,56 @@ return compile(tpl, data); | ||
/** https://github.com/jbt/js-crypto */ | ||
/*eslint-disable*/ | ||
Bella.md5 = function() {for(var m=[],l=0;64>l;)m[l]=0|4294967296*Math.abs(Math.sin(++l));return function(c) {var e,g,f,a,h=[];c=unescape(encodeURI(c));for(var b=c.length,k=[e=1732584193,g=-271733879,~e,~g],d=0;d<=b;)h[d>>2]|=(c.charCodeAt(d)||128)<<8*(d++%4);h[c=16*(b+8>>6)+14]=8*b;for(d=0;d<c;d+=16) {b=k;for(a=0;64>a;)b=[f=b[3],(e=b[1]|0)+((f=b[0]+[e&(g=b[2])|~e&f,f&e|~f&g,e^g^f,g^(e|~f)][b=a>>4]+(m[a]+(h[[a,5*a+1,3*a+5,7*a][b]%16+d]|0)))<<(b=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*b+a++%4])|f>>>32-b),e,g];for(a=4;a;)k[--a]=k[a]+b[a]}for(c="";32>a;)c+=(k[a>>3]>>4*(1^a++&7)&15).toString(16);return c}}(); | ||
/*eslint-enable*/ | ||
B.encode = encode; | ||
B.decode = decode; | ||
B.trim = trim; | ||
B.truncate = truncate; | ||
B.stripTags = stripTags; | ||
B.escapeHTML = escapeHTML; | ||
B.unescapeHTML = unescapeHTML; | ||
B.strtolower = strtolower; | ||
B.strtoupper = strtoupper; | ||
B.ucfirst = ucfirst; | ||
B.ucwords = ucwords; | ||
B.leftPad = leftPad; | ||
B.rightPad = rightPad; | ||
B.replaceAll = replaceAll; | ||
B.stripAccent = stripAccent; | ||
B.createAlias = createAlias; | ||
B.template = template; | ||
Bella.random = function random(min, max) { | ||
if (!min || min < 0) { | ||
min = 0; | ||
} | ||
if (!max) { | ||
max = 9007199254740991; | ||
} | ||
if (min === max) { | ||
return max; | ||
} | ||
if (min > max) { | ||
min = Math.min(min, max); | ||
max = Math.max(min, max); | ||
} | ||
var offset = min; | ||
var range = max - min + 1; | ||
var rd = Math.floor(Math.random() * range) + offset; | ||
return rd; | ||
}; | ||
// collection | ||
Bella.unique = function unique(a) { | ||
if (isArray(a)) { | ||
var r = []; | ||
for (var i = 0; i < a.length; i++) { | ||
if (r.indexOf(a[i]) === -1) { | ||
r.push(a[i]); | ||
} | ||
} | ||
return r; | ||
} | ||
return a || []; | ||
}; | ||
Bella.max = function max(a) { | ||
return isArray(a) ? Math.max.apply({}, a) : a; | ||
}; | ||
Bella.min = function min(a) { | ||
return isArray(a) ? Math.min.apply({}, a) : a; | ||
}; | ||
Bella.contains = function contains(a, el, key) { | ||
if (isArray(a)) { | ||
for (var i = 0; i < a.length; i++) { | ||
var val = a[i]; | ||
if (key && val[key] === el[key] || val === el) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
Bella.sort = function sort(arr, opts) { | ||
var a = []; | ||
var one = {}; | ||
var o = opts || 1; | ||
if (isArray(arr) && arr.length > 0) { | ||
a = Bella.clone(arr); | ||
one = a[0]; | ||
if (o === 1 || o === -1) { | ||
a.sort(function f1(m, n) { | ||
return m > n ? o : m < n ? -1 * o : 0; | ||
}); | ||
} else if (isString(o) && Bella.hasProperty(one, o)) { | ||
a.sort(function f2(m, n) { | ||
return m[o] > n[o] ? 1 : m[o] < n[o] ? -1 : 0; | ||
}); | ||
} else if (isObject(o)) { | ||
for (var key in o) { | ||
if (Bella.hasProperty(one, key)) { | ||
var order = o[key] === -1 ? -1 : 1; | ||
/*eslint-disable*/ | ||
a.sort(function(m, n) { | ||
return (m[key] > n[key]) ? order : (m[key] < n[key] ? (-1 * order) : 0); | ||
}); | ||
/*eslint-enable*/ | ||
} | ||
} | ||
} | ||
} | ||
return a; | ||
}; | ||
Bella.shuffle = function shuffle(arr) { | ||
for (var i = arr.length - 1; i > 0; i--) { | ||
var j = Math.floor(Math.random() * (i + 1)); | ||
var tmp = arr[i]; | ||
arr[i] = arr[j]; | ||
arr[j] = tmp; | ||
} | ||
return arr; | ||
}; | ||
Bella.pick = function pick(arr, count) { | ||
var c = count ? Math.min(count, arr.length) : 1; | ||
if (c < 1) { | ||
c = 1; | ||
} | ||
if (c >= arr.length) { | ||
return arr; | ||
} | ||
if (c === 1) { | ||
var ri = Bella.random(0, arr.length - 1); | ||
return arr[ri]; | ||
} | ||
var ab = [], ba = Bella.clone(arr); | ||
while (ab.length < c) { | ||
var i = Bella.random(0, ba.length - 1); | ||
ab.push(ba[i]); | ||
ba.splice(i, 1); | ||
} | ||
return ab; | ||
}; | ||
Bella.copies = function copies(from, to, matched, excepts) { | ||
var mt = matched || false; | ||
var ex = excepts || []; | ||
for (var k in from) { | ||
if (ex.length > 0 && Bella.contains(ex, k)) { | ||
continue; | ||
} | ||
if (!mt || mt && to.hasOwnProperty(k)) { | ||
var oa = from[k]; | ||
var ob = to[k]; | ||
if (isObject(ob) && isObject(oa) || isArray(ob) && isArray(oa)) { | ||
to[k] = Bella.copies(oa, to[k], mt, ex); | ||
} else { | ||
to[k] = oa; | ||
} | ||
} | ||
} | ||
return to; | ||
}; | ||
Bella.clone = function clone(obj) { | ||
if (!isObject(obj) && !isArray(obj) && !isDate(obj)) { | ||
return obj; | ||
} | ||
if (isDate(obj)) { | ||
var copy1 = new Date(); | ||
copy1.setTime(obj.getTime()); | ||
return copy1; | ||
} | ||
if (isArray(obj)) { | ||
var copy2 = [], arr = obj.slice(0); | ||
for (var i = 0, len = arr.length; i < len; ++i) { | ||
copy2[i] = Bella.clone(arr[i]); | ||
} | ||
return copy2; | ||
} | ||
if (isObject(obj)) { | ||
var copy = {}; | ||
for (var attr in obj) { | ||
if (attr === 'clone') { | ||
continue; | ||
} | ||
if (obj.hasOwnProperty(attr)) { | ||
copy[attr] = Bella.clone(obj[attr]); | ||
} | ||
} | ||
return copy; | ||
} | ||
return false; | ||
}; | ||
Bella.empty = function empty(a) { | ||
if (isArray(a)) { | ||
for (var i = a.length - 1; i >= 0; i--) { | ||
a[i] = null; | ||
delete a[i]; | ||
} | ||
a.length = 0; | ||
} else if (isObject(a)) { | ||
for (var k in a) { | ||
if (Bella.hasProperty(a, k)) { | ||
a[k] = null; | ||
delete a[k]; | ||
} | ||
} | ||
} else if (isString(a)) { | ||
a = ''; | ||
} else if (isElement(a)) { | ||
a.innerHTML = ''; | ||
} | ||
return a; | ||
}; | ||
Bella.hasProperty = function hasProperty(ob, k) { | ||
if (!ob || !k) { | ||
return false; | ||
} | ||
var r = true; | ||
if (!isDef(ob[k])) { | ||
r = k in ob; | ||
} | ||
return r; | ||
}; | ||
Bella.equals = function equals(a, b) { | ||
var re = true; | ||
if (isEmpty(a) && isEmpty(b)) { | ||
return true; | ||
} else if (isDate(a) && isDate(b)) { | ||
return a.getTime() === b.getTime(); | ||
} else if (isNumber(a) && isNumber(b) || isString(a) && isString(b)) { | ||
return a === b; | ||
} else if (isArray(a) && isArray(b)) { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
if (a.length > 0) { | ||
for (var i = 0, l = a.length; i < l; i++) { | ||
if (!Bella.equals(a[i], b[i])) { | ||
re = false; | ||
break; | ||
} | ||
} | ||
} | ||
return re; | ||
} else if (isObject(a) && isObject(b)) { | ||
var as = [], bs = []; | ||
for (var k1 in a) { | ||
if (Bella.hasProperty(a, k1)) { | ||
as.push(k1); | ||
} | ||
} | ||
for (var k2 in b) { | ||
if (Bella.hasProperty(b, k2)) { | ||
bs.push(k2); | ||
} | ||
} | ||
if (as.length !== bs.length) { | ||
return false; | ||
} | ||
for (var k in a) { | ||
if (!Bella.hasProperty(b, k) || !Bella.equals(a[k], b[k])) { | ||
re = false; | ||
break; | ||
} | ||
} | ||
return re; | ||
} | ||
return false; | ||
}; | ||
// for browser only | ||
var _getElement, _addElement, _createElement, _query, _queryAll; | ||
if (Bella.ENV === 'browser') { | ||
_getElement = function __getElement(el) { | ||
var p = (isString(el) ? document.getElementById(el) : el) || null; | ||
if (p && isElement(p)) { | ||
p.hasClass = function hasClass(c) { | ||
var r = true, e = p.className.split(' '); c = c.split(' '); | ||
for (var i = 0; i < c.length; i++) { | ||
if (e.indexOf(c[i]) === -1) { | ||
r = false; | ||
break; | ||
} | ||
} | ||
return r; | ||
}; | ||
p.addClass = function addClass(c) { | ||
c = c.split(' '); | ||
var t = p.className.split(' '); | ||
var nc = c.concat(t); | ||
var sc = Bella.unique(nc); | ||
p.className = sc.join(' '); | ||
return p; | ||
}; | ||
p.removeClass = function removeClass(c) { | ||
var e = p.className.split(' '); c = c.split(' '); | ||
for (var i = 0; i < c.length; i++) { | ||
if (p.hasClass(c[i])) { | ||
e.splice(e.indexOf(c[i]), 1); | ||
} | ||
} | ||
p.className = e.join(' '); | ||
return p; | ||
}; | ||
p.toggleClass = function toggleClass(c) { | ||
if (p.hasClass(c)) { | ||
p.removeClass(c); | ||
} else { | ||
p.addClass(c); | ||
} | ||
return p; | ||
}; | ||
p.empty = function empty() { | ||
p.innerHTML = ''; | ||
return p; | ||
}; | ||
p.html = function html(s) { | ||
if (s !== '' && isEmpty(s)) { | ||
return p.innerHTML; | ||
} | ||
p.innerHTML = s; | ||
return p; | ||
}; | ||
p.destroy = function destroy() { | ||
if (p.parentNode) { | ||
p.parentNode.removeChild(p); | ||
} | ||
}; | ||
} | ||
return p; | ||
}; | ||
_addElement = function __addElement(tag, parent) { | ||
var p = parent ? _getElement(parent) : document.body; | ||
var d = isElement(tag) ? tag : document.createElement(tag); | ||
p.appendChild(d); | ||
return _getElement(d); | ||
}; | ||
_createElement = function __createElement(tag) { | ||
return _getElement(document.createElement(tag)); | ||
}; | ||
_query = function __query(condition) { | ||
var el, tmp = document.querySelector(condition); | ||
if (tmp) { | ||
el = _getElement(tmp); | ||
} | ||
return el; | ||
}; | ||
_queryAll = function __queryAll(condition) { | ||
var els = [], tmp = document.querySelectorAll(condition); | ||
if (tmp) { | ||
for (var i = 0; i < tmp.length; i++) { | ||
els.push(_getElement(tmp[i])); | ||
} | ||
} | ||
return els; | ||
}; | ||
/*eslint-disable*/ | ||
/*! | ||
* domready (c) Dustin Diaz 2014 - License MIT | ||
*/ | ||
var onready = (function() { | ||
var fns = [], listener, doc = document, | ||
hack = doc.documentElement.doScroll, | ||
domContentLoaded = 'DOMContentLoaded', | ||
loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState); | ||
if (!loaded) { | ||
doc.addEventListener(domContentLoaded, listener = function() { | ||
doc.removeEventListener(domContentLoaded, listener); | ||
loaded = 1; | ||
while(listener = fns.shift()) { | ||
listener(); | ||
} | ||
}); | ||
} | ||
return function (fn) { | ||
loaded ? setTimeout(fn, 0) : fns.push(fn) | ||
} | ||
})(); | ||
/*eslint-enable*/ | ||
Bella.dom = { | ||
ready: onready, | ||
one: _query, | ||
all: _queryAll, | ||
get: _getElement, | ||
add: _addElement, | ||
create: _createElement | ||
}; | ||
Bella.hostname = (function _hostname() { | ||
var atag = _createElement('A'); | ||
atag.href = document.URL; | ||
var loc = atag.hostname; | ||
atag.destroy(); | ||
return loc; | ||
})(); | ||
var isGecko = (function _isGecko(ua) { | ||
var n = ua.toLowerCase(); | ||
return /gecko/i.test(n); | ||
})(navigator.userAgent); | ||
Bella.event = (function _event() { | ||
return { | ||
on: function on(element, event, callback) { | ||
if (event === 'wheel') { | ||
event = isGecko ? 'DOMMouseScroll' : 'mousewheel'; | ||
} | ||
var el = isString(element) ? _getElement(element) : element; | ||
var cb = callback || function _callback() {}; | ||
if (el.addEventListener) { | ||
el.addEventListener(event, cb, false); | ||
} else if (el.attachEvent) { | ||
el.attachEvent('on' + event, cb); | ||
} | ||
}, | ||
off: function off(element, event, callback) { | ||
var el = isString(element) ? _getElement(element) : element; | ||
if (el.removeEventListener) { | ||
el.removeEventListener(event, callback, false); | ||
} else if (el.detachEvent) { | ||
el.detachEvent('on' + event, callback); | ||
} | ||
}, | ||
simulate: function simulate(element, event) { | ||
var evt, el = isString(element) ? _getElement(element) : element; | ||
if (document.createEventObject) { | ||
evt = document.createEventObject(); | ||
el.fireEvent('on' + event, evt); | ||
} else { | ||
evt = document.createEvent('HTMLEvents'); | ||
evt.initEvent(event, true, true); | ||
el.dispatchEvent(evt); | ||
} | ||
}, | ||
stop: function stop(e) { | ||
e.cancelBubble = true; | ||
if (e.stopPropagation) { | ||
e.stopPropagation(); | ||
} | ||
if (e.preventDefault) { | ||
e.preventDefault(); | ||
} | ||
return false; | ||
}, | ||
detect: function detect(e) { | ||
var evt = e || window.event; | ||
var targ = evt.target || evt.srcElement; | ||
if (targ && targ.nodeType === 3) { | ||
targ = targ.parentNode; | ||
} | ||
return _getElement(targ); | ||
} | ||
}; | ||
})(); | ||
Bella.getMousePosition = function getMousePosition(ev) { | ||
var e = ev || window.event; | ||
var cursor = { | ||
x: 0, | ||
y: 0 | ||
}; | ||
if (e.pageX || e.pageY) { | ||
cursor.x = e.pageX; | ||
cursor.y = e.pageY; | ||
} else { | ||
var de = document.documentElement; | ||
var db = document.body; | ||
cursor.x = e.clientX + (de.scrollLeft || db.scrollLeft) - (de.clientLeft || 0); | ||
cursor.y = e.clientY + (de.scrollTop || db.scrollTop) - (de.clientTop || 0); | ||
} | ||
return cursor; | ||
}; | ||
Bella.getWindowSize = function getWindowSize() { | ||
var w = 0, h = 0; | ||
if (window.innerWidth) { | ||
w = window.innerWidth; | ||
h = window.innerHeight; | ||
} else if (document.documentElement && document.documentElement.clientWidth) { | ||
w = document.documentElement.clientWidth; | ||
h = document.documentElement.clientHeight; | ||
} else if (document.body) { | ||
w = document.body.clientWidth; | ||
h = document.body.clientHeight; | ||
} | ||
return { | ||
width: w, | ||
height: h | ||
}; | ||
}; | ||
var cookie = { | ||
set: function set(name, value, expires, domain, path) { | ||
var cdata = false; | ||
var parse = function parse(ob) { | ||
var tmp = []; | ||
var _name = ob.name || ''; | ||
var _val = ob.value; | ||
var _exp = ob.expires || false; | ||
var _pat = ob.path || '/'; | ||
var _dom = ob.domain || false; | ||
if (_name) { | ||
var iss = !isObject(_val) && !isArray(_val); | ||
var vx = iss ? _val : JSON.stringify(_val); | ||
var arr = [ | ||
[ _name, isString(vx) ? encodeURIComponent(vx) : vx ], | ||
[ 'path', _pat ] | ||
]; | ||
if (_dom) { | ||
arr.push([ 'domain', _dom ]); | ||
} | ||
if (_exp && _exp.length && _exp.match(/(w|d|h|m|s)/gi)) { | ||
var v = parseInt(_exp, 10); | ||
var s = _exp.replace(v, ''); | ||
var delta = 0; | ||
if (s === 's') { | ||
delta = 1; | ||
} else if (s === 'm') { | ||
delta = 60; | ||
} else if (s === 'h') { | ||
delta = 60 * 60; | ||
} else if (s === 'd') { | ||
delta = 60 * 60 * 24; | ||
} else if (s === 'w') { | ||
delta = 7 * 60 * 60 * 24; | ||
} | ||
var ms = delta * v * 1000; | ||
if (Bella.isInteger(ms)) { | ||
var d = new Date(); | ||
var t = d.getTime() + ms; | ||
d.setTime(t); | ||
arr.push([ 'expires', d.toUTCString() ]); | ||
} | ||
} | ||
arr.forEach(function join(item) { | ||
tmp.push(item.join('=')); | ||
}); | ||
} | ||
return tmp.join('; '); | ||
}; | ||
if (arguments.length === 1 && Bella.isObject(name)) { | ||
cdata = parse(name); | ||
} else { | ||
cdata = parse({ | ||
name: name, | ||
value: value, | ||
path: path || false, | ||
expires: expires || false, | ||
domain: domain || false | ||
}); | ||
} | ||
if (cdata) { | ||
document.cookie = cdata; | ||
} | ||
}, | ||
get: function get(name) { | ||
if (document.cookie) { | ||
var a = document.cookie.split(';'); | ||
var n = Bella.trim(name); | ||
for (var i = 0; i < a.length; i++) { | ||
var t = a[i], ac = t.split('='), x = Bella.trim(ac[0]); | ||
if (x === n) { | ||
return decodeURIComponent(ac[1]); | ||
} | ||
} | ||
} | ||
return null; | ||
}, | ||
unset: function unset(name) { | ||
cookie.set(name, '', '-1d'); | ||
} | ||
}; | ||
Bella.cookie = cookie; | ||
} | ||
// DateTime | ||
Bella.now = function now() { | ||
var now = () => { | ||
return new Date(); | ||
}; | ||
Bella.time = function time() { | ||
return (new Date()).getTime(); | ||
var time = () => { | ||
return now().getTime(); | ||
}; | ||
Bella.date = (function _date() { | ||
(() => { | ||
var pattern = 'D, M d, Y h:i:s A'; | ||
var weeks = [ | ||
'Sunday', | ||
'Monday', | ||
'Tuesday', | ||
'Wednesday', | ||
'Thursday', | ||
'Friday', | ||
'Saturday' | ||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' | ||
]; | ||
var months = [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December' | ||
'January', 'February', 'March', 'April', | ||
'May', 'June', 'July', 'August', | ||
'September', 'October', 'November', 'December' | ||
]; | ||
var tz = (function tz() { | ||
var t = (new Date()).getTimezoneOffset(); | ||
var z = Math.abs(t / 60); | ||
var sign = t < 0 ? '+' : '-'; | ||
return [ 'GMT', sign, Bella.leftPad(z, 2) ].join(''); | ||
var tz = (() => { | ||
let t = new Date().getTimezoneOffset(); | ||
let z = Math.abs(t / 60); | ||
let sign = t < 0 ? '+' : '-'; | ||
return [ 'GMT', sign, leftPad(z, 2) ].join(''); | ||
})(); | ||
function format(output, input) { | ||
var meridiem = false, d, f, vchar = /\.*\\?([a-z])/gi; | ||
var format = (output, input) => { | ||
let meridiem = false; | ||
let d, f, vchar = /\.*\\?([a-z])/gi; | ||
if (!input) { | ||
input = Bella.time(); | ||
input = time(); | ||
} else { | ||
input = (new Date(input)).getTime(); | ||
input = new Date(input).getTime(); | ||
} | ||
if (!output) { | ||
if (!output || !isString(output)) { | ||
output = pattern; | ||
@@ -1025,28 +779,29 @@ } | ||
var wn = weeks; | ||
var mn = months; | ||
function _num(n) { | ||
let wn = weeks; | ||
let mn = months; | ||
let _num = (n) => { | ||
return String(n < 10 ? '0' + n : n); | ||
} | ||
function _ord(day) { | ||
var s = day + ' ', x = s.charAt(s.length - 2); | ||
}; | ||
let _ord = (day) => { | ||
let s = day + ' ', 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; | ||
} | ||
}; | ||
function _term(t, s) { | ||
var _term = (t, s) => { | ||
return f[t] ? f[t]() : s; | ||
} | ||
}; | ||
d = input instanceof Date ? input : new Date(input); | ||
if (isNaN(d.getTime())) { | ||
var reg = /^(\d+-\d+-\d+)\s(\d+:\d+:\d+)$/i; | ||
let reg = /^(\d+-\d+-\d+)\s(\d+:\d+:\d+)$/i; | ||
if (reg.test(input)) { | ||
@@ -1061,32 +816,74 @@ d = new Date(input.replace(' ', 'T')); | ||
f = { | ||
Y: function() {return d.getFullYear()}, // 2015 | ||
y: function() {return (f.Y()+'').slice(-2)}, // 15 | ||
F: function() {return mn[f.n()-1]}, // August | ||
M: function() {return (f.F()+'').slice(0,3)}, // Aug | ||
m: function() {return _num(f.n())}, // 08 | ||
n: function() {return d.getMonth()+1}, // 8 | ||
S: function() {return _ord(f.j())}, // 1st, 2nd, 3rd, 4th | ||
j: function() {return d.getDate()}, // 3 | ||
d: function() {return _num(f.j())}, // 03 | ||
t: function() {return (new Date(f.Y(), f.n(), 0)).getDate()}, // date in year | ||
w: function() {return d.getDay()}, // weekday in number | ||
l: function() {return wn[f.w()]}, // Sunday, Monday | ||
D: function() {return (f.l()+'').slice(0,3)},// Sun, Mon | ||
G: function() {return d.getHours()}, // 0 - 24 | ||
g: function() {return (f.G()%12||12)}, // 0 - 12 | ||
h: function() {return _num(meridiem?f.g():f.G())}, // 00 - 12 or 00 - 24 | ||
i: function() {return _num(d.getMinutes())}, // 00 - 59 | ||
s: function() {return _num(d.getSeconds())}, // 00 - 59 | ||
a: function() {return f.G()>11?'pm':'am'}, // am, pm | ||
A: function() {return (f.a()).toUpperCase()}, // AM, PM | ||
O: function() {return tz} | ||
} | ||
Y: () => { | ||
return d.getFullYear(); | ||
}, // 2015 | ||
y: () => { | ||
return (f.Y() + '').slice(-2); | ||
}, // 15 | ||
F: () => { | ||
return mn[f.n() - 1]; | ||
}, // August | ||
M: () => { | ||
return (f.F() + '').slice(0, 3); | ||
}, // Aug | ||
m: () => { | ||
return _num(f.n()); | ||
}, // 08 | ||
n: () => { | ||
return d.getMonth() + 1; | ||
}, // 8 | ||
S: () => { | ||
return _ord(f.j()); | ||
}, // st, nd, rd, th | ||
j: () => { | ||
return d.getDate(); | ||
}, // 3 | ||
d: () => { | ||
return _num(f.j()); | ||
}, // 03 | ||
t: () => { | ||
return new Date(f.Y(), f.n(), 0).getDate(); | ||
}, // date in year | ||
w: () => { | ||
return d.getDay(); | ||
}, // weekday in number | ||
l: () => { | ||
return wn[f.w()]; | ||
}, // Sunday, Monday | ||
D: () => { | ||
return (f.l() + '').slice(0, 3); | ||
}, // Sun, Mon | ||
G: () => { | ||
return d.getHours(); | ||
}, // 0 - 24 | ||
g: () => { | ||
return f.G() % 12 || 12; | ||
}, // 0 - 12 | ||
h: () => { | ||
return _num(meridiem ? f.g() : f.G()); | ||
}, // 00 - 12 or 00 - 24 | ||
i: () => { | ||
return _num(d.getMinutes()); | ||
}, // 00 - 59 | ||
s: () => { | ||
return _num(d.getSeconds()); | ||
}, // 00 - 59 | ||
a: () => { | ||
return f.G() > 11 ? 'pm' : 'am'; | ||
}, // am, pm | ||
A: () => { | ||
return f.a().toUpperCase(); | ||
}, // AM, PM | ||
O: () => { | ||
return tz; | ||
} | ||
}; | ||
/*eslint-enable */ | ||
return output.replace(vchar, _term); | ||
} | ||
}; | ||
var relativize = function _relativize(input) { | ||
var time = input instanceof Date ? input : new Date(input); | ||
var delta = new Date() - time; | ||
var nowThreshold = parseInt(time, 10); | ||
let relativize = (input) => { | ||
let t = input instanceof Date ? input : new Date(input); | ||
let delta = new Date() - t; | ||
let nowThreshold = parseInt(t, 10); | ||
if (isNaN(nowThreshold)) { | ||
@@ -1098,4 +895,4 @@ nowThreshold = 0; | ||
} | ||
var units = null; | ||
var conversions = { | ||
let units = null; | ||
let conversions = { | ||
millisecond: 1, | ||
@@ -1109,3 +906,3 @@ second: 1000, | ||
}; | ||
for (var key in conversions) { | ||
for (let key in conversions) { | ||
if (delta < conversions[key]) { | ||
@@ -1125,15 +922,18 @@ break; | ||
var utc = function utc(t) { | ||
return (new Date(t || Bella.now())).toUTCString(); | ||
let utc = (t) => { | ||
return new Date(t || now()).toUTCString(); | ||
}; | ||
var local = function local(t) { | ||
let local = (t) => { | ||
return format('D, j M Y h:i:s O', t); | ||
}; | ||
var strtotime = function strtotime(t) { | ||
return (new Date(t)).getTime(); | ||
let strtotime = (t) => { | ||
return new Date(t).getTime(); | ||
}; | ||
return { | ||
B.now = now; | ||
B.time = time; | ||
B.date = { | ||
utc: utc, | ||
@@ -1145,183 +945,301 @@ local: local, | ||
}; | ||
})(); | ||
// schedule | ||
Bella.scheduler = (function scheduler() { | ||
(() => { | ||
var TaskList = [], pattern = 'Y m d h i s', checkTimer; | ||
const MAX_TIMEOUT = 2147483647; | ||
function compare(task, sysTime, sysDay, currTime) { | ||
var TaskList = new Map(); | ||
var checkTimer; | ||
var taskTime = task.time, beginAt = Math.round(task.at / 1000); | ||
var getNextDay = (t, tday) => { | ||
let d = new Date(t); | ||
d.setDate(d.getDate() + tday + 7 - d.getDay() % 7); | ||
return d; | ||
}; | ||
if (taskTime.match(/^(sun|mon|tue|wed|thu|fri|sat)+(\w+)?(\s+)+(\d+(:\d)?)+$/gi)) { | ||
var a = taskTime.split(' '); | ||
var yes = false; | ||
if (a.length > 1) { | ||
var getDT1 = (mat, lastTick) => { | ||
var day = Bella.trim(a[0]), time = Bella.trim(a[1]); | ||
let delta = 0; | ||
let passed = time() - lastTick; | ||
if (sysDay.match(new RegExp(day, 'gi'))) { | ||
if (!mat) { | ||
return -1; | ||
} | ||
let v = parseInt(mat[1], 10); | ||
let s = mat[2]; | ||
if (s === 's') { | ||
delta = 1000; | ||
} else if (s === 'm') { | ||
delta = 6e4; | ||
} else if (s === 'h') { | ||
delta = 6e4 * 60; | ||
} else if (s === 'd') { | ||
delta = 6e4 * 60 * 24; | ||
} | ||
delta *= v; | ||
return delta - passed; | ||
}; | ||
var a2 = time.split(':'); | ||
if (a2.length === 1) { | ||
a2 = a2.concat([ '00', '00' ]); | ||
} | ||
if (a2.length === 2) { | ||
a2 = a2.concat([ '00' ]); | ||
} | ||
var getDT2 = (mat) => { | ||
let wds = 'sun|mon|tue|wed|thu|fri|sat'.split('|'); | ||
let today = new Date(); | ||
let wday = today.getDay(); | ||
var a3 = sysTime.split(' ').slice(3, 6); | ||
let awd = wds[wday]; | ||
let awi = getIndex(awd, wds); | ||
yes = true; | ||
for (var i = 0; i < a3.length; i++) { | ||
if (parseInt(a3[i], 10) !== parseInt(a2[i], 10)) { | ||
yes = false; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return yes; | ||
} else if (taskTime.match(/(d|h|m|s)/gi)) { | ||
let dd = mat[1].toLowerCase(); | ||
let ddi = getIndex(dd, wds); | ||
var v = parseInt(taskTime, 10); | ||
var s = taskTime.replace(v, ''); | ||
let hh = 0, ii = 0, ss = 0; | ||
if (mat[2]) { | ||
hh = parseInt(mat[2], 10); | ||
} | ||
if (mat[3]) { | ||
ii = parseInt(mat[3].replace(/\D/gi, ''), 10); | ||
} | ||
if (mat[4]) { | ||
ss = parseInt(mat[4].replace(/\D/gi, ''), 10); | ||
} | ||
var delta = 0; | ||
today.setHours(hh); | ||
today.setMinutes(ii); | ||
today.setSeconds(ss); | ||
if (s === 's') { | ||
delta = 1; | ||
} else if (s === 'm') { | ||
delta = 60; | ||
} else if (s === 'h') { | ||
delta = 60 * 60; | ||
} else if (s === 'd') { | ||
delta = 60 * 60 * 24; | ||
} | ||
let ttime = today.getTime(); | ||
let ctime = time(); | ||
delta *= v; | ||
var sdur = currTime - beginAt; | ||
return delta > 0 && sdur % delta === 0; | ||
let nextDay = today; | ||
if (ddi < awi || ctime > ttime) { | ||
nextDay = getNextDay(today, awi); | ||
} | ||
nextDay.setHours(hh); | ||
nextDay.setMinutes(ii); | ||
nextDay.setSeconds(ss); | ||
var a1 = taskTime.split(' '), a21 = sysTime.split(' '), s1 = '', s2 = ''; | ||
return nextDay.getTime() - ctime; | ||
}; | ||
for (var j = 0; j < a1.length; j++) { | ||
if (a1[j] === '*') { | ||
a21[j] = '*'; | ||
} | ||
s1 += a1[j]; | ||
s2 += a21[j]; | ||
var getDT3 = (mat) => { // eslint-disable-line complexity | ||
let yy = mat[1] === '*' ? '*' : parseInt(mat[1], 10); | ||
let mm = mat[2] === '*' ? '*' : parseInt(mat[2], 10); | ||
let dd = mat[3] === '*' ? '*' : parseInt(mat[3], 10); | ||
let hh = mat[4] === '*' ? '*' : parseInt(mat[4], 10); | ||
let ii = mat[5] === '*' ? '*' : parseInt(mat[5], 10); | ||
let ss = mat[6] === '*' ? '*' : parseInt(mat[6], 10); | ||
let today = new Date(); | ||
let ayy = today.getFullYear(); | ||
if (yy !== '*' && yy < ayy) { | ||
return -1; | ||
} | ||
return s1 === s2; | ||
} | ||
function check() { | ||
let tyy = yy; | ||
let tmm = mm; | ||
let tdd = dd; | ||
let thh = hh; | ||
let tii = ii; | ||
let tss = ss; | ||
var gt = Bella.time(), ggt = Math.round(gt / 1000); | ||
var sysTime = Bella.date.format(pattern, gt); | ||
var sysDay = Bella.date.format('l', gt); | ||
if (yy === '*') { | ||
tyy = ayy; | ||
} | ||
if (TaskList.length > 0) { | ||
for (var i = TaskList.length - 1; i >= 0; i--) { | ||
var t = TaskList[i]; | ||
if (compare(t, sysTime, sysDay, ggt)) { | ||
t.fn(); | ||
if (!t.repeat) { | ||
TaskList.splice(i, 1); | ||
} | ||
} | ||
let amm = today.getMonth() + 1; | ||
if (mm === '*') { | ||
tmm = amm; | ||
} | ||
let add = today.getDate(); | ||
if (dd === '*') { | ||
tdd = add; | ||
} | ||
let ahh = today.getHours(); | ||
if (hh === '*') { | ||
thh = ahh; | ||
} | ||
let aii = today.getMinutes(); | ||
if (ii === '*') { | ||
tii = aii; | ||
} | ||
let gd = new Date(tyy, tmm - 1, tdd, thh, tii, tss); | ||
let ttime = gd.getTime(); | ||
let ctime = time(); | ||
let delta = ttime - ctime; | ||
if (delta < 0) { | ||
if (ii === '*') { | ||
gd.setMinutes(tii + 1); | ||
ttime = gd.getTime(); | ||
delta = ttime - ctime; | ||
} | ||
} else { | ||
clearInterval(checkTimer); | ||
checkTimer = null; | ||
} | ||
} | ||
if (delta < 0) { | ||
if (hh === '*') { | ||
gd.setHours(thh + 1); | ||
ttime = gd.getTime(); | ||
delta = ttime - ctime; | ||
} | ||
} | ||
if (delta < 0) { | ||
if (dd === '*') { | ||
gd.setDate(tdd + 1); | ||
ttime = gd.getTime(); | ||
delta = ttime - ctime; | ||
} | ||
} | ||
function register(t, fn, single) { | ||
var ot = single || false; | ||
TaskList.push({ | ||
fn: fn, | ||
time: t, | ||
at: Bella.time(), | ||
repeat: !ot | ||
}); | ||
if (delta < 0) { | ||
if (mm === '*') { | ||
gd.setMonth(tmm); | ||
ttime = gd.getTime(); | ||
delta = ttime - ctime; | ||
} | ||
} | ||
if (!checkTimer) { | ||
checkTimer = setInterval(check, 1000); | ||
if (delta < 0) { | ||
if (yy === '*') { | ||
gd.setFullYear(tyy + 1); | ||
ttime = gd.getTime(); | ||
delta = ttime - ctime; | ||
} | ||
} | ||
} | ||
function yearly(t, fn) { | ||
var pt = '* ' + t; | ||
register(pt, fn); | ||
} | ||
return delta; | ||
}; | ||
function monthly(t, fn) { | ||
var pt = '* * ' + t; | ||
register(pt, fn); | ||
} | ||
var getDelayTime = (pat, lastTick) => { | ||
function daily(t, fn) { | ||
var pt = '* * * ' + t; | ||
register(pt, fn); | ||
} | ||
let pt1 = /^(\d+)\s?(d|h|m|s)+$/i; | ||
let pt2 = /^(sun|mon|tue|wed|thu|fri|sat)+\w*\s+(\d+)(:\d+)?(:\d+)?$/i; | ||
let pt3 = /^(\*|\d+)\s+(\*|\d+)\s+(\*|\d+)\s+(\*|\d+)\s+(\*|\d+)\s+(\d+)$/i; | ||
function hourly(t, fn) { | ||
var pt = '* * * * ' + t; | ||
register(pt, fn); | ||
} | ||
let mat = pat.match(pt1); | ||
if (mat) { | ||
return getDT1(mat, lastTick); | ||
} | ||
function every(t, fn) { | ||
register(t, fn); | ||
} | ||
mat = pat.match(pt2); | ||
if (mat) { | ||
return getDT2(mat); | ||
} | ||
function once(t, fn) { | ||
register(t, fn, true); | ||
} | ||
mat = pat.match(pt3); | ||
if (mat) { | ||
return getDT3(mat); | ||
} | ||
return { | ||
yearly: yearly, | ||
monthly: monthly, | ||
daily: daily, | ||
hourly: hourly, | ||
every: every, | ||
once: once | ||
return -1; | ||
}; | ||
})(); | ||
var tracable = 1; | ||
Bella.enableTrace = function enableTrace() { | ||
tracable = 1; | ||
}; | ||
var execute = (task) => { | ||
task.fn(); | ||
let id = task.id; | ||
if (!task.repeat) { | ||
return TaskList.delete(id); | ||
} | ||
Bella.disableTrace = function disableTrace() { | ||
tracable = 0; | ||
}; | ||
let t = time(); | ||
task.lastTick = t; | ||
TaskList.set(id, task); | ||
return true; | ||
}; | ||
Bella.trace = function trace() { | ||
if (tracable !== 1 || !console) { | ||
return false; | ||
} | ||
var a = Array.prototype.slice.call(arguments); | ||
var updateTimer = () => { | ||
if (TaskList.size > 0) { | ||
let minDelay = MAX_TIMEOUT; | ||
let candidates = []; | ||
TaskList.forEach((task) => { | ||
let id = task.id; | ||
let delay = getDelayTime(task.time, task.lastTick); | ||
if (delay < 0) { | ||
TaskList.delete(id); | ||
} else if (delay === 0) { | ||
task.delay = 0; | ||
candidates.push(task); | ||
} else { | ||
task.delay = delay; | ||
TaskList.set(id, task); | ||
if (delay <= minDelay) { | ||
minDelay = delay; | ||
let arr = []; | ||
arr = candidates.concat(task); | ||
candidates = arr.filter((item) => { | ||
return item.delay <= minDelay; | ||
}); | ||
} | ||
} | ||
}); | ||
if (checkTimer) { | ||
clearTimeout(checkTimer); | ||
} | ||
if (candidates.length) { | ||
checkTimer = setTimeout(() => { | ||
candidates.map(execute); | ||
setTimeout(updateTimer, 1); | ||
}, minDelay); | ||
} | ||
/*eslint-disable */ | ||
console.trace.apply(console, a); | ||
/*eslint-enable */ | ||
return true; | ||
}; | ||
} | ||
}; | ||
var register = (t, fn, once) => { | ||
let rep = once ? 0 : 1; | ||
let n = time(); | ||
let id = createId(32); | ||
let task = { | ||
id: id, | ||
fn: fn, | ||
time: t, | ||
repeat: rep, | ||
createdAt: n, | ||
lastTick: n, | ||
delay: 0 | ||
}; | ||
TaskList.set(id, task); | ||
updateTimer(); | ||
}; | ||
B.scheduler = { | ||
yearly: (t, fn) => { | ||
let pt = '* ' + t; | ||
register(pt, fn); | ||
}, | ||
monthly: (t, fn) => { | ||
let pt = '* * ' + t; | ||
register(pt, fn); | ||
}, | ||
daily: (t, fn) => { | ||
let pt = '* * * ' + t; | ||
register(pt, fn); | ||
}, | ||
hourly: (t, fn) => { | ||
let pt = '* * * * ' + t; | ||
return register(pt, fn); | ||
}, | ||
every: (t, fn) => { | ||
return register(t, fn); | ||
}, | ||
once: (t, fn) => { | ||
return register(t, fn, 1); | ||
} | ||
}; | ||
})(); | ||
// exports | ||
if (Bella.ENV === 'node') { | ||
module.exports = Bella; | ||
if (ENV === 'node') { | ||
module.exports = B; | ||
} else { | ||
var root = context || window; | ||
if (isFunction(root.define) && root.define.amd) { | ||
root.define(function bella() { | ||
return Bella; | ||
let root = window || {}; | ||
if (root.define && root.define.amd) { | ||
root.define(() => { | ||
return B; | ||
}); | ||
} | ||
root.Bella = Bella; | ||
root.Bella = B; | ||
} | ||
})(); |
@@ -5,3 +5,5 @@ /** | ||
*/ | ||
/* global describe it */ | ||
'use strict'; | ||
/* eslint no-undefined: 0*/ | ||
@@ -11,14 +13,9 @@ /* eslint no-array-constructor: 0*/ | ||
import path from 'path'; | ||
import chai from 'chai'; | ||
var test = require('tape'); | ||
chai.should(); | ||
var expect = chai.expect; | ||
var config = require('../../config'); | ||
var bella = config.bella; | ||
var rootDir = '../../../src/'; | ||
var bella = require(path.join(rootDir, 'bella')); | ||
describe('.compile(String s, Object date)', () => { | ||
// isArray | ||
test('Testing .compile(String s, Object date) method:', (assert) => { | ||
let sample = ` | ||
@@ -54,12 +51,5 @@ <article> | ||
describe(' / bella.compile(sample, data)', () => { | ||
let result = bella.compile(sample, data); | ||
it(' should return "' + expectation + '"', () => { | ||
expect(result).to.equal(expectation); | ||
}); | ||
}); | ||
let result = bella.compile(sample, data); | ||
assert.equal(result, bella.trim(expectation, true), 'Result must match expectation'); | ||
assert.end(); | ||
}); |
'use strict'; | ||
var traceur = require('traceur'); | ||
traceur.require.makeDefault((filename) => { | ||
return !filename.includes('node_modules'); | ||
}); | ||
var fs = require('fs'); | ||
@@ -15,3 +10,6 @@ var path = require('path'); | ||
var dirs = [ '', 'types', 'string', 'template', 'array', 'object' ]; | ||
// var dirs = [ '', 'detection', 'utils', 'string', 'date', 'scheduler' ]; | ||
var dirs = [ '', 'detection', 'utils', 'string', 'date', 'scheduler' ]; | ||
dirs.forEach((dir) => { | ||
@@ -18,0 +16,0 @@ let where = './test/specs/' + dir; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
122563
2834
4
11
22
423
5