New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

xe-utils

Package Overview
Dependencies
Maintainers
1
Versions
305
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xe-utils - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

dist/xe-utils.js

2

package.json
{
"name": "xe-utils",
"version": "1.2.1",
"version": "1.3.0",
"description": "XEUtils 是一个轻量级的函数库,提供一套实用丰富函数",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,4 +5,24 @@ # XEUtils 轻量级的函数库,提供一套实用丰富函数

### 通过NPM安装最新版本
### 直接引用 script 全局安装,XEUtils 会定义为全局变量
``` shell
<script src="./dist/xe-utils.min.js" type="text/javascript"></script>
// 全局调用
XEUtils.dateToString(new Date(), 'yyyy-MM-dd')
```
### AMD 安装, 以 require.js 为例
``` shell
require.config({
paths: {
'xe-utils': './dist/xe-utils.min'
}
})
require(['xe-utils'], function (XEUtils) {
XEUtils.dateToString(new Date(), 'yyyy-MM-dd')
})
```
### ES6 Module 安装方式
``` shell
npm install xe-utils --save

@@ -16,3 +36,3 @@ ```

const dateStr = dateToString(new Date(), 'yyyy-MM-dd')
const date = stringToDate(dateStr, 'yyyy-MM-dd')
const date = stringToDate('11/20/2017 10:10:30', 'MM/dd/yyyy HH:mm:ss')
```

@@ -25,3 +45,3 @@

const dateStr = XEUtils.dateToString(new Date(), 'yyyy-MM-dd')
const date = XEUtils.stringToDate(dateStr, 'yyyy-MM-dd')
const date = XEUtils.stringToDate('11/20/2017 10:10:30', 'MM/dd/yyyy HH:mm:ss')
```

@@ -51,152 +71,152 @@

```shell
import { isNaN } from 'xe-utils'
import XEUtils from 'xe-utils'
isNaN(undefined) // true
isNaN({}) // true
isNaN('num') // true
isNaN(true) // false
isNaN(null) // false
isNaN('') // false
XEUtils.isNaN(undefined) // true
XEUtils.isNaN({}) // true
XEUtils.isNaN('num') // true
XEUtils.isNaN(true) // false
XEUtils.isNaN(null) // false
XEUtils.isNaN('') // false
```
#### isFinite (val) 判断是否为有限数值
```shell
import { isFinite } from 'xe-utils'
import XEUtils from 'xe-utils'
isFinite(NaN) // false
isFinite(0) // true
isFinite(2e64) // true
XEUtils.isFinite(NaN) // false
XEUtils.isFinite(0) // true
XEUtils.isFinite(2e64) // true
```
#### isArray (val) 判断是否数组
```shell
import { isArray } from 'xe-utils'
import XEUtils from 'xe-utils'
isArray(null) // false
isArray({}) // false
isArray([1,2,3]) // true
XEUtils.isArray(null) // false
XEUtils.isArray({}) // false
XEUtils.isArray([1,2,3]) // true
```
#### isFloat (val) 判断是否小数
```shell
import { isFloat } from 'xe-utils'
import XEUtils from 'xe-utils'
isFloat(null) // false
isFloat(0) // false
isFloat(3) // false
isFloat(3.3) // true
XEUtils.isFloat(null) // false
XEUtils.isFloat(0) // false
XEUtils.isFloat(3) // false
XEUtils.isFloat(3.3) // true
```
#### isInteger (val) 判断是否整数
```shell
import { isInteger } from 'xe-utils'
import XEUtils from 'xe-utils'
isInteger(null) // false
isInteger(3.3) // false
isInteger(3) // true
isInteger(0) // true
XEUtils.isInteger(null) // false
XEUtils.isInteger(3.3) // false
XEUtils.isInteger(3) // true
XEUtils.isInteger(0) // true
```
#### isFunction (val) 判断是否方法
```shell
import { isFunction } from 'xe-utils'
import XEUtils from 'xe-utils'
isFunction({}) // false
isFunction(function(){}) // true
XEUtils.isFunction({}) // false
XEUtils.isFunction(function(){}) // true
```
#### isBoolean (val) 判断是否Boolean对象
```shell
import { isBoolean } from 'xe-utils'
import XEUtils from 'xe-utils'
isBoolean('false') // false
isBoolean(true) // true
XEUtils.isBoolean('false') // false
XEUtils.isBoolean(true) // true
```
#### isString (val) 判断是否String对象
```shell
import { isString } from 'xe-utils'
import XEUtils from 'xe-utils'
isString(1) // false
isString(true) // false
isString('') // true
isString('abc') // true
XEUtils.isString(1) // false
XEUtils.isString(true) // false
XEUtils.isString('') // true
XEUtils.isString('abc') // true
```
#### isNumber (val) 判断是否Number对象
```shell
import { isNumber } from 'xe-utils'
import XEUtils from 'xe-utils'
isNumber(null) // false
isNumber('1') // false
isNumber(1) // true
XEUtils.isNumber(null) // false
XEUtils.isNumber('1') // false
XEUtils.isNumber(1) // true
```
#### isRegExp (val) 判断是否RegExp对象
```shell
import { isRegExp } from 'xe-utils'
import XEUtils from 'xe-utils'
isRegExp(null) // false
isRegExp('a') // false
isRegExp(new RegExp('a')) // true
isRegExp(/\a/) // true
XEUtils.isRegExp(null) // false
XEUtils.isRegExp('a') // false
XEUtils.isRegExp(new RegExp('a')) // true
XEUtils.isRegExp(/\a/) // true
```
#### isObject (val) 判断是否Object对象
```shell
import { isObject } from 'xe-utils'
import XEUtils from 'xe-utils'
isObject(null) // true
isObject([]) // true
isObject({}) // true
isObject(123) // false
XEUtils.isObject(null) // true
XEUtils.isObject([]) // true
XEUtils.isObject({}) // true
XEUtils.isObject(123) // false
```
#### isPlainObject (val) 判断是否是一个对象
```shell
import { isPlainObject } from 'xe-utils'
import XEUtils from 'xe-utils'
isPlainObject(null) // false
isPlainObject([]) // false
isPlainObject(123) // false
isPlainObject({}) // true
XEUtils.sPlainObject(null) // false
XEUtils.isPlainObject([]) // false
XEUtils.isPlainObject(123) // false
XEUtils.isPlainObject({}) // true
```
#### isDate (val) 判断是否Date对象
```shell
import { isDate } from 'xe-utils'
import XEUtils from 'xe-utils'
isDate('2017-12-20') // false
isDate({}) // false
isDate(1514096716800) // false
isDate(new Date()) // true
XEUtils.isDate('2017-12-20') // false
XEUtils.isDate({}) // false
XEUtils.isDate(1514096716800) // false
XEUtils.isDate(new Date()) // true
```
#### isError (val) 判断是否Error对象
```shell
import { isError } from 'xe-utils'
import XEUtils from 'xe-utils'
isError(null) // false
isError({}) // false
isError(new Error('error')) // true
XEUtils.isError(null) // false
XEUtils.isError({}) // false
XEUtils.isError(new Error('error')) // true
```
#### isTypeError (val) 判断是否TypeError对象
```shell
import { isTypeError } from 'xe-utils'
import XEUtils from 'xe-utils'
isTypeError(null) // false
isTypeError({}) // false
isTypeError(new TypeError('error')) // true
XEUtils.isTypeError(null) // false
XEUtils.isTypeError({}) // false
XEUtils.isTypeError(new TypeError('error')) // true
```
#### isEmpty (val) 判断是否为空,包括空对象、空数值、空字符串
```shell
import { isEmpty } from 'xe-utils'
import XEUtils from 'xe-utils'
isEmpty(0) // true
isEmpty('') // true
isEmpty(null) // true
isEmpty({}) // true
isEmpty([]]) // true
XEUtils.isEmpty(0) // true
XEUtils.isEmpty('') // true
XEUtils.isEmpty(null) // true
XEUtils.isEmpty({}) // true
XEUtils.isEmpty([]]) // true
```
#### isNull (val) 判断是否为Null
```shell
import { isNull } from 'xe-utils'
import XEUtils from 'xe-utils'
isNull(0) // false
isNull('') // false
isNull(null) // true
XEUtils.isNull(0) // false
XEUtils.isNull('') // false
XEUtils.isNull(null) // true
```
#### isSymbol (val) 判断是否Symbol对象
```shell
import { isSymbol } from 'xe-utils'
import XEUtils from 'xe-utils'
isSymbol('a') // false
isSymbol(Symbol('a')) // true
XEUtils.isSymbol('a') // false
XEUtils.isSymbol(Symbol('a')) // true
```

@@ -212,20 +232,20 @@ #### isArguments (val) 判断是否Arguments对象

```shell
import { isElement } from 'xe-utils'
import XEUtils from 'xe-utils'
isElement({}) // false
isElement(document.createElement('div')) // true
XEUtils.isElement({}) // false
XEUtils.isElement(document.createElement('div')) // true
```
#### isDocument (val) 判断是否Document对象
```shell
import { isDocument } from 'xe-utils'
import XEUtils from 'xe-utils'
isDocument(document.createElement('div')) // false
isDocument(document) // true
XEUtils.isDocument(document.createElement('div')) // false
XEUtils.isDocument(document) // true
```
#### isWindow (val) 判断是否Window对象
```shell
import { isWindow } from 'xe-utils'
import XEUtils from 'xe-utils'
isWindow(document) // false
isWindow(window) // true
XEUtils.isWindow(document) // false
XEUtils.isWindow(window) // true
```

@@ -241,122 +261,122 @@ #### isFormData (val) 判断是否FormData对象

```shell
import { isLeapYear } from 'xe-utils'
import XEUtils from 'xe-utils'
isLeapYear('2018-12-01') // false
isLeapYear('2020-12-01') // true
isLeapYear(new Date('2020/12/01')) // true
XEUtils.isLeapYear('2018-12-01') // false
XEUtils.isLeapYear('2020-12-01') // true
XEUtils.isLeapYear(new Date('2020/12/01')) // true
```
#### getType (obj) 获取对象类型
```shell
import { getType } from 'xe-utils'
import XEUtils from 'xe-utils'
getType() // 'undefined'
getType(null) // 'null'
getType('') // 'string'
getType(1) // 'number'
getType([]) // 'array'
getType({}) // 'object'
getType(function(){}) // 'function'
XEUtils.getType() // 'undefined'
XEUtils.getType(null) // 'null'
XEUtils.getType('') // 'string'
XEUtils.getType(1) // 'number'
XEUtils.getType([]) // 'array'
XEUtils.getType({}) // 'object'
XEUtils.getType(function(){}) // 'function'
```
#### uniqueId ( ) 获取一个全局唯一标识
```shell
import { uniqueId } from 'xe-utils'
import XEUtils from 'xe-utils'
uniqueId() // 1
uniqueId() // 2
XEUtils.uniqueId() // 1
XEUtils.uniqueId() // 2
```
#### size ( obj ) 返回对象的长度
```shell
import { size } from 'xe-utils'
import XEUtils from 'xe-utils'
size('123') // 3
size([1, 3]) // 2
size({a: 2, b: 5}) // 2
XEUtils.size('123') // 3
XEUtils.size([1, 3]) // 2
XEUtils.size({a: 2, b: 5}) // 2
```
#### indexOf (obj, val) 返回对象第一个索引值
```shell
import { indexOf } from 'xe-utils'
import XEUtils from 'xe-utils'
indexOf([11], 22) // -1
indexOf([11, 22], 22) // 1
XEUtils.indexOf([11], 22) // -1
XEUtils.indexOf([11, 22], 22) // 1
```
#### lastIndexOf (obj, val) 从最后开始的索引值,返回对象第一个索引值
```shell
import { lastIndexOf } from 'xe-utils'
import XEUtils from 'xe-utils'
lastIndexOf([11], 22) // -1
lastIndexOf([11, 22], 22) // 1
XEUtils.lastIndexOf([11], 22) // -1
XEUtils.lastIndexOf([11, 22], 22) // 1
```
#### includes (obj, val) 判断对象是否包含该值,成功返回true否则false
```shell
import { includes } from 'xe-utils'
import XEUtils from 'xe-utils'
includes([11], 22) // false
includes([11, 22], 22) // true
XEUtils.includes([11], 22) // false
XEUtils.includes([11, 22], 22) // true
```
#### assign (target, ...) 浅拷贝一个或者多个对象到目标对象中
```shell
import { assign, extend } from 'xe-utils'
import XEUtils from 'xe-utils'
const obj1 = {a: null}
assign(obj1, {a: 11}) // {a: 11}
extend(obj1, {a: 11}) // {a: 11}
XEUtils.assign(obj1, {a: 11}) // {a: 11}
XEUtils.extend(obj1, {a: 11}) // {a: 11}
const obj2 = {c: null}
assign(obj2, {a: 11}, {b: 22}) // {a: 11, b: 22, c: null}
extend(obj2, {a: 11}, {b: 22}) // {a: 11, b: 22, c: null}
XEUtils.assign(obj2, {a: 11}, {b: 22}) // {a: 11, b: 22, c: null}
XEUtils.extend(obj2, {a: 11}, {b: 22}) // {a: 11, b: 22, c: null}
```
#### stringToJson (str) 字符串转JSON
```shell
import { stringToJson } from 'xe-utils'
import XEUtils from 'xe-utils'
stringToJson('{"a":1}') // {a: 1}
stringToJson('[11,22]') // [11, 22]
XEUtils.stringToJson('{"a":1}') // {a: 1}
XEUtils.stringToJson('[11,22]') // [11, 22]
```
#### jsonToString (obj) JSON转字符串
```shell
import { jsonToString } from 'xe-utils'
import XEUtils from 'xe-utils'
jsonToString({a: 1}) // '{"a":1}'
jsonToString([11, 22]) // '[11,22]'
XEUtils.jsonToString({a: 1}) // '{"a":1}'
XEUtils.jsonToString([11, 22]) // '[11,22]'
```
#### keys (obj) 获取对象所有属性
```shell
import { keys } from 'xe-utils'
import XEUtils from 'xe-utils'
keys({a: 11}) // ['a']
keys([11, 22]) // [0, 1]
XEUtils.keys({a: 11}) // ['a']
XEUtils.keys([11, 22]) // [0, 1]
```
#### values (obj) 获取对象所有值
```shell
import { values } from 'xe-utils'
import XEUtils from 'xe-utils'
values({a: 11}) // [11]
values([11, 22]) // [11, 22]
XEUtils.values({a: 11}) // [11]
XEUtils.values([11, 22]) // [11, 22]
```
#### entries (obj) 获取对象所有属性、值
```shell
import { entries } from 'xe-utils'
import XEUtils from 'xe-utils'
entries({a: 11}) // [['a', 11]]
entries([11, 22]) // [[0, 11], [1, 22]]
XEUtils.entries({a: 11}) // [['a', 11]]
XEUtils.entries([11, 22]) // [[0, 11], [1, 22]]
```
#### first (obj) 获取对象第一个值
```shell
import { first } from 'xe-utils'
import XEUtils from 'xe-utils'
first({a: 11, b : 22}) // 11
first([11, 22]) // 11
XEUtils.first({a: 11, b : 22}) // 11
XEUtils.first([11, 22]) // 11
```
#### last (obj) 获取对象最后一个值
```shell
import { last } from 'xe-utils'
import XEUtils from 'xe-utils'
last({a: 11, b: 22}) // 22
last([11, 22]) // 22
XEUtils.last({a: 11, b: 22}) // 22
XEUtils.last([11, 22]) // 22
```
#### each ( obj, iteratee, context ) 迭代器
```shell
import { each } from 'xe-utils'
import XEUtils from 'xe-utils'
const result = []
each({a: 11, b: 22}, (item, key) => {
XEUtils.each({a: 11, b: 22}, (item, key) => {
if (key === 'b') {

@@ -369,6 +389,6 @@ result.push(item)

```shell
import { groupBy } from 'xe-utils'
import XEUtils from 'xe-utils'
const result1 = groupBy([{type: 'a'}, {type: 'b'}]], 'type') // {a: [{a: 'a'}], b: [{b: 'b'}]}
const result2 = groupBy([{type: 'a'}, {type: 'b'}]], (item, key) => {
const result1 = XEUtils.groupBy([{type: 'a'}, {type: 'b'}]], 'type') // {a: [{a: 'a'}], b: [{b: 'b'}]}
const result2 = XEUtils.groupBy([{type: 'a'}, {type: 'b'}]], (item, key) => {
return item.type

@@ -379,6 +399,6 @@ }) // {a: [{a: 'a'}], b: [{b: 'b'}]}

