|
|
@ -3,28 +3,29 @@ |
|
|
|
* Create By GUY 2014\11\17 |
|
|
|
* Create By GUY 2014\11\17 |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var traverse = function (func, context) { |
|
|
|
function traverse (func, context) { |
|
|
|
return function (value, key, obj) { |
|
|
|
return function (value, key, obj) { |
|
|
|
return func.call(context, key, value, obj); |
|
|
|
return func.call(context, key, value, obj); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
var _apply = function (name) { |
|
|
|
function _apply(name) { |
|
|
|
return function () { |
|
|
|
return function () { |
|
|
|
return BI._[name].apply(BI._, arguments); |
|
|
|
return BI._[name](...arguments); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
var _applyFunc = function (name) { |
|
|
|
function _applyFunc(name) { |
|
|
|
return function () { |
|
|
|
return function () { |
|
|
|
var args = Array.prototype.slice.call(arguments, 0); |
|
|
|
const args = Array.prototype.slice.call(arguments, 0); |
|
|
|
args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1]; |
|
|
|
args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1]; |
|
|
|
return BI._[name].apply(BI._, args); |
|
|
|
|
|
|
|
|
|
|
|
return BI._[name](...args); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function assert(v, is) { |
|
|
|
export function assert(v, is) { |
|
|
|
if (isFunction(is)) { |
|
|
|
if (isFunction(is)) { |
|
|
|
if (!is(v)) { |
|
|
|
if (!is(v)) { |
|
|
|
throw new Error(v + " error"); |
|
|
|
throw new Error(`${v} error`); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -33,8 +34,9 @@ export function assert(v, is) { |
|
|
|
is = [is]; |
|
|
|
is = [is]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!deepContains(is, v)) { |
|
|
|
if (!deepContains(is, v)) { |
|
|
|
throw new Error(v + " error"); |
|
|
|
throw new Error(`${v} error`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -43,12 +45,13 @@ export function warn(message) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function UUID() { |
|
|
|
export function UUID() { |
|
|
|
var f = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; |
|
|
|
const f = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; |
|
|
|
var str = ""; |
|
|
|
let str = ""; |
|
|
|
for (var i = 0; i < 16; i++) { |
|
|
|
for (let i = 0; i < 16; i++) { |
|
|
|
var r = _global.parseInt(f.length * Math.random(), 10); |
|
|
|
const r = _global.parseInt(f.length * Math.random(), 10); |
|
|
|
str += f[r]; |
|
|
|
str += f[r]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
return str; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -66,58 +69,60 @@ export function createWidgets(items, options, context) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
options || (options = {}); |
|
|
|
options || (options = {}); |
|
|
|
} |
|
|
|
} |
|
|
|
return map(flatten(items), function (i, item) { |
|
|
|
|
|
|
|
return BI.createWidget(item, deepClone(options), context); |
|
|
|
return map(flatten(items), (i, item) => BI.createWidget(item, deepClone(options), context)); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function createItems(data, innerAttr, outerAttr) { |
|
|
|
export function createItems(data, innerAttr, outerAttr) { |
|
|
|
innerAttr = isArray(innerAttr) ? innerAttr : makeArray(flatten(data).length, innerAttr || {}); |
|
|
|
innerAttr = isArray(innerAttr) ? innerAttr : makeArray(flatten(data).length, innerAttr || {}); |
|
|
|
outerAttr = isArray(outerAttr) ? outerAttr : makeArray(flatten(data).length, outerAttr || {}); |
|
|
|
outerAttr = isArray(outerAttr) ? outerAttr : makeArray(flatten(data).length, outerAttr || {}); |
|
|
|
return map(data, function (i, item) { |
|
|
|
|
|
|
|
|
|
|
|
return map(data, (i, item) => { |
|
|
|
if (isArray(item)) { |
|
|
|
if (isArray(item)) { |
|
|
|
return createItems(item, innerAttr, outerAttr); |
|
|
|
return createItems(item, innerAttr, outerAttr); |
|
|
|
} |
|
|
|
} |
|
|
|
if (item instanceof BI.Widget) { |
|
|
|
if (item instanceof BI.Widget) { |
|
|
|
return extend({}, innerAttr.shift(), outerAttr.shift(), { |
|
|
|
return extend({}, innerAttr.shift(), outerAttr.shift(), { |
|
|
|
type: null, |
|
|
|
type: null, |
|
|
|
el: item |
|
|
|
el: item, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (innerAttr[0] instanceof BI.Widget) { |
|
|
|
if (innerAttr[0] instanceof BI.Widget) { |
|
|
|
outerAttr.shift(); |
|
|
|
outerAttr.shift(); |
|
|
|
|
|
|
|
|
|
|
|
return extend({}, item, { |
|
|
|
return extend({}, item, { |
|
|
|
el: innerAttr.shift() |
|
|
|
el: innerAttr.shift(), |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (item.el instanceof BI.Widget) { |
|
|
|
if (item.el instanceof BI.Widget) { |
|
|
|
innerAttr.shift(); |
|
|
|
innerAttr.shift(); |
|
|
|
|
|
|
|
|
|
|
|
return extend({}, outerAttr.shift(), { type: null }, item); |
|
|
|
return extend({}, outerAttr.shift(), { type: null }, item); |
|
|
|
} |
|
|
|
} |
|
|
|
if (item.el) { |
|
|
|
if (item.el) { |
|
|
|
return extend({}, outerAttr.shift(), item, { |
|
|
|
return extend({}, outerAttr.shift(), item, { |
|
|
|
el: extend({}, innerAttr.shift(), item.el) |
|
|
|
el: extend({}, innerAttr.shift(), item.el), |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return extend({}, outerAttr.shift(), { |
|
|
|
return extend({}, outerAttr.shift(), { |
|
|
|
el: extend({}, innerAttr.shift(), item) |
|
|
|
el: extend({}, innerAttr.shift(), item), |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 用容器包装items
|
|
|
|
// 用容器包装items
|
|
|
|
export function packageItems(items, layouts) { |
|
|
|
export function packageItems(items, layouts) { |
|
|
|
for (var i = layouts.length - 1; i >= 0; i--) { |
|
|
|
for (let i = layouts.length - 1; i >= 0; i--) { |
|
|
|
items = map(items, function (k, it) { |
|
|
|
items = map(items, (k, it) => extend({}, layouts[i], { |
|
|
|
return extend({}, layouts[i], { |
|
|
|
|
|
|
|
items: [ |
|
|
|
items: [ |
|
|
|
extend({}, layouts[i].el, { |
|
|
|
extend({}, layouts[i].el, { |
|
|
|
el: it |
|
|
|
el: it, |
|
|
|
}) |
|
|
|
}) |
|
|
|
] |
|
|
|
], |
|
|
|
}); |
|
|
|
})); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return items; |
|
|
|
return items; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -125,8 +130,9 @@ export function formatEL(obj) { |
|
|
|
if (obj && !obj.type && obj.el) { |
|
|
|
if (obj && !obj.type && obj.el) { |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
el: obj |
|
|
|
el: obj, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -140,13 +146,13 @@ export function trans2Element(widgets) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 集合相关方法
|
|
|
|
// 集合相关方法
|
|
|
|
BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) { |
|
|
|
BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], name => { |
|
|
|
BI[name] = _apply(name); |
|
|
|
BI[name] = _apply(name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI._.each([ |
|
|
|
BI._.each([ |
|
|
|
"get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", |
|
|
|
"get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", |
|
|
|
"sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp" |
|
|
|
"sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp" |
|
|
|
], function (name) { |
|
|
|
], name => { |
|
|
|
if (name === "any") { |
|
|
|
if (name === "any") { |
|
|
|
BI[name] = _applyFunc("some"); |
|
|
|
BI[name] = _applyFunc("some"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -185,12 +191,13 @@ export const clamp = BI.clamp; |
|
|
|
|
|
|
|
|
|
|
|
// 数数
|
|
|
|
// 数数
|
|
|
|
export function count(from, to, predicate) { |
|
|
|
export function count(from, to, predicate) { |
|
|
|
var t; |
|
|
|
let t; |
|
|
|
if (predicate) { |
|
|
|
if (predicate) { |
|
|
|
for (t = from; t < to; t++) { |
|
|
|
for (t = from; t < to; t++) { |
|
|
|
predicate(t); |
|
|
|
predicate(t); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return to - from; |
|
|
|
return to - from; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -201,45 +208,51 @@ export function inverse(from, to, predicate) { |
|
|
|
|
|
|
|
|
|
|
|
export function firstKey(obj) { |
|
|
|
export function firstKey(obj) { |
|
|
|
let res = undefined; |
|
|
|
let res = undefined; |
|
|
|
any(obj, function (key, value) { |
|
|
|
any(obj, (key, value) => { |
|
|
|
res = key; |
|
|
|
res = key; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function lastKey(obj) { |
|
|
|
export function lastKey(obj) { |
|
|
|
let res = undefined; |
|
|
|
let res = undefined; |
|
|
|
each(obj, function (key, value) { |
|
|
|
each(obj, (key, value) => { |
|
|
|
res = key; |
|
|
|
res = key; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function firstObject(obj) { |
|
|
|
export function firstObject(obj) { |
|
|
|
let res = undefined; |
|
|
|
let res = undefined; |
|
|
|
any(obj, function (key, value) { |
|
|
|
any(obj, (key, value) => { |
|
|
|
res = value; |
|
|
|
res = value; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function lastObject(obj) { |
|
|
|
export function lastObject(obj) { |
|
|
|
let res = undefined; |
|
|
|
let res = undefined; |
|
|
|
each(obj, function (key, value) { |
|
|
|
each(obj, (key, value) => { |
|
|
|
res = value; |
|
|
|
res = value; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function concat(obj1, obj2) { |
|
|
|
export function concat(obj1, obj2) { |
|
|
|
if (isKey(obj1)) { |
|
|
|
if (isKey(obj1)) { |
|
|
|
return map([].slice.apply(arguments), function (idx, v) { |
|
|
|
return map([].slice.apply(arguments), (idx, v) => v).join(""); |
|
|
|
return v; |
|
|
|
|
|
|
|
}).join(""); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (isArray(obj1)) { |
|
|
|
if (isArray(obj1)) { |
|
|
|
return BI._.concat.apply([], arguments); |
|
|
|
return BI._.concat.apply([], arguments); |
|
|
@ -254,6 +267,7 @@ export function backEach(obj, predicate, context) { |
|
|
|
for (let index = obj.length - 1; index >= 0; index--) { |
|
|
|
for (let index = obj.length - 1; index >= 0; index--) { |
|
|
|
predicate(index, obj[index], obj); |
|
|
|
predicate(index, obj[index], obj); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -264,6 +278,7 @@ export function backAny(obj, predicate, context) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -274,12 +289,14 @@ export function backEvery(obj, predicate, context) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function backFindKey(obj, predicate, context) { |
|
|
|
export function backFindKey(obj, predicate, context) { |
|
|
|
predicate = iteratee(predicate, context); |
|
|
|
predicate = iteratee(predicate, context); |
|
|
|
let objKeys = keys(obj), key; |
|
|
|
const objKeys = keys(obj); |
|
|
|
|
|
|
|
let key; |
|
|
|
for (let i = objKeys.length - 1; i >= 0; i--) { |
|
|
|
for (let i = objKeys.length - 1; i >= 0; i--) { |
|
|
|
key = objKeys[i]; |
|
|
|
key = objKeys[i]; |
|
|
|
if (predicate(obj[key], key, obj)) { |
|
|
|
if (predicate(obj[key], key, obj)) { |
|
|
@ -311,7 +328,7 @@ export function remove(obj, target, context) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
each(obj, function (i, v) { |
|
|
|
each(obj, (i, v) => { |
|
|
|
if ((targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i]))) { |
|
|
|
if ((targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i]))) { |
|
|
|
delete obj[i]; |
|
|
|
delete obj[i]; |
|
|
|
} |
|
|
|
} |
|
|
@ -321,7 +338,8 @@ export function remove(obj, target, context) { |
|
|
|
|
|
|
|
|
|
|
|
export function removeAt(obj, index) { |
|
|
|
export function removeAt(obj, index) { |
|
|
|
index = isArray(index) ? index : [index]; |
|
|
|
index = isArray(index) ? index : [index]; |
|
|
|
let objIsArray = isArray(obj), i; |
|
|
|
const objIsArray = isArray(obj); |
|
|
|
|
|
|
|
let i; |
|
|
|
for (i = 0; i < index.length; i++) { |
|
|
|
for (i = 0; i < index.length; i++) { |
|
|
|
if (objIsArray) { |
|
|
|
if (objIsArray) { |
|
|
|
obj[index[i]] = "$deleteIndex"; |
|
|
|
obj[index[i]] = "$deleteIndex"; |
|
|
@ -343,13 +361,15 @@ export function array2String(array) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function abc2Int(string) { |
|
|
|
export function abc2Int(string) { |
|
|
|
let idx = 0, start = "A", str = string.toUpperCase(); |
|
|
|
let idx = 0; |
|
|
|
|
|
|
|
const start = "A", str = string.toUpperCase(); |
|
|
|
for (let i = 0, len = str.length; i < len; ++i) { |
|
|
|
for (let i = 0, len = str.length; i < len; ++i) { |
|
|
|
idx = str.charAt(i).charCodeAt(0) - start.charCodeAt(0) + 26 * idx + 1; |
|
|
|
idx = str.charAt(i).charCodeAt(0) - start.charCodeAt(0) + 26 * idx + 1; |
|
|
|
if (idx > (2147483646 - str.charAt(i).charCodeAt(0) + start.charCodeAt(0)) / 26) { |
|
|
|
if (idx > (2147483646 - str.charAt(i).charCodeAt(0) + start.charCodeAt(0)) / 26) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return idx; |
|
|
|
return idx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -367,6 +387,7 @@ export function int2Abc(num) { |
|
|
|
str = DIGITS[t - 1] + str; |
|
|
|
str = DIGITS[t - 1] + str; |
|
|
|
idx = (idx - t) / 26; |
|
|
|
idx = (idx - t) / 26; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
return str; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -374,10 +395,10 @@ export function int2Abc(num) { |
|
|
|
BI._.each([ |
|
|
|
BI._.each([ |
|
|
|
"first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", |
|
|
|
"first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", |
|
|
|
"difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy" |
|
|
|
"difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy" |
|
|
|
], function (name) { |
|
|
|
], name => { |
|
|
|
BI[name] = _apply(name); |
|
|
|
BI[name] = _apply(name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI._.each(["findIndex", "findLastIndex"], function (name) { |
|
|
|
BI._.each(["findIndex", "findLastIndex"], name => { |
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
export const first = BI.first; |
|
|
|
export const first = BI.first; |
|
|
@ -405,7 +426,7 @@ export const findLastIndex = BI.findLastIndex; |
|
|
|
|
|
|
|
|
|
|
|
// 构建一个长度为length的数组
|
|
|
|
// 构建一个长度为length的数组
|
|
|
|
export function makeArray(length, value) { |
|
|
|
export function makeArray(length, value) { |
|
|
|
let res = []; |
|
|
|
const res = []; |
|
|
|
for (let i = 0; i < length; i++) { |
|
|
|
for (let i = 0; i < length; i++) { |
|
|
|
if (isNull(value)) { |
|
|
|
if (isNull(value)) { |
|
|
|
res.push(i); |
|
|
|
res.push(i); |
|
|
@ -413,11 +434,12 @@ export function makeArray(length, value) { |
|
|
|
res.push(deepClone(value)); |
|
|
|
res.push(deepClone(value)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function makeObject(array, value) { |
|
|
|
export function makeObject(array, value) { |
|
|
|
let map = {}; |
|
|
|
const map = {}; |
|
|
|
for (let i = 0; i < array.length; i++) { |
|
|
|
for (let i = 0; i < array.length; i++) { |
|
|
|
if (isNull(value)) { |
|
|
|
if (isNull(value)) { |
|
|
|
map[array[i]] = array[i]; |
|
|
|
map[array[i]] = array[i]; |
|
|
@ -427,11 +449,12 @@ export function makeObject(array, value) { |
|
|
|
map[array[i]] = deepClone(value); |
|
|
|
map[array[i]] = deepClone(value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return map; |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function makeArrayByArray(array, value) { |
|
|
|
export function makeArrayByArray(array, value) { |
|
|
|
let res = []; |
|
|
|
const res = []; |
|
|
|
if (!array) { |
|
|
|
if (!array) { |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
@ -442,11 +465,12 @@ export function makeArrayByArray(array, value) { |
|
|
|
res.push(deepClone(value)); |
|
|
|
res.push(deepClone(value)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function uniq(array, isSorted, iteratee, context) { |
|
|
|
export function uniq(array, isSorted, iteratee, context) { |
|
|
|
if (array == null) { |
|
|
|
if (array === null) { |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!isBoolean(isSorted)) { |
|
|
|
if (!isBoolean(isSorted)) { |
|
|
@ -455,7 +479,8 @@ export function uniq(array, isSorted, iteratee, context) { |
|
|
|
isSorted = false; |
|
|
|
isSorted = false; |
|
|
|
} |
|
|
|
} |
|
|
|
iteratee && (iteratee = traverse(iteratee, context)); |
|
|
|
iteratee && (iteratee = traverse(iteratee, context)); |
|
|
|
return uniq.call(BI._, array, isSorted, iteratee, context); |
|
|
|
|
|
|
|
|
|
|
|
return BI._uniq.call(BI._, array, isSorted, iteratee, context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 对象相关方法
|
|
|
|
// 对象相关方法
|
|
|
@ -464,7 +489,7 @@ BI._.each([ |
|
|
|
"defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", |
|
|
|
"defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", |
|
|
|
"isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", |
|
|
|
"isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", |
|
|
|
"isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep" |
|
|
|
"isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep" |
|
|
|
], function (name) { |
|
|
|
], name => { |
|
|
|
BI[name] = _apply(name); |
|
|
|
BI[name] = _apply(name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
export const keys = BI.keys; |
|
|
|
export const keys = BI.keys; |
|
|
@ -502,7 +527,7 @@ export const isUndefined = BI.isUndefined; |
|
|
|
export const zipObject = BI.zipObject; |
|
|
|
export const zipObject = BI.zipObject; |
|
|
|
export const cloneDeep = BI.cloneDeep; |
|
|
|
export const cloneDeep = BI.cloneDeep; |
|
|
|
|
|
|
|
|
|
|
|
BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], function (name) { |
|
|
|
BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], name => { |
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
export const mapObject = BI.mapObject; |
|
|
|
export const mapObject = BI.mapObject; |
|
|
@ -512,17 +537,18 @@ export const omit = BI.omit; |
|
|
|
export const tap = BI.tap; |
|
|
|
export const tap = BI.tap; |
|
|
|
|
|
|
|
|
|
|
|
export function inherit(sp, overrides) { |
|
|
|
export function inherit(sp, overrides) { |
|
|
|
let sb = function () { |
|
|
|
function sb () { |
|
|
|
return sp.apply(this, arguments); |
|
|
|
return sp.apply(this, arguments); |
|
|
|
}; |
|
|
|
} |
|
|
|
let F = function () { |
|
|
|
function F () {} |
|
|
|
}, spp = sp.prototype; |
|
|
|
const spp = sp.prototype; |
|
|
|
F.prototype = spp; |
|
|
|
F.prototype = spp; |
|
|
|
sb.prototype = new F(); |
|
|
|
sb.prototype = new F(); |
|
|
|
sb.superclass = spp; |
|
|
|
sb.superclass = spp; |
|
|
|
extend(sb.prototype, overrides, { |
|
|
|
extend(sb.prototype, overrides, { |
|
|
|
superclass: sp |
|
|
|
superclass: sp, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return sb; |
|
|
|
return sb; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -542,11 +568,11 @@ export function has(obj, keys) { |
|
|
|
if (keys.length === 0) { |
|
|
|
if (keys.length === 0) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return every(keys, function (i, key) { |
|
|
|
|
|
|
|
return BI._.has(obj, key); |
|
|
|
return every(keys, (i, key) => BI._.has(obj, key)); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return BI._.has.apply(BI._, arguments); |
|
|
|
|
|
|
|
|
|
|
|
return BI._.has(...arguments); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function freeze(value) { |
|
|
|
export function freeze(value) { |
|
|
@ -555,6 +581,7 @@ export function freeze(value) { |
|
|
|
if (Object.freeze && isObject(value)) { |
|
|
|
if (Object.freeze && isObject(value)) { |
|
|
|
return Object.freeze(value); |
|
|
|
return Object.freeze(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return value; |
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -565,8 +592,9 @@ export function isKey(key) { |
|
|
|
|
|
|
|
|
|
|
|
// 忽略大小写的等于
|
|
|
|
// 忽略大小写的等于
|
|
|
|
export function isCapitalEqual(a, b) { |
|
|
|
export function isCapitalEqual(a, b) { |
|
|
|
a = isNull(a) ? a : ("" + a).toLowerCase(); |
|
|
|
a = isNull(a) ? a : (`${a}`).toLowerCase(); |
|
|
|
b = isNull(b) ? b : ("" + b).toLowerCase(); |
|
|
|
b = isNull(b) ? b : (`${b}`).toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
return isEqual(a, b); |
|
|
|
return isEqual(a, b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -603,7 +631,7 @@ export function isNotEmptyObject(obj) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isWindow(obj) { |
|
|
|
export function isWindow(obj) { |
|
|
|
return obj != null && obj == obj.window; |
|
|
|
return obj !== null && obj === obj.window; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isPromise(obj) { |
|
|
|
export function isPromise(obj) { |
|
|
@ -614,8 +642,8 @@ export const deepClone = BI._.cloneDeep; |
|
|
|
export const deepExtend = BI._.deepExtend; |
|
|
|
export const deepExtend = BI._.deepExtend; |
|
|
|
|
|
|
|
|
|
|
|
export function isDeepMatch(object, attrs) { |
|
|
|
export function isDeepMatch(object, attrs) { |
|
|
|
let attrsKeys = keys(attrs), length = attrsKeys.length; |
|
|
|
const attrsKeys = keys(attrs), length = attrsKeys.length; |
|
|
|
if (object == null) { |
|
|
|
if (object === null) { |
|
|
|
return !length; |
|
|
|
return !length; |
|
|
|
} |
|
|
|
} |
|
|
|
const obj = Object(object); |
|
|
|
const obj = Object(object); |
|
|
@ -625,11 +653,13 @@ export function isDeepMatch(object, attrs) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function contains(obj, target, fromIndex) { |
|
|
|
export function contains(obj, target, fromIndex) { |
|
|
|
if (!BI._.isArrayLike(obj)) obj = values(obj); |
|
|
|
if (!BI._.isArrayLike(obj)) obj = values(obj); |
|
|
|
|
|
|
|
|
|
|
|
return indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0; |
|
|
|
return indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -637,6 +667,7 @@ export function deepContains(obj, copy) { |
|
|
|
if (isObject(copy)) { |
|
|
|
if (isObject(copy)) { |
|
|
|
return any(obj, (i, v) => isEqual(v, copy)); |
|
|
|
return any(obj, (i, v) => isEqual(v, copy)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return contains(obj, copy); |
|
|
|
return contains(obj, copy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -646,6 +677,7 @@ export function deepIndexOf(obj, target) { |
|
|
|
return i; |
|
|
|
return i; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -667,35 +699,39 @@ export function deepRemove(obj, target) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return done; |
|
|
|
return done; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function deepWithout(obj, target) { |
|
|
|
export function deepWithout(obj, target) { |
|
|
|
if (isArray(obj)) { |
|
|
|
if (isArray(obj)) { |
|
|
|
let result = []; |
|
|
|
const result = []; |
|
|
|
for (let i = 0; i < obj.length; i++) { |
|
|
|
for (let i = 0; i < obj.length; i++) { |
|
|
|
if (!isEqual(target, obj[i])) { |
|
|
|
if (!isEqual(target, obj[i])) { |
|
|
|
result.push(obj[i]); |
|
|
|
result.push(obj[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
let result = {}; |
|
|
|
const result = {}; |
|
|
|
each(obj, (i, v) => { |
|
|
|
each(obj, (i, v) => { |
|
|
|
if (!isEqual(target, obj[i])) { |
|
|
|
if (!isEqual(target, obj[i])) { |
|
|
|
result[i] = v; |
|
|
|
result[i] = v; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function deepUnique(array) { |
|
|
|
export function deepUnique(array) { |
|
|
|
let result = []; |
|
|
|
const result = []; |
|
|
|
each(array, (i, item) => { |
|
|
|
each(array, (i, item) => { |
|
|
|
if (!deepContains(result, item)) { |
|
|
|
if (!deepContains(result, item)) { |
|
|
|
result.push(item); |
|
|
|
result.push(item); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -703,9 +739,9 @@ export function deepUnique(array) { |
|
|
|
export function deepDiff(object, other) { |
|
|
|
export function deepDiff(object, other) { |
|
|
|
object || (object = {}); |
|
|
|
object || (object = {}); |
|
|
|
other || (other = {}); |
|
|
|
other || (other = {}); |
|
|
|
let result = []; |
|
|
|
const result = []; |
|
|
|
let used = []; |
|
|
|
const used = []; |
|
|
|
for (let b in object) { |
|
|
|
for (const b in object) { |
|
|
|
if (has(object, b)) { |
|
|
|
if (has(object, b)) { |
|
|
|
if (!isEqual(object[b], other[b])) { |
|
|
|
if (!isEqual(object[b], other[b])) { |
|
|
|
result.push(b); |
|
|
|
result.push(b); |
|
|
@ -713,19 +749,18 @@ export function deepDiff(object, other) { |
|
|
|
used.push(b); |
|
|
|
used.push(b); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (let b in other) { |
|
|
|
for (const b in other) { |
|
|
|
if (has(other, b) && !contains(used, b)) { |
|
|
|
if (has(other, b) && !contains(used, b)) { |
|
|
|
result.push(b); |
|
|
|
result.push(b); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 通用方法
|
|
|
|
// 通用方法
|
|
|
|
BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], function (name) { |
|
|
|
BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], name => { |
|
|
|
BI[name] = function () { |
|
|
|
BI[name] = (...args) => BI._[name](...args); |
|
|
|
return BI._[name].apply(BI._, arguments); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
export const uniqueId = BI.uniqueId; |
|
|
|
export const uniqueId = BI.uniqueId; |
|
|
|
export const result = BI.result; |
|
|
|
export const result = BI.result; |
|
|
@ -737,10 +772,8 @@ export const after = BI.after; |
|
|
|
export const chunk = BI.chunk; |
|
|
|
export const chunk = BI.chunk; |
|
|
|
|
|
|
|
|
|
|
|
// 事件相关方法
|
|
|
|
// 事件相关方法
|
|
|
|
BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], function (name) { |
|
|
|
BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], name => { |
|
|
|
BI[name] = function () { |
|
|
|
BI[name] = (...args) => BI._[name](...args); |
|
|
|
return BI._[name].apply(BI._, arguments); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
export const bind = BI.bind; |
|
|
|
export const bind = BI.bind; |
|
|
|
export const once = BI.once; |
|
|
|
export const once = BI.once; |
|
|
@ -752,13 +785,13 @@ export const defer = BI.defer; |
|
|
|
export const wrap = BI.wrap; |
|
|
|
export const wrap = BI.wrap; |
|
|
|
|
|
|
|
|
|
|
|
export const nextTick = (function () { |
|
|
|
export const nextTick = (function () { |
|
|
|
let callbacks = []; |
|
|
|
const callbacks = []; |
|
|
|
let pending = false; |
|
|
|
let pending = false; |
|
|
|
let timerFunc = void 0; |
|
|
|
let timerFunc = void 0; |
|
|
|
|
|
|
|
|
|
|
|
function nextTickHandler() { |
|
|
|
function nextTickHandler() { |
|
|
|
pending = false; |
|
|
|
pending = false; |
|
|
|
let copies = callbacks.slice(0); |
|
|
|
const copies = callbacks.slice(0); |
|
|
|
callbacks.length = 0; |
|
|
|
callbacks.length = 0; |
|
|
|
for (let i = 0; i < copies.length; i++) { |
|
|
|
for (let i = 0; i < copies.length; i++) { |
|
|
|
copies[i](); |
|
|
|
copies[i](); |
|
|
@ -766,16 +799,16 @@ export const nextTick = (function () { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof Promise !== "undefined") { |
|
|
|
if (typeof Promise !== "undefined") { |
|
|
|
let p = Promise.resolve(); |
|
|
|
const p = Promise.resolve(); |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
p.then(nextTickHandler); |
|
|
|
p.then(nextTickHandler); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else if (typeof MutationObserver !== "undefined") { |
|
|
|
} else if (typeof MutationObserver !== "undefined") { |
|
|
|
let counter = 1; |
|
|
|
let counter = 1; |
|
|
|
let observer = new MutationObserver(nextTickHandler); |
|
|
|
const observer = new MutationObserver(nextTickHandler); |
|
|
|
let textNode = document.createTextNode(String(counter)); |
|
|
|
const textNode = document.createTextNode(String(counter)); |
|
|
|
observer.observe(textNode, { |
|
|
|
observer.observe(textNode, { |
|
|
|
characterData: true |
|
|
|
characterData: true, |
|
|
|
}); |
|
|
|
}); |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
counter = (counter + 1) % 2; |
|
|
|
counter = (counter + 1) % 2; |
|
|
@ -794,16 +827,16 @@ export const nextTick = (function () { |
|
|
|
|
|
|
|
|
|
|
|
return function queueNextTick(cb) { |
|
|
|
return function queueNextTick(cb) { |
|
|
|
let _resolve = void 0; |
|
|
|
let _resolve = void 0; |
|
|
|
let args = [].slice.call(arguments, 1); |
|
|
|
const args = [].slice.call(arguments, 1); |
|
|
|
callbacks.push(function () { |
|
|
|
callbacks.push(() => { |
|
|
|
if (cb) { |
|
|
|
if (cb) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
cb.apply(null, args); |
|
|
|
cb(...args); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.error(e); |
|
|
|
console.error(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (_resolve) { |
|
|
|
} else if (_resolve) { |
|
|
|
_resolve.apply(null, args); |
|
|
|
_resolve(...args); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (!pending) { |
|
|
|
if (!pending) { |
|
|
@ -811,16 +844,16 @@ export const nextTick = (function () { |
|
|
|
timerFunc(); |
|
|
|
timerFunc(); |
|
|
|
} |
|
|
|
} |
|
|
|
// $flow-disable-line
|
|
|
|
// $flow-disable-line
|
|
|
|
if (!cb && typeof Promise !== 'undefined') { |
|
|
|
if (!cb && typeof Promise !== "undefined") { |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
return new Promise(((resolve, reject) => { |
|
|
|
_resolve = resolve; |
|
|
|
_resolve = resolve; |
|
|
|
}); |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
}()); |
|
|
|
|
|
|
|
|
|
|
|
// 数字相关方法
|
|
|
|
// 数字相关方法
|
|
|
|
BI._.each(["random"], function (name) { |
|
|
|
BI._.each(["random"], name => { |
|
|
|
BI[name] = _apply(name); |
|
|
|
BI[name] = _apply(name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
export const random = BI.random; |
|
|
|
export const random = BI.random; |
|
|
@ -833,13 +866,13 @@ export function parseInt(number) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return _global.parseInt(number, radix); |
|
|
|
return _global.parseInt(number, radix); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
throw new Error(number + "parse int error"); |
|
|
|
throw new Error(`${number}parse int error`); |
|
|
|
return NaN; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function parseSafeInt(value) { |
|
|
|
export function parseSafeInt(value) { |
|
|
|
let MAX_SAFE_INTEGER = 9007199254740991; |
|
|
|
const MAX_SAFE_INTEGER = 9007199254740991; |
|
|
|
|
|
|
|
|
|
|
|
return value |
|
|
|
return value |
|
|
|
? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) |
|
|
|
? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) |
|
|
|
: (value === 0 ? value : 0); |
|
|
|
: (value === 0 ? value : 0); |
|
|
@ -849,8 +882,7 @@ export function parseFloat(number) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return _global.parseFloat(number); |
|
|
|
return _global.parseFloat(number); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
throw new Error(number + "parse float error"); |
|
|
|
throw new Error(`${number}parse float error`); |
|
|
|
return NaN; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -863,11 +895,11 @@ export function isPositiveInteger(number) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isNegativeInteger(number) { |
|
|
|
export function isNegativeInteger(number) { |
|
|
|
return /^\-[1-9][0-9]*$/.test(number); |
|
|
|
return /^-[1-9][0-9]*$/.test(number); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isInteger(number) { |
|
|
|
export function isInteger(number) { |
|
|
|
return /^\-?\d+$/.test(number); |
|
|
|
return /^-?\d+$/.test(number); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isNumeric(number) { |
|
|
|
export function isNumeric(number) { |
|
|
@ -882,6 +914,7 @@ export function isOdd(number) { |
|
|
|
if (!isInteger(number)) { |
|
|
|
if (!isInteger(number)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return (number & 1) === 1; |
|
|
|
return (number & 1) === 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -889,6 +922,7 @@ export function isEven(number) { |
|
|
|
if (!isInteger(number)) { |
|
|
|
if (!isInteger(number)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return (number & 1) === 0; |
|
|
|
return (number & 1) === 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -901,24 +935,26 @@ export function sum(array, iteratee, context) { |
|
|
|
sum += Number(item); |
|
|
|
sum += Number(item); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return sum; |
|
|
|
return sum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function average(array, iteratee, context) { |
|
|
|
export function average(array, iteratee, context) { |
|
|
|
const sumResult = sum(array, iteratee, context); |
|
|
|
const sumResult = sum(array, iteratee, context); |
|
|
|
|
|
|
|
|
|
|
|
return sumResult / array.length; |
|
|
|
return sumResult / array.length; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function trim() { |
|
|
|
export function trim(...args) { |
|
|
|
return BI._.trim.apply(BI._, arguments); |
|
|
|
return BI._.trim(...args); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function toUpperCase(string) { |
|
|
|
export function toUpperCase(string) { |
|
|
|
return (string + "").toLocaleUpperCase(); |
|
|
|
return (`${string}`).toLocaleUpperCase(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function toLowerCase(string) { |
|
|
|
export function toLowerCase(string) { |
|
|
|
return (string + "").toLocaleLowerCase(); |
|
|
|
return (`${string}`).toLocaleLowerCase(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isEndWithBlank(string) { |
|
|
|
export function isEndWithBlank(string) { |
|
|
@ -926,12 +962,13 @@ export function isEndWithBlank(string) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function isLiteral(exp) { |
|
|
|
export function isLiteral(exp) { |
|
|
|
return /^\s?(true|false|-?[\d\.]+|'[^']*'|"[^"]*")\s?$/.test(exp); |
|
|
|
return /^\s?(true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/.test(exp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function stripQuotes(str) { |
|
|
|
export function stripQuotes(str) { |
|
|
|
const a = str.charCodeAt(0); |
|
|
|
const a = str.charCodeAt(0); |
|
|
|
const b = str.charCodeAt(str.length - 1); |
|
|
|
const b = str.charCodeAt(str.length - 1); |
|
|
|
|
|
|
|
|
|
|
|
return a === b && (a === 0x22 || a === 0x27) |
|
|
|
return a === b && (a === 0x22 || a === 0x27) |
|
|
|
? str.slice(1, -1) |
|
|
|
? str.slice(1, -1) |
|
|
|
: str; |
|
|
|
: str; |
|
|
@ -1015,6 +1052,7 @@ export function leftPad(val, size, ch) { |
|
|
|
while (result.length < size) { |
|
|
|
while (result.length < size) { |
|
|
|
result = ch + result; |
|
|
|
result = ch + result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result.toString(); |
|
|
|
return result.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1030,7 +1068,8 @@ export function leftPad(val, size, ch) { |
|
|
|
* @return {String} 做了替换后的字符串 |
|
|
|
* @return {String} 做了替换后的字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function format(format) { |
|
|
|
export function format(format) { |
|
|
|
var args = Array.prototype.slice.call(arguments, 1); |
|
|
|
const args = Array.prototype.slice.call(arguments, 1); |
|
|
|
|
|
|
|
|
|
|
|
return format.replace(/\{(\d+)\}/g, (m, i) => args[i]); |
|
|
|
return format.replace(/\{(\d+)\}/g, (m, i) => args[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1065,25 +1104,26 @@ export function checkDateVoid(YY, MM, DD, minDate, maxDate) { |
|
|
|
} else if (YY > maxDate[0]) { |
|
|
|
} else if (YY > maxDate[0]) { |
|
|
|
back = ["y", 1]; |
|
|
|
back = ["y", 1]; |
|
|
|
} else if (YY >= minDate[0] && YY <= maxDate[0]) { |
|
|
|
} else if (YY >= minDate[0] && YY <= maxDate[0]) { |
|
|
|
if (YY == minDate[0]) { |
|
|
|
if (YY === minDate[0]) { |
|
|
|
if (MM < minDate[1]) { |
|
|
|
if (MM < minDate[1]) { |
|
|
|
back = ["m"]; |
|
|
|
back = ["m"]; |
|
|
|
} else if (MM == minDate[1]) { |
|
|
|
} else if (MM === minDate[1]) { |
|
|
|
if (DD < minDate[2]) { |
|
|
|
if (DD < minDate[2]) { |
|
|
|
back = ["d"]; |
|
|
|
back = ["d"]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (YY == maxDate[0]) { |
|
|
|
if (YY === maxDate[0]) { |
|
|
|
if (MM > maxDate[1]) { |
|
|
|
if (MM > maxDate[1]) { |
|
|
|
back = ["m", 1]; |
|
|
|
back = ["m", 1]; |
|
|
|
} else if (MM == maxDate[1]) { |
|
|
|
} else if (MM === maxDate[1]) { |
|
|
|
if (DD > maxDate[2]) { |
|
|
|
if (DD > maxDate[2]) { |
|
|
|
back = ["d", 1]; |
|
|
|
back = ["d", 1]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return back; |
|
|
|
return back; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1096,8 +1136,9 @@ export function checkDateLegal(str) { |
|
|
|
if (ar.length <= 2) { |
|
|
|
if (ar.length <= 2) { |
|
|
|
return MM >= 1 && MM <= 12; |
|
|
|
return MM >= 1 && MM <= 12; |
|
|
|
} |
|
|
|
} |
|
|
|
let MD = BI.Date._MD.slice(0); |
|
|
|
const MD = BI.Date._MD.slice(0); |
|
|
|
MD[1] = isLeapYear(YY) ? 29 : 28; |
|
|
|
MD[1] = isLeapYear(YY) ? 29 : 28; |
|
|
|
|
|
|
|
|
|
|
|
return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; |
|
|
|
return MM >= 1 && MM <= 12 && DD <= MD[MM - 1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1114,15 +1155,15 @@ export function parseDateTime(str, fmt) { |
|
|
|
let m; |
|
|
|
let m; |
|
|
|
let d; |
|
|
|
let d; |
|
|
|
// wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。
|
|
|
|
// wei : 对于fmt为‘YYYYMM’或者‘YYYYMMdd’的格式,str的值为类似'201111'的形式,因为年月之间没有分隔符,所以正则表达式分割无效,导致bug7376。
|
|
|
|
let a = str.split(/\W+/); |
|
|
|
const a = str.split(/\W+/); |
|
|
|
if (fmt.toLowerCase() == "%y%x" || fmt.toLowerCase() == "%y%x%d") { |
|
|
|
if (fmt.toLowerCase() === "%y%x" || fmt.toLowerCase() === "%y%x%d") { |
|
|
|
let yearlength = 4; |
|
|
|
const yearlength = 4; |
|
|
|
let otherlength = 2; |
|
|
|
const otherlength = 2; |
|
|
|
a[0] = str.substring(0, yearlength); |
|
|
|
a[0] = str.substring(0, yearlength); |
|
|
|
a[1] = str.substring(yearlength, yearlength + otherlength); |
|
|
|
a[1] = str.substring(yearlength, yearlength + otherlength); |
|
|
|
a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); |
|
|
|
a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); |
|
|
|
} |
|
|
|
} |
|
|
|
let b = fmt.match(/%./g); |
|
|
|
const b = fmt.match(/%./g); |
|
|
|
let i = 0, j = 0; |
|
|
|
let i = 0, j = 0; |
|
|
|
let hr = 0; |
|
|
|
let hr = 0; |
|
|
|
let min = 0; |
|
|
|
let min = 0; |
|
|
@ -1150,7 +1191,7 @@ export function parseDateTime(str, fmt) { |
|
|
|
case "%b": |
|
|
|
case "%b": |
|
|
|
case "%B": |
|
|
|
case "%B": |
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { |
|
|
|
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { |
|
|
|
m = j; |
|
|
|
m = j; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -1182,6 +1223,7 @@ export function parseDateTime(str, fmt) { |
|
|
|
case "%S": |
|
|
|
case "%S": |
|
|
|
sec = _global.parseInt(a[i], 10); |
|
|
|
sec = _global.parseInt(a[i], 10); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// if (!a[i]) {
|
|
|
|
// if (!a[i]) {
|
|
|
@ -1205,45 +1247,46 @@ export function parseDateTime(str, fmt) { |
|
|
|
if (isNaN(sec)) { |
|
|
|
if (isNaN(sec)) { |
|
|
|
sec = today.getSeconds(); |
|
|
|
sec = today.getSeconds(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (y != 0) { |
|
|
|
if (y !== 0) { |
|
|
|
return BI.getDate(y, m, d, hr, min, sec); |
|
|
|
return BI.getDate(y, m, d, hr, min, sec); |
|
|
|
} |
|
|
|
} |
|
|
|
y = 0; |
|
|
|
y = 0; |
|
|
|
m = -1; |
|
|
|
m = -1; |
|
|
|
d = 0; |
|
|
|
d = 0; |
|
|
|
for (i = 0; i < a.length; ++i) { |
|
|
|
for (i = 0; i < a.length; ++i) { |
|
|
|
if (a[i].search(/[a-zA-Z]+/) != -1) { |
|
|
|
if (a[i].search(/[a-zA-Z]+/) !== -1) { |
|
|
|
let t = -1; |
|
|
|
let t = -1; |
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { |
|
|
|
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { |
|
|
|
t = j; |
|
|
|
t = j; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (t != -1) { |
|
|
|
if (t !== -1) { |
|
|
|
if (m != -1) { |
|
|
|
if (m !== -1) { |
|
|
|
d = m + 1; |
|
|
|
d = m + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
m = t; |
|
|
|
m = t; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (_global.parseInt(a[i], 10) <= 12 && m == -1) { |
|
|
|
} else if (_global.parseInt(a[i], 10) <= 12 && m === -1) { |
|
|
|
m = a[i] - 1; |
|
|
|
m = a[i] - 1; |
|
|
|
} else if (_global.parseInt(a[i], 10) > 31 && y == 0) { |
|
|
|
} else if (_global.parseInt(a[i], 10) > 31 && y === 0) { |
|
|
|
y = _global.parseInt(a[i], 10); |
|
|
|
y = _global.parseInt(a[i], 10); |
|
|
|
(y < 100) && (y += (y > 29) ? 1900 : 2000); |
|
|
|
(y < 100) && (y += (y > 29) ? 1900 : 2000); |
|
|
|
} else if (d == 0) { |
|
|
|
} else if (d === 0) { |
|
|
|
d = a[i]; |
|
|
|
d = a[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (y == 0) { |
|
|
|
if (y === 0) { |
|
|
|
y = today.getFullYear(); |
|
|
|
y = today.getFullYear(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (m === -1) { |
|
|
|
if (m === -1) { |
|
|
|
m = today.getMonth(); |
|
|
|
m = today.getMonth(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (m != -1 && d != 0) { |
|
|
|
if (m !== -1 && d !== 0) { |
|
|
|
return BI.getDate(y, m, d, hr, min, sec); |
|
|
|
return BI.getDate(y, m, d, hr, min, sec); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return today; |
|
|
|
return today; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1292,8 +1335,10 @@ export function getDate(...args) { |
|
|
|
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
|
|
|
|
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
|
|
|
|
const localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数
|
|
|
|
const localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数
|
|
|
|
const utc = localTime + localOffset; // utc即GMT时间标准时区
|
|
|
|
const utc = localTime + localOffset; // utc即GMT时间标准时区
|
|
|
|
|
|
|
|
|
|
|
|
return new Date(utc + BI.timeZone);// + Pool.timeZone.offset);
|
|
|
|
return new Date(utc + BI.timeZone);// + Pool.timeZone.offset);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return dt; |
|
|
|
return dt; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1342,6 +1387,7 @@ export function getTime() { |
|
|
|
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
|
|
|
|
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
|
|
|
|
return dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000; |
|
|
|
return dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return dt.getTime(); |
|
|
|
return dt.getTime(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|