Skip to content

Commit

Permalink
1.5.14
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Apr 24, 2018
1 parent c3423de commit 66fefd8
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 88 deletions.
74 changes: 37 additions & 37 deletions dist/xe-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* xe-utils.js v1.5.13
* xe-utils.js v1.5.14
* (c) 2017-2018 Xu Liangzhan
* ISC License.
* @preserve
Expand All @@ -13,7 +13,7 @@

function XEUtils () { }

XEUtils.version = '1.5.13'
XEUtils.version = '1.5.14'
XEUtils.mixin = function (methods) {
return Object.assign(XEUtils, methods)
}
Expand All @@ -26,8 +26,8 @@
*/
function arrayUniq (array) {
var result = []
if (isArray(array)) {
arrayEach(array, function (value) {
if (baseExports.isArray(array)) {
baseExports.arrayEach(array, function (value) {
if (!result.includes(value)) {
result.push(value)
}
Expand Down Expand Up @@ -60,8 +60,8 @@
* @return {Array}
*/
function arraySort (arr, iteratee, context) {
if (isArray(arr)) {
return arr.sort(iteratee ? isFunction(iteratee) ? iteratee.bind(context || this) : function (v1, v2) {
if (baseExports.isArray(arr)) {
return arr.sort(iteratee ? baseExports.isFunction(iteratee) ? iteratee.bind(context || this) : function (v1, v2) {
return v1[iteratee] > v2[iteratee] ? 1 : -1
} : function (v1, v2) {
return v1 > v2 ? 1 : -1
Expand All @@ -79,8 +79,8 @@
*/
function arrayShuffle (array) {
var result = []
for (var list = objectValues(array), len = list.length - 1; len >= 0; len--) {
var index = len > 0 ? getRandom(0, len) : 0
for (var list = baseExports.objectValues(array), len = list.length - 1; len >= 0; len--) {
var index = len > 0 ? numberExports.getRandom(0, len) : 0
result.push(list[index])
list.splice(index, 1)
}
Expand Down Expand Up @@ -117,7 +117,7 @@
*/
function arraySome (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.some(iteratee, context || this)
} else {
for (var index in obj) {
Expand All @@ -143,7 +143,7 @@
*/
function arrayEvery (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.every(iteratee, context || this)
} else {
for (var index in obj) {
Expand All @@ -169,11 +169,11 @@
*/
function arrayFilter (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.filter(iteratee, context || this)
} else {
var result = {}
each(obj, function (val, key) {
baseExports.each(obj, function (val, key) {
if (iteratee.call(context || this, val, key, obj)) {
result[key] = val
}
Expand All @@ -195,7 +195,7 @@
*/
function arrayFind (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.find(iteratee, context || this)
} else {
for (var key in obj) {
Expand All @@ -221,10 +221,10 @@
function arrayMap (obj, iteratee, context) {
var result = []
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.map(iteratee, context || this)
} else {
each(obj, function () {
baseExports.each(obj, function () {
result.push(iteratee.apply(context || this, arguments))
})
}
Expand Down Expand Up @@ -495,7 +495,7 @@
* @return {Boolean}
*/
function isLeapYear (date) {
var currentDate = date ? stringToDate(date) : new Date()
var currentDate = date ? dateExports.stringToDate(date) : new Date()
var year = currentDate.getFullYear()
return (year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0)
}
Expand Down Expand Up @@ -842,7 +842,7 @@
}

function cloneArr (arr) {
return arrayMap(arr, function (val, index) {
return arrayExports.arrayMap(arr, function (val, index) {
return deepClone(val)
})
}
Expand Down Expand Up @@ -924,7 +924,7 @@
function browse () {
var result = {}
var $body = document.body || document.documentElement
arrayEach(['webkit', 'khtml', 'moz', 'ms', 'o'], function (core) {
baseExports.arrayEach(['webkit', 'khtml', 'moz', 'ms', 'o'], function (core) {
result['-' + core] = !!$body[core + 'MatchesSelector']
})
return result
Expand All @@ -947,23 +947,23 @@
*/
function cookie (name, value, options) {
var inserts = []
if (isArray(name)) {
if (baseExports.isArray(name)) {
inserts = name
} else if (arguments.length > 1) {
inserts = [objectAssign({ name: name, value: value }, options)]
} else if (isObject(name)) {
inserts = [baseExports.objectAssign({ name: name, value: value }, options)]
} else if (baseExports.isObject(name)) {
inserts = [name]
}
if (inserts.length > 0) {
arrayEach(inserts, function (obj) {
var opts = objectAssign({}, obj)
baseExports.arrayEach(inserts, function (obj) {
var opts = baseExports.objectAssign({}, obj)
var values = []
if (opts.name) {
values.push(encodeURIComponent(opts.name) + '=' + encodeURIComponent(isObject(opts.value) ? JSON.stringify(opts.value) : opts.value))
values.push(encodeURIComponent(opts.name) + '=' + encodeURIComponent(baseExports.isObject(opts.value) ? JSON.stringify(opts.value) : opts.value))
if (opts.expires !== undefined) {
opts.expires = new Date(new Date().getTime() + parseFloat(opts.expires) * 86400000).toUTCString()
}
arrayEach(['expires', 'path', 'domain', 'secure'], function (key) {
baseExports.arrayEach(['expires', 'path', 'domain', 'secure'], function (key) {
if (opts[key] !== undefined) {
values.push(key + '=' + opts[key])
}
Expand All @@ -974,7 +974,7 @@
} else {
var result = {}
if (document.cookie) {
arrayEach(document.cookie.split('; '), function (val) {
baseExports.arrayEach(document.cookie.split('; '), function (val) {
var keyIndex = val.indexOf('=')
result[decodeURIComponent(val.substring(0, keyIndex))] = decodeURIComponent(val.substring(keyIndex + 1) || '')
})
Expand All @@ -983,7 +983,7 @@
}
}

objectAssign(cookie, {
baseExports.objectAssign(cookie, {
setItem: function (name, key) {
cookie(name, key)
},
Expand Down Expand Up @@ -1031,16 +1031,16 @@
*/
function stringToDate (str, format) {
if (str) {
if (isDate(str)) {
if (baseExports.isDate(str)) {
return str
}
if (!isNaN(str)) {
return new Date(str)
}
if (isString(str)) {
if (baseExports.isString(str)) {
format = format || 'yyyy-MM-dd HH:mm:ss.SSS'
var dates = []
arrayEach(dateFormatRules, function (item) {
baseExports.arrayEach(dateFormatRules, function (item) {
for (var arr, sIndex, index = 0, rules = item.rules, len = rules.length; index < len; index++) {
arr = rules[index]
sIndex = format.indexOf(arr[0])
Expand Down Expand Up @@ -1068,7 +1068,7 @@
function dateToString (date, format) {
if (date) {
date = stringToDate(date)
if (isDate(date)) {
if (baseExports.isDate(date)) {
var weeks = ['日', '一', '二', '三', '四', '五', '六']
var resDate = {
'q+': Math.floor((date.getMonth() + 3) / 3),
Expand Down Expand Up @@ -1232,7 +1232,7 @@
var result = {}
var params = uri.split('?')[1] || ''
if (params) {
arrayEach(params.split('&'), function (param) {
baseExports.arrayEach(params.split('&'), function (param) {
var items = param.split('=')
result[decodeURIComponent(items[0])] = decodeURIComponent(items[1] || '')
})
Expand All @@ -1246,7 +1246,7 @@

function getBaseURL () {
var pathname = $locat.pathname
var lastIndex = lastIndexOf(pathname, '/') + 1
var lastIndex = baseExports.lastIndexOf(pathname, '/') + 1
return getLocatOrigin() + (lastIndex === pathname.length ? pathname : pathname.substring(0, lastIndex))
}

Expand Down Expand Up @@ -1285,7 +1285,7 @@
}

function sortData (arr, iteratee) {
return (isFunction(iteratee) ? arraySort(arrayMap(arr, iteratee, this)) : arraySort(arr, iteratee))
return (baseExports.isFunction(iteratee) ? arrayExports.arraySort(arrayExports.arrayMap(arr, iteratee, this)) : arrayExports.arraySort(arr, iteratee))
}

/**
Expand Down Expand Up @@ -1330,12 +1330,12 @@
}

var unescapeMap = {}
arrayEach(objectKeys(escapeMap), function (key) {
baseExports.arrayEach(baseExports.objectKeys(escapeMap), function (key) {
unescapeMap[escapeMap[key]] = key
})

function formatEscaper (dataMap) {
var replaceRegexp = new RegExp('(?:' + objectKeys(dataMap).join('|') + ')', 'g')
var replaceRegexp = new RegExp('(?:' + baseExports.objectKeys(dataMap).join('|') + ')', 'g')
return function (str) {
return String(str || '').replace(replaceRegexp, function (match) {
return dataMap[match]
Expand Down Expand Up @@ -1366,7 +1366,7 @@

var methodExports = {}

objectAssign(
baseExports.objectAssign(
methodExports,
arrayExports,
baseExports,
Expand Down
4 changes: 2 additions & 2 deletions dist/xe-utils.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xe-utils",
"version": "1.5.13",
"version": "1.5.14",
"description": "XEUtils 函数库",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function XEUtils () {}

XEUtils.version = '1.5.13'
XEUtils.version = '1.5.14'
XEUtils.mixin = function (methods) {
return Object.assign(XEUtils, methods)
}
Expand Down
30 changes: 15 additions & 15 deletions src/method/array.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

var { getRandom } = require('./number')
var { isFunction, isArray, each, arrayEach, objectValues } = require('./base')
var numberExports = require('./number')
var baseExports = require('./base')

/**
* 数组去重
Expand All @@ -11,8 +11,8 @@ var { isFunction, isArray, each, arrayEach, objectValues } = require('./base')
*/
function arrayUniq (array) {
var result = []
if (isArray(array)) {
arrayEach(array, function (value) {
if (baseExports.isArray(array)) {
baseExports.arrayEach(array, function (value) {
if (!result.includes(value)) {
result.push(value)
}
Expand Down Expand Up @@ -45,8 +45,8 @@ var union = arrayUnion
* @return {Array}
*/
function arraySort (arr, iteratee, context) {
if (isArray(arr)) {
return arr.sort(iteratee ? isFunction(iteratee) ? iteratee.bind(context || this) : function (v1, v2) {
if (baseExports.isArray(arr)) {
return arr.sort(iteratee ? baseExports.isFunction(iteratee) ? iteratee.bind(context || this) : function (v1, v2) {
return v1[iteratee] > v2[iteratee] ? 1 : -1
} : function (v1, v2) {
return v1 > v2 ? 1 : -1
Expand All @@ -64,8 +64,8 @@ var sort = arraySort
*/
function arrayShuffle (array) {
var result = []
for (var list = objectValues(array), len = list.length - 1; len >= 0; len--) {
var index = len > 0 ? getRandom(0, len) : 0
for (var list = baseExports.objectValues(array), len = list.length - 1; len >= 0; len--) {
var index = len > 0 ? numberExports.getRandom(0, len) : 0
result.push(list[index])
list.splice(index, 1)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ var sample = arraySample
*/
function arraySome (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.some(iteratee, context || this)
} else {
for (var index in obj) {
Expand All @@ -128,7 +128,7 @@ var some = arraySome
*/
function arrayEvery (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.every(iteratee, context || this)
} else {
for (var index in obj) {
Expand All @@ -154,11 +154,11 @@ var every = arrayEvery
*/
function arrayFilter (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.filter(iteratee, context || this)
} else {
var result = {}
each(obj, function (val, key) {
baseExports.each(obj, function (val, key) {
if (iteratee.call(context || this, val, key, obj)) {
result[key] = val
}
Expand All @@ -180,7 +180,7 @@ var filter = arrayFilter
*/
function arrayFind (obj, iteratee, context) {
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.find(iteratee, context || this)
} else {
for (var key in obj) {
Expand All @@ -206,10 +206,10 @@ var find = arrayFind
function arrayMap (obj, iteratee, context) {
var result = []
if (obj) {
if (isArray(obj)) {
if (baseExports.isArray(obj)) {
return obj.map(iteratee, context || this)
} else {
each(obj, function () {
baseExports.each(obj, function () {
result.push(iteratee.apply(context || this, arguments))
})
}
Expand Down
Loading

0 comments on commit 66fefd8

Please sign in to comment.