```shell
import { mapObject } from 'xe-utils'
import XEUtils from 'xe-utils'
const result = []
mapObject([{type: 'a'}, {type: 'b'}]], (item, key) => {
XEUtils.mapObject([{type: 'a'}, {type: 'b'}]], (item, key) => {
return item.type

@@ -389,10 +409,10 @@ }) // {a: {type: 'a', b: {type: 'b'}}}

```shell
import { clone } from 'xe-utils'
import XEUtils from 'xe-utils'
const v1 = {a: 11, b: {b1: 22}
const v2 = clone({a: 11, b: 22})
const v2 = XEUtils.clone({a: 11, b: 22})
if (v1.b === v2.b) {
// true
}
const v3 = clone(v1, true)
const v3 = XEUtils.clone(v1, true)
if (v1.b === v3.b) {

@@ -405,18 +425,18 @@ // false

```shell
import { uniq } from 'xe-utils'
import XEUtils from 'xe-utils'
uniq([11, 22, 33, 33, 22, 55]) // [11, 22, 33, 55]
XEUtils.uniq([11, 22, 33, 33, 22, 55]) // [11, 22, 33, 55]
```
#### union ( ...array ) 将多个数的值返回唯一的并集数组
```shell
import { union } from 'xe-utils'
import XEUtils from 'xe-utils'
union([11, 22], [33, 22], [44, 11]) // [11, 22, 33, 44]
XEUtils.union([11, 22], [33, 22], [44, 11]) // [11, 22, 33, 44]
```
#### sort ( arr, iteratee, context ) 数组按属性值升序
```shell
import { sort } from 'xe-utils'
import XEUtils from 'xe-utils'
sort([{a: 9}, {a: 4}, {a: 5}], 'a') // [{a: 4}, {a: 5}, {a: 9}]
sort([{a: 9}, {a: 4}, {a: 5}], (v1, v2) => {
XEUtils.sort([{a: 9}, {a: 4}, {a: 5}], 'a') // [{a: 4}, {a: 5}, {a: 9}]
XEUtils.sort([{a: 9}, {a: 4}, {a: 5}], (v1, v2) => {
return v1.a > v2.a ? 1 : -1

@@ -428,20 +448,20 @@ }) // [{a: 4}, {a: 5}, {a: 9}]

```shell
import { shuffle } from 'xe-utils'
import XEUtils from 'xe-utils'
shuffle([11, 22, 33, 44, 55]) // [22, 33, 55, 11, 44]
XEUtils.shuffle([11, 22, 33, 44, 55]) // [22, 33, 55, 11, 44]
```
#### sample ( array, number ) 从一个数组中随机返回几个元素
```shell
import { sample } from 'xe-utils'
import XEUtils from 'xe-utils'
sample([11, 22, 33, 44, 55], 3) // [22, 33, 55]
XEUtils.sample([11, 22, 33, 44, 55], 3) // [22, 33, 55]
```
#### some ( obj, iteratee, context ) 对象中的值中的每一项运行给定函数,如果函数对任一项返回true,则返回true,否则返回false
```shell
import { some } from 'xe-utils'
import XEUtils from 'xe-utils'
some([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.some([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 55
}) // false
some([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.some([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 11

@@ -452,8 +472,8 @@ }) // true

```shell
import { every } from 'xe-utils'
import XEUtils from 'xe-utils'
every([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.every([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 11
}) // false
every([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.every([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 11 || item.a === 22

@@ -464,5 +484,5 @@ }) // true

```shell
import { filter } from 'xe-utils'
import XEUtils from 'xe-utils'
filter([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.filter([{a: 11}, {a: 22}]], (item, key) => {
return item.a > 11

@@ -473,8 +493,8 @@ }) // [{a: 22}]

```shell
import { find } from 'xe-utils'
import XEUtils from 'xe-utils'
find([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.find([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 55
}) // null
find([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.find([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 22

@@ -485,5 +505,5 @@ }) // {a: 22}

```shell
import { map } from 'xe-utils'
import XEUtils from 'xe-utils'
map([{a: 11}, {a: 22}]], (item, key) => {
XEUtils.map([{a: 11}, {a: 22}]], (item, key) => {
return item.a

@@ -495,76 +515,76 @@ }) // [11, 22]

```shell
import { now } from 'xe-utils'
import XEUtils from 'xe-utils'
now() // 1514096716800
XEUtils.now() // 1514096716800
```
#### stringToDate ( str, format ) 字符串转为日期(yyyy年份、MM月份、dd天、HH小时、mm分钟、ss秒、SSS毫秒)
```shell
import { stringToDate } from 'xe-utils'
import XEUtils from 'xe-utils'
stringToDate('2017-12-20') // Wed Dec 20 2017 00:00:00 GMT+0800 (中国标准时间)
stringToDate('2017-12-20 10:10:30') // Wed Dec 20 2017 10:10:30 GMT+0800 (中国标准时间)
stringToDate('12/20/2017', 'MM/dd/yyyy') // Wed Dec 20 2017 00:00:00 GMT+0800 (中国标准时间)
stringToDate('12/20/2017 10:10:30.100', 'MM/dd/yyyy HH:mm') // Wed Dec 20 2017 10:10:00 GMT+0800 (中国标准时间)
stringToDate('12/20/2017 10:10:30.100', 'MM/dd/yyyy HH:mm:ss.SSS') // Wed Dec 20 2017 10:10:30 GMT+0800 (中国标准时间)
XEUtils.stringToDate('2017-12-20') // Wed Dec 20 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.stringToDate('2017-12-20 10:10:30') // Wed Dec 20 2017 10:10:30 GMT+0800 (中国标准时间)
XEUtils.stringToDate('12/20/2017', 'MM/dd/yyyy') // Wed Dec 20 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.stringToDate('12/20/2017 10:10:30.100', 'MM/dd/yyyy HH:mm') // Wed Dec 20 2017 10:10:00 GMT+0800 (中国标准时间)
XEUtils.stringToDate('12/20/2017 10:10:30.100', 'MM/dd/yyyy HH:mm:ss.SSS') // Wed Dec 20 2017 10:10:30 GMT+0800 (中国标准时间)
```
#### dateToString ( date, format ) 日期格式化为字符串(yyyy年份、MM月份、dd天、HH小时、mm分钟、ss秒、S毫秒、E星期几、q季度)
```shell
import { dateToString } from 'xe-utils'
import XEUtils from 'xe-utils'
dateToString(1513735830000) // '2017-12-20 10:10:30'
dateToString(new Date()) // '2017-12-20 10:10:30'
dateToString('2017-12-20 10:10:30', 'MM/dd/yyyy') // '12/20/2017'
dateToString(new Date(), 'yyyy-MM-dd') // '2017-12-20'
dateToString(new Date(), 'yyyy-MM-dd HH:mm:ss.S') // '2017-12-20 10:10:30.100'
dateToString(new Date(), 'yyyy年MM月dd日 HH时mm分ss秒S毫秒,星期E 第q季度') // '2017年12月20日 10时10分30秒100毫秒,星期三 第四季度'
XEUtils.dateToString(1513735830000) // '2017-12-20 10:10:30'
XEUtils.dateToString(new Date()) // '2017-12-20 10:10:30'
XEUtils.dateToString('2017-12-20 10:10:30', 'MM/dd/yyyy') // '12/20/2017'
XEUtils.dateToString(new Date(), 'yyyy-MM-dd') // '2017-12-20'
XEUtils.dateToString(new Date(), 'yyyy-MM-dd HH:mm:ss.S') // '2017-12-20 10:10:30.100'
XEUtils.dateToString(new Date(), 'yyyy年MM月dd日 HH时mm分ss秒S毫秒,星期E 第q季度') // '2017年12月20日 10时10分30秒100毫秒,星期三 第四季度'
```
#### getWhatMonth ( date, mode, month ) 返回前几个月或后几个月的日期,可以指定月初或月末,默认当前
```shell
import { getWhatMonth } from 'xe-utils'
import XEUtils from 'xe-utils'
getWhatMonth(new Date(), -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatMonth(1513735830000, -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatMonth('2017-12-20', -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatMonth('2017-12-20', 1) // Sat Jan 20 2018 00:00:00 GMT+0800 (中国标准时间)
getWhatMonth('2017-12-20', -1, 'first') // Wed Nov 01 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatMonth('2017-12-20', 1, 'last') // Wed Jan 31 2018 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatMonth(new Date(), -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatMonth(1513735830000, -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatMonth('2017-12-20', -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatMonth('2017-12-20', 1) // Sat Jan 20 2018 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatMonth('2017-12-20', -1, 'first') // Wed Nov 01 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatMonth('2017-12-20', 1, 'last') // Wed Jan 31 2018 00:00:00 GMT+0800 (中国标准时间)
```
#### getWhatWeek ( date, mode, week ) 返回前几周或后几周的日期,可以指定星期几,默认当前
```shell
import { getWhatWeek } from 'xe-utils'
import XEUtils from 'xe-utils'
getWhatWeek(new Date(), -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatWeek(1513735830000, -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatWeek('2017-12-20', -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatWeek('2017-12-20', 1) // Sun Dec 31 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatWeek('2017-12-20', -1, 5) // Fri Dec 15 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatWeek('2017-12-20', 1, 0) // Sun Dec 31 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatWeek(new Date(), -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatWeek(1513735830000, -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatWeek('2017-12-20', -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatWeek('2017-12-20', 1) // Sun Dec 31 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatWeek('2017-12-20', -1, 5) // Fri Dec 15 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatWeek('2017-12-20', 1, 0) // Sun Dec 31 2017 00:00:00 GMT+0800 (中国标准时间)
```
#### getWhatDay ( date, day ) 返回前几天或后几天的日期
```shell
import { getWhatDay } from 'xe-utils'
import XEUtils from 'xe-utils'
getWhatDay(new Date(), -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatDay(1513735830000, -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatDay('2017-12-20', -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
getWhatDay('2017-12-20', 1) // Tue Dec 21 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatDay(new Date(), -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatDay(1513735830000, -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatDay('2017-12-20', -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
XEUtils.getWhatDay('2017-12-20', 1) // Tue Dec 21 2017 00:00:00 GMT+0800 (中国标准时间)
```
#### getDaysOfMonth ( date, month ) 返回当前日期月份的天数,可以指定前几个月或后几个月,默认当前
```shell
import { getDaysOfMonth } from 'xe-utils'
import XEUtils from 'xe-utils'
getDaysOfMonth(new Date()) // 31
getDaysOfMonth(1513735830000) // 31
getDaysOfMonth('2017-12-20') // 31
getDaysOfMonth('2017-12-20', -1) // 30
getDaysOfMonth('2017-12-20', 1) // 31
XEUtils.getDaysOfMonth(new Date()) // 31
XEUtils.getDaysOfMonth(1513735830000) // 31
XEUtils.getDaysOfMonth('2017-12-20') // 31
XEUtils.getDaysOfMonth('2017-12-20', -1) // 30
XEUtils.getDaysOfMonth('2017-12-20', 1) // 31
```
#### getDateDiff ( startDate, endDate, rules ) 返回两个日期之间差距
```shell
import { getDateDiff } from 'xe-utils'
import XEUtils from 'xe-utils'
getDateDiff('2017-11-20', '2017-12-21') // {MM: 1, dd: 1}
getDateDiff('2017-12-20', '2017-12-21') // {dd: 1}
getDateDiff('2017-12-20', '2017-12-21') // {dd: 1, ss: 30}
const dateDiff = getDateDiff('2017-12-20 10:10:30', '2017-12-21 10:15:00')
XEUtils.getDateDiff('2017-11-20', '2017-12-21') // {MM: 1, dd: 1}
XEUtils.getDateDiff('2017-12-20', '2017-12-21') // {dd: 1}
XEUtils.getDateDiff('2017-12-20', '2017-12-21') // {dd: 1, ss: 30}
const dateDiff = XEUtils.getDateDiff('2017-12-20 10:10:30', '2017-12-21 10:15:00')
const content = `${dateDiff.mm}分${dateDiff.ss}秒` // '4分30秒'

@@ -575,15 +595,15 @@ ```

```shell
import { random } from 'xe-utils'
import XEUtils from 'xe-utils'
random() // 0 ~ 9
random(3, 6) // 3 ~ 6
random(10, 100) // 10 ~ 100
XEUtils.random() // 0 ~ 9
XEUtils.random(3, 6) // 3 ~ 6
XEUtils.random(10, 100) // 10 ~ 100
```
#### min ( arr, iteratee ) 获取最小值
```shell
import { min } from 'xe-utils'
import XEUtils from 'xe-utils'
min([22, 66, 77, 11]) // 11
min([{a: 11}, {a: 44}], 'a') // 11
min([{a: 11}, {a: 44}], (item) => {
XEUtils.min([22, 66, 77, 11]) // 11
XEUtils.min([{a: 11}, {a: 44}], 'a') // 11
XEUtils.min([{a: 11}, {a: 44}], (item) => {
return item.a

@@ -594,7 +614,7 @@ }) // {a: 11}

```shell
import { max } from 'xe-utils'
import XEUtils from 'xe-utils'
max([22, 66, 77, 11]) // 77
max([{a: 11}, {a: 44}], 'a') // 44
max([{a: 11}, {a: 44}], (item) => {
XEUtils.max([22, 66, 77, 11]) // 77
XEUtils.max([{a: 11}, {a: 44}], 'a') // 44
XEUtils.max([{a: 11}, {a: 44}], (item) => {
return item.a

@@ -606,11 +626,11 @@ }) // {a: 44}

```shell
import { escape } from 'xe-utils'
import XEUtils from 'xe-utils'
escape('<a>link</a>') // '&lt;a&gt;link&lt;/a&gt;'
XEUtils.escape('<a>link</a>') // '&lt;a&gt;link&lt;/a&gt;'
```
#### unescape ( str ) 反转escape
```shell
import { unescape } from 'xe-utils'
import XEUtils from 'xe-utils'
unescape('&lt;a&gt;link&lt;/a&gt;') // '<a>link</a>'
XEUtils.unescape('&lt;a&gt;link&lt;/a&gt;') // '<a>link</a>'
```

@@ -620,5 +640,5 @@

```shell
import { browse } from 'xe-utils'
import XEUtils from 'xe-utils'
browse() // {-khtml: false, -moz: false, -ms: fasle, -o: false, -webkit: true}
XEUtils.browse() // {-khtml: false, -moz: false, -ms: fasle, -o: false, -webkit: true}
```

@@ -628,5 +648,5 @@

```shell
import { locat } from 'xe-utils'
import XEUtils from 'xe-utils'
locat() // {hash: '', host: '', hostname: '', href: '', protocol: '', port: '', origin: '', query: {...}, params: {...}, ...}
XEUtils.locat() // {hash: '', host: '', hostname: '', href: '', protocol: '', port: '', origin: '', query: {...}, params: {...}, ...}
```

@@ -636,12 +656,12 @@

```shell
import { cookie } from 'xe-utils'
import XEUtils from 'xe-utils'
cookie() // 获取所有
cookie('name') // 根据name获取
cookie('name', null, {expires: -1}) // 删除
cookie([{name: 'name', expires: -1}]) // 批量删除
cookie('name', 'value') // 添加/修改
cookie([{name: 'name', value: 'value'}]) // 批量添加/修改
cookie('name', 'value', {domain: 'xxx.com', path: '/', expires: 7, secure: true}) // 添加并设置domain/path/secure/expires 7天后过期
cookie([{name: 'name', value: 'value', domain: 'xxx.com', path: '/', expires: 7, secure: true}]) // 批量添加并设置domain/path/secure/expires 7天后过期
XEUtils.cookie() // 获取所有
XEUtils.cookie('name') // 根据name获取
XEUtils.cookie('name', null, {expires: -1}) // 删除
XEUtils.cookie([{name: 'name', expires: -1}]) // 批量删除
XEUtils.cookie('name', 'value') // 添加/修改
XEUtils.cookie([{name: 'name', value: 'value'}]) // 批量添加/修改
XEUtils.cookie('name', 'value', {domain: 'xxx.com', path: '/', expires: 7, secure: true}) // 添加并设置domain/path/secure/expires 7天后过期
XEUtils.cookie([{name: 'name', value: 'value', domain: 'xxx.com', path: '/', expires: 7, secure: true}]) // 批量添加并设置domain/path/secure/expires 7天后过期
```

@@ -648,0 +668,0 @@

@@ -1,2 +0,2 @@

const $locat = location
var $locat = location

@@ -20,5 +20,5 @@ function hash () {

/**
* 获取地址栏信息
* 获取地址栏信息
* @return Object
*/
*/
export function locat () {

@@ -25,0 +25,0 @@ return {

@@ -5,3 +5,3 @@ /**

*/
const $body = document.body || document.documentElement
var $body = document.body || document.documentElement
export function browse () {

@@ -8,0 +8,0 @@ var result = {};

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc