Skip to content

Commit

Permalink
1.5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Mar 31, 2018
1 parent 1201e9f commit a46abfb
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
31 changes: 18 additions & 13 deletions dist/xe-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* xe-utils.js v1.5.11
* xe-utils.js v1.5.12
* (c) 2017-2018 Xu Liangzhan
* ISC License.
* @preserve
Expand All @@ -11,6 +11,8 @@
}(this, function () {
'use strict'

var objectToString = Object.prototype.toString

/**
* 判断是否非数值
*
Expand All @@ -34,7 +36,7 @@
* @return {Boolean}
*/
var isArray = Array.isArray || function (val) {
return Object.prototype.toString.call(val) === '[object Array]'
return objectToString.call(val) === '[object Array]'
}

/**
Expand Down Expand Up @@ -102,7 +104,7 @@
* @return {Boolean}
*/
function isRegExp (val) {
return val ? val.constructor === RegExp : false
return objectToString.call(val) === '[object RegExp]'
}

/**
Expand Down Expand Up @@ -132,7 +134,7 @@
* @return {Boolean}
*/
function isDate (val) {
return val ? val.constructor === Date : false
return objectToString.call(val) === '[object Date]'
}

/**
Expand All @@ -142,7 +144,7 @@
* @return {Boolean}
*/
function isError (val) {
return val ? val.constructor === Error : false
return objectToString.call(val) === '[object Error]'
}

/**
Expand Down Expand Up @@ -198,7 +200,7 @@
* @return {Boolean}
*/
function isArguments (val) {
return String(val) === '[object Arguments]'
return objectToString.call(val) === '[object Arguments]'
}

/**
Expand Down Expand Up @@ -897,7 +899,6 @@
if (date) {
date = stringToDate(date)
if (isDate(date)) {
var result = format || 'yyyy-MM-dd HH:mm:ss'
var weeks = ['日', '一', '二', '三', '四', '五', '六']
var resDate = {
'q+': Math.floor((date.getMonth() + 3) / 3),
Expand All @@ -909,13 +910,15 @@
's+': date.getSeconds(),
'S': date.getMilliseconds()
}
if (/(y+)/.test(result)) {
result = result.replace(RegExp.$1, ('' + date.getFullYear()).substr(4 - RegExp.$1.length))
}
var result = String(format || 'yyyy-MM-dd HH:mm:ss').replace(/(y+)/, function ($1) {
return ('' + date.getFullYear()).substr(4 - $1.length)
})
for (var key in resDate) {
if (resDate.hasOwnProperty(key) && new RegExp('(' + key + ')').test(result)) {
if (resDate.hasOwnProperty(key)) {
var val = '' + resDate[key]
result = result.replace(RegExp.$1, (key === 'q+' || key === 'E+') ? weeks[val] : (RegExp.$1.length === 1 ? val : ('00' + val).substr(val.length)))
result = result.replace(new RegExp('(' + key + ')'), function ($1) {
return (key === 'q+' || key === 'E+') ? weeks[val] : ($1.length === 1 ? val : ('00' + val).substr(val.length))
})
}
}
return result
Expand Down Expand Up @@ -1125,6 +1128,8 @@
isString: isString,
isRegExp: isRegExp,
isObject: isObject,
isPlainObject: isPlainObject,
isDate: isDate,
isError: isError,
isTypeError: isTypeError,
isEmpty: isEmpty,
Expand Down Expand Up @@ -1356,7 +1361,7 @@

coreMethods.objectAssign(XEUtils, {
mixin: mixin,
version: '1.5.11',
version: '1.5.12',
$name: 'XEUtils'
})

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 index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function mixin (methods) {

coreMethods.objectAssign(XEUtils, {
mixin: mixin,
version: '1.5.11',
version: '1.5.12',
$name: 'XEUtils'
})

Expand Down
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.11",
"version": "1.5.12",
"description": "XEUtils 函数库",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions src/core/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { arrayMap } from './array'
import { stringToDate } from './date'

var objectToString = Object.prototype.toString

/**
* 判断是否非数值
*
Expand All @@ -24,7 +26,7 @@ export var isFinite = window.isFinite
* @return {Boolean}
*/
export var isArray = Array.isArray || function (val) {
return Object.prototype.toString.call(val) === '[object Array]'
return objectToString.call(val) === '[object Array]'
}

/**
Expand Down Expand Up @@ -92,7 +94,7 @@ export function isNumber (val) {
* @return {Boolean}
*/
export function isRegExp (val) {
return val ? val.constructor === RegExp : false
return objectToString.call(val) === '[object RegExp]'
}

/**
Expand Down Expand Up @@ -122,7 +124,7 @@ export function isPlainObject (val) {
* @return {Boolean}
*/
export function isDate (val) {
return val ? val.constructor === Date : false
return objectToString.call(val) === '[object Date]'
}

/**
Expand All @@ -132,7 +134,7 @@ export function isDate (val) {
* @return {Boolean}
*/
export function isError (val) {
return val ? val.constructor === Error : false
return objectToString.call(val) === '[object Error]'
}

/**
Expand Down Expand Up @@ -188,7 +190,7 @@ export function isSymbol (val) {
* @return {Boolean}
*/
export function isArguments (val) {
return String(val) === '[object Arguments]'
return objectToString.call(val) === '[object Arguments]'
}

/**
Expand Down
13 changes: 7 additions & 6 deletions src/core/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function dateToString (date, format) {
if (date) {
date = stringToDate(date)
if (isDate(date)) {
var result = format || 'yyyy-MM-dd HH:mm:ss'
var weeks = ['日', '一', '二', '三', '四', '五', '六']
var resDate = {
'q+': Math.floor((date.getMonth() + 3) / 3),
Expand All @@ -79,13 +78,15 @@ export function dateToString (date, format) {
's+': date.getSeconds(),
'S': date.getMilliseconds()
}
if (/(y+)/.test(result)) {
result = result.replace(RegExp.$1, ('' + date.getFullYear()).substr(4 - RegExp.$1.length))
}
var result = String(format || 'yyyy-MM-dd HH:mm:ss').replace(/(y+)/, function ($1) {
return ('' + date.getFullYear()).substr(4 - $1.length)
})
for (var key in resDate) {
if (resDate.hasOwnProperty(key) && new RegExp('(' + key + ')').test(result)) {
if (resDate.hasOwnProperty(key)) {
var val = '' + resDate[key]
result = result.replace(RegExp.$1, (key === 'q+' || key === 'E+') ? weeks[val] : (RegExp.$1.length === 1 ? val : ('00' + val).substr(val.length)))
result = result.replace(new RegExp('(' + key + ')'), function ($1) {
return (key === 'q+' || key === 'E+') ? weeks[val] : ($1.length === 1 ? val : ('00' + val).substr(val.length))
})
}
}
return result
Expand Down
4 changes: 3 additions & 1 deletion src/core/methods.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNaN, isFinite, isFloat, isInteger, isFunction, isBoolean, isString, isRegExp, isObject, isError, isTypeError, isEmpty, isNull, isSymbol, isArguments, isElement, isDocument, isWindow, isFormData, isLeapYear, getType, uniqueId, getSize, lastIndexOf, includes, contains, objectAssign, assign, extend, stringToJson, jsonToString, objectKeys, keys, objectValues, values, objectEntries, entries, arrayFirst, first, arrayLast, last, objectEach, arrayEach, each, groupBy, objectMap, clone } from './base'
import { isNaN, isFinite, isFloat, isInteger, isFunction, isBoolean, isString, isRegExp, isPlainObject, isObject, isDate, isError, isTypeError, isEmpty, isNull, isSymbol, isArguments, isElement, isDocument, isWindow, isFormData, isLeapYear, getType, uniqueId, getSize, lastIndexOf, includes, contains, objectAssign, assign, extend, stringToJson, jsonToString, objectKeys, keys, objectValues, values, objectEntries, entries, arrayFirst, first, arrayLast, last, objectEach, arrayEach, each, groupBy, objectMap, clone } from './base'
import { arrayUniq, uniq, arrayUnion, union, arraySort, sort, arrayShuffle, shuffle, arraySample, sample, arraySome, some, arrayEvery, every, arrayFilter, filter, arrayFind, find, arrayMap, map } from './array'
import { timestamp, now, stringToDate, dateToString, getWhatMonth, getWhatWeek, getWhatDay, getDaysOfMonth, getDateDiff } from './date'
import { escape, unescape } from './string'
Expand All @@ -14,6 +14,8 @@ export var coreMethods = {
isString: isString,
isRegExp: isRegExp,
isObject: isObject,
isPlainObject: isPlainObject,
isDate: isDate,
isError: isError,
isTypeError: isTypeError,
isEmpty: isEmpty,
Expand Down

0 comments on commit a46abfb

Please sign in to comment.