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.0.62 to 1.1.0

11

index.js

@@ -12,12 +12,3 @@ import * as core from './src/core'

function mixin (methods) {
if (methods) {
Object.keys(methods).forEach(function (name) {
var fn = methods[name]
XEUtils[name] = typeof fn === 'function' ? function () {
var rest = fn.apply(XEUtils.context || window, arguments)
XEUtils.context = window
return rest
} : fn
})
}
return Object.assign(XEUtils, methods)
}

@@ -24,0 +15,0 @@

4

package.json
{
"name": "xe-utils",
"version": "1.0.62",
"description": "xe-utils 提供一整套实用函数式编程功能",
"version": "1.1.0",
"description": "XExtends Utils 提供一套实用函数式编程功能",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

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

# xe-utils 提供一整套实用函数式编程功能
# XExtends Utils 提供一套实用函数式编程功能

@@ -9,8 +9,8 @@ ## 通过NPM安装最新版本

### 按需引入
### 部分引入
``` shell
import { dateToString, stringToDate } from 'xe-utils'
let dateStr = dateToString(new Date())
let date = stringToDate(dateStr)
const dateStr = dateToString(new Date())
const date = stringToDate(dateStr)
```

@@ -22,7 +22,7 @@

let dateStr = XEUtils.dateToString(new Date())
let date = XEUtils.stringToDate(dateStr)
const dateStr = XEUtils.dateToString(new Date())
const date = XEUtils.stringToDate(dateStr)
```
### Vue全局安装,通过实例调用this.$utils函数this默认指向当前vue实例
### Vue全局安装
``` shell

@@ -35,12 +35,19 @@ import Vue from 'vue'

// 在Vue实例中使用
let date = this.$utils.stringToDate('2017-12-20', 'yyyy-MM-dd')
// 通过vue实例的调用方式
var date = this.$utils.stringToDate('2017-12-20', 'yyyy-MM-dd')
```
### 自定义扩展
### 混合函数
#### 文件 ./customs.js
``` shell
export function custom1 () {
console.log('自定义函数')
}
```
#### 代码
``` shell
import Vue from 'vue'
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
import customs from './customs' // ./customs.js export function custom1 () {}
import customs from './customs'

@@ -54,237 +61,318 @@ XEUtils.mixin(customs)

## API :
### *./core/base*
## 'xe-utils' 函数库
#### isNaN (val) 判断是否非数值
```shell
this.$utils.isNaN(undefined) // true
this.$utils.isNaN({}) // true
this.$utils.isNaN('num') // true
this.$utils.isNaN(true) // false
this.$utils.isNaN(null) // false
this.$utils.isNaN('') // false
import { isNaN } from 'xe-utils'
isNaN(undefined) // true
isNaN({}) // true
isNaN('num') // true
isNaN(true) // false
isNaN(null) // false
isNaN('') // false
```
#### isFinite (val) 判断是否为有限数值
```shell
this.$utils.isFinite(NaN) // false
this.$utils.isFinite(0) // true
this.$utils.isFinite(2e64) // true
import { isFinite } from 'xe-utils'
isFinite(NaN) // false
isFinite(0) // true
isFinite(2e64) // true
```
#### isArray (val) 判断是否数组
```shell
this.$utils.isArray(null) // false
this.$utils.isArray({}) // false
this.$utils.isArray([1,2,3]) // true
import { isArray } from 'xe-utils'
isArray(null) // false
isArray({}) // false
isArray([1,2,3]) // true
```
#### isFloat (val) 判断是否小数
```shell
this.$utils.isFloat(null) // false
this.$utils.isFloat(0) // false
this.$utils.isFloat(3) // false
this.$utils.isFloat(3.3) // true
import { isFloat } from 'xe-utils'
isFloat(null) // false
isFloat(0) // false
isFloat(3) // false
isFloat(3.3) // true
```
#### isInteger (val) 判断是否整数
```shell
this.$utils.isInteger(null) // false
this.$utils.isInteger(3.3) // false
this.$utils.isInteger(3) // true
this.$utils.isInteger(0) // true
import { isInteger } from 'xe-utils'
isInteger(null) // false
isInteger(3.3) // false
isInteger(3) // true
isInteger(0) // true
```
#### isFunction (val) 判断是否方法
```shell
this.$utils.isFunction({}) // false
this.$utils.isFunction(function(){}) // true
import { isFunction } from 'xe-utils'
isFunction({}) // false
isFunction(function(){}) // true
```
#### isBoolean (val) 判断是否Boolean对象
```shell
this.$utils.isBoolean('false') // false
this.$utils.isBoolean(true) // true
import { isBoolean } from 'xe-utils'
isBoolean('false') // false
isBoolean(true) // true
```
#### isString (val) 判断是否String对象
```shell
this.$utils.isString(1) // false
this.$utils.isString(true) // false
this.$utils.isString('') // true
this.$utils.isString('abc') // true
import { isString } from 'xe-utils'
isString(1) // false
isString(true) // false
isString('') // true
isString('abc') // true
```
#### isNumber (val) 判断是否Number对象
```shell
this.$utils.isNumber(null) // false
this.$utils.isNumber('1') // false
this.$utils.isNumber(1) // true
import { isNumber } from 'xe-utils'
isNumber(null) // false
isNumber('1') // false
isNumber(1) // true
```
#### isRegExp (val) 判断是否RegExp对象
```shell
this.$utils.isRegExp(null) // false
this.$utils.isRegExp('a') // false
this.$utils.isRegExp(new RegExp('a')) // true
this.$utils.isRegExp(/\a/) // true
import { isRegExp } from 'xe-utils'
isRegExp(null) // false
isRegExp('a') // false
isRegExp(new RegExp('a')) // true
isRegExp(/\a/) // true
```
#### isObject (val) 判断是否Object对象
```shell
this.$utils.isObject(null) // true
this.$utils.isObject([]) // true
this.$utils.isObject({}) // true
this.$utils.isObject(123) // false
import { isObject } from 'xe-utils'
isObject(null) // true
isObject([]) // true
isObject({}) // true
isObject(123) // false
```
#### isPlainObject (val) 判断是否是一个对象
```shell
this.$utils.isPlainObject(null) // false
this.$utils.isPlainObject([]) // false
this.$utils.isPlainObject(123) // false
this.$utils.isPlainObject({}) // true
import { isPlainObject } from 'xe-utils'
isPlainObject(null) // false
isPlainObject([]) // false
isPlainObject(123) // false
isPlainObject({}) // true
```
#### isDate (val) 判断是否Date对象
```shell
this.$utils.isDate('2017-12-20') // false
this.$utils.isDate({}) // false
this.$utils.isDate(1514096716800) // false
this.$utils.isDate(new Date()) // true
import { isDate } from 'xe-utils'
isDate('2017-12-20') // false
isDate({}) // false
isDate(1514096716800) // false
isDate(new Date()) // true
```
#### isError (val) 判断是否Error对象
```shell
this.$utils.isError(null) // false
this.$utils.isError({}) // false
this.$utils.isError(new Error('error')) // true
import { isError } from 'xe-utils'
isError(null) // false
isError({}) // false
isError(new Error('error')) // true
```
#### isTypeError (val) 判断是否TypeError对象
```shell
this.$utils.isTypeError(null) // false
this.$utils.isTypeError({}) // false
this.$utils.isTypeError(new TypeError('error')) // true
import { isTypeError } from 'xe-utils'
isTypeError(null) // false
isTypeError({}) // false
isTypeError(new TypeError('error')) // true
```
#### isEmpty (val) 判断是否为空,包括空对象、空数值、空字符串
```shell
this.$utils.isEmpty(0) // true
this.$utils.isEmpty('') // true
this.$utils.isEmpty(null) // true
this.$utils.isEmpty({}) // true
this.$utils.isEmpty([]]) // true
import { isEmpty } from 'xe-utils'
isEmpty(0) // true
isEmpty('') // true
isEmpty(null) // true
isEmpty({}) // true
isEmpty([]]) // true
```
#### isNull (val) 判断是否为Null
```shell
this.$utils.isNull(0) // false
this.$utils.isNull('') // false
this.$utils.isNull(null) // true
import { isNull } from 'xe-utils'
isNull(0) // false
isNull('') // false
isNull(null) // true
```
#### isSymbol (val) 判断是否Symbol对象
```shell
this.$utils.isSymbol('a') // false
this.$utils.isSymbol(Symbol('a')) // true
import { isSymbol } from 'xe-utils'
isSymbol('a') // false
isSymbol(Symbol('a')) // true
```
#### isArguments (val) 判断是否Arguments对象
```shell
this.$utils.isArguments([]) // false
this.$utils.isArguments(arguments) // true
import { isArguments } from 'xe-utils'
isArguments([]) // false
isArguments(arguments) // true
```
#### isElement (val) 判断是否Element对象
```shell
this.$utils.isElement({}) // false
this.$utils.isElement(document.createElement('div')) // true
import { isElement } from 'xe-utils'
isElement({}) // false
isElement(document.createElement('div')) // true
```
#### isDocument (val) 判断是否Document对象
```shell
this.$utils.isDocument(document.createElement('div')) // false
this.$utils.isDocument(document) // true
import { isDocument } from 'xe-utils'
isDocument(document.createElement('div')) // false
isDocument(document) // true
```
#### isWindow (val) 判断是否Window对象
```shell
this.$utils.isWindow(document) // false
this.$utils.isWindow(window) // true
import { isWindow } from 'xe-utils'
isWindow(document) // false
isWindow(window) // true
```
#### isFormData (val) 判断是否FormData对象
```shell
this.$utils.isFormData({}) // false
this.$utils.isFormData(new FormData()) // true
import { isFormData } from 'xe-utils'
isFormData({}) // false
isFormData(new FormData()) // true
```
#### isLeapYear (date) 判断是否闰年
```shell
this.$utils.isLeapYear('2018-12-01') // false
this.$utils.isLeapYear('2020-12-01') // true
this.$utils.isLeapYear(new Date('2020/12/01')) // true
import { isLeapYear } from 'xe-utils'
isLeapYear('2018-12-01') // false
isLeapYear('2020-12-01') // true
isLeapYear(new Date('2020/12/01')) // true
```
#### getType (obj) 获取对象类型
```shell
this.$utils.getType() // 'undefined'
this.$utils.getType(null) // 'null'
this.$utils.getType('') // 'string'
this.$utils.getType(1) // 'number'
this.$utils.getType([]) // 'array'
this.$utils.getType({}) // 'object'
this.$utils.getType(function(){}) // 'function'
import { getType } from 'xe-utils'
getType() // 'undefined'
getType(null) // 'null'
getType('') // 'string'
getType(1) // 'number'
getType([]) // 'array'
getType({}) // 'object'
getType(function(){}) // 'function'
```
#### uniqueId ( ) 获取一个全局唯一标识
```shell
this.$utils.uniqueId() // 1
this.$utils.uniqueId() // 2
import { uniqueId } from 'xe-utils'
uniqueId() // 1
uniqueId() // 2
```
#### size ( obj ) 返回对象的长度
```shell
this.$utils.size('123') // 3
this.$utils.size([1, 3]) // 2
this.$utils.size({a: 2, b: 5}) // 2
import { size } from 'xe-utils'
size('123') // 3
size([1, 3]) // 2
size({a: 2, b: 5}) // 2
```
#### indexOf (obj, val) 返回对象第一个索引值
```shell
this.$utils.indexOf([11], 22) // -1
this.$utils.indexOf([11, 22], 22) // 1
import { indexOf } from 'xe-utils'
indexOf([11], 22) // -1
indexOf([11, 22], 22) // 1
```
#### lastIndexOf (obj, val) 从最后开始的索引值,返回对象第一个索引值
```shell
this.$utils.lastIndexOf([11], 22) // -1
this.$utils.lastIndexOf([11, 22], 22) // 1
import { lastIndexOf } from 'xe-utils'
lastIndexOf([11], 22) // -1
lastIndexOf([11, 22], 22) // 1
```
#### includes (obj, val) 判断对象是否包含该值,成功返回true否则false
```shell
this.$utils.includes([11], 22) // false
this.$utils.includes([11, 22], 22) // true
import { includes } from 'xe-utils'
includes([11], 22) // false
includes([11, 22], 22) // true
```
#### assign (target, ...) 浅拷贝一个或者多个对象到目标对象中
```shell
let obj1 = {a: null}
this.$utils.assign(obj1, {a: 11}) // {a: 11}
this.$utils.extend(obj1, {a: 11}) // {a: 11}
let obj2 = {c: null}
this.$utils.assign(obj2, {a: 11}, {b: 22}) // {a: 11, b: 22, c: null}
this.$utils.extend(obj2, {a: 11}, {b: 22}) // {a: 11, b: 22, c: null}
import { assign, extend } from 'xe-utils'
const obj1 = {a: null}
assign(obj1, {a: 11}) // {a: 11}
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}
```
#### stringToJson (str) 字符串转JSON
```shell
this.$utils.stringToJson('{"a":1}') // {a: 1}
this.$utils.stringToJson('[11,22]') // [11, 22]
import { stringToJson } from 'xe-utils'
stringToJson('{"a":1}') // {a: 1}
stringToJson('[11,22]') // [11, 22]
```
#### jsonToString (obj) JSON转字符串
```shell
this.$utils.jsonToString({a: 1}) // '{"a":1}'
this.$utils.jsonToString([11, 22]) // '[11,22]'
import { jsonToString } from 'xe-utils'
jsonToString({a: 1}) // '{"a":1}'
jsonToString([11, 22]) // '[11,22]'
```
#### keys (obj) 获取对象所有属性
```shell
this.$utils.keys({a: 11}) // ['a']
this.$utils.keys([11, 22]) // [0, 1]
import { keys } from 'xe-utils'
keys({a: 11}) // ['a']
keys([11, 22]) // [0, 1]
```
#### values (obj) 获取对象所有值
```shell
this.$utils.values({a: 11}) // [11]
this.$utils.values([11, 22]) // [11, 22]
import { values } from 'xe-utils'
values({a: 11}) // [11]
values([11, 22]) // [11, 22]
```
#### entries (obj) 获取对象所有属性、值
```shell
this.$utils.entries({a: 11}) // [['a', 11]]
this.$utils.entries([11, 22]) // [[0, 11], [1, 22]]
import { entries } from 'xe-utils'
entries({a: 11}) // [['a', 11]]
entries([11, 22]) // [[0, 11], [1, 22]]
```
#### first (obj) 获取对象第一个值
```shell
this.$utils.first({a: 11, b : 22}) // 11
this.$utils.first([11, 22]) // 11
import { first } from 'xe-utils'
first({a: 11, b : 22}) // 11
first([11, 22]) // 11
```
#### last (obj) 获取对象最后一个值
```shell
this.$utils.last({a: 11, b: 22}) // 22
this.$utils.last([11, 22]) // 22
import { last } from 'xe-utils'
last({a: 11, b: 22}) // 22
last([11, 22]) // 22
```
#### each ( obj, iteratee, context ) 迭代器
```shell
let result = []
import { each } from 'xe-utils'
const result = []
each({a: 11, b: 22}, (item, key) => {
if (key === 'b') {
result.push(item)
}
}) // [22]
this.$utils.each({a: 11, b: 22}, (item, key) => {
// // this 指向当前vue实例
if (key === 'b') {

@@ -297,13 +385,23 @@ result.push(item)

```shell
let result1 = this.$utils.groupBy([{type: 'a'}, {type: 'b'}]], 'type') // {a: [{a: 'a'}], b: [{b: 'b'}]}
let result2 = this.$utils.groupBy([{type: 'a'}, {type: 'b'}]], (item, key) => {
// // this 指向当前vue实例
import { groupBy } 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) => {
return item.type
}) // {a: [{a: 'a'}], b: [{b: 'b'}]}
var result3 = this.$utils.groupBy([{type: 'a'}, {type: 'b'}]], (item, key) => {
return item.type
}) // {a: [{a: 'a'}], b: [{b: 'b'}]}
```
#### mapObject ( obj, iteratee, context ) 指定方法后的返回值组成的新对象
```shell
let result = []
import { mapObject } from 'xe-utils'
const result = []
mapObject([{type: 'a'}, {type: 'b'}]], (item, key) => {
return item.type
}) // {a: {type: 'a', b: {type: 'b'}}}
this.$utils.mapObject([{type: 'a'}, {type: 'b'}]], (item, key) => {
// // this 指向当前vue实例
return item.type

@@ -314,8 +412,10 @@ }) // {a: {type: 'a', b: {type: 'b'}}}

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

@@ -326,16 +426,24 @@ // false

### *./core/array*
#### uniq ( array ) 数组去重
```shell
this.$utils.uniq([11, 22, 33, 33, 22, 55]) // [11, 22, 33, 55]
import { uniq } from 'xe-utils'
uniq([11, 22, 33, 33, 22, 55]) // [11, 22, 33, 55]
```
#### union ( ...array ) 将多个数的值返回唯一的并集数组
```shell
this.$utils.union([11, 22], [33, 22], [44, 11]) // [11, 22, 33, 44]
import { union } from 'xe-utils'
union([11, 22], [33, 22], [44, 11]) // [11, 22, 33, 44]
```
#### sort ( arr, iteratee, context ) 数组按属性值升序
```shell
this.$utils.sort([{a: 9}, {a: 4}, {a: 5}], 'a') // [{a: 4}, {a: 5}, {a: 9}]
import { sort } 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) => {
return v1.a > v2.a ? 1 : -1
}) // [{a: 4}, {a: 5}, {a: 9}]
this.$utils.sort([{a: 9}, {a: 4}, {a: 5}], (v1, v2) => {
// // this 指向当前vue实例
return v1.a > v2.a ? 1 : -1

@@ -346,16 +454,24 @@ }) // [{a: 4}, {a: 5}, {a: 9}]

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

@@ -366,8 +482,12 @@ }) // true

```shell
this.$utils.every([{a: 11}, {a: 22}]], (item, key) => {
// // this 指向当前vue实例
import { every } from 'xe-utils'
every([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 11
}) // false
every([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 11 || item.a === 22
}) // true
this.$utils.every([{a: 11}, {a: 22}]], (item, key) => {
// // this 指向当前vue实例
return item.a === 11 || item.a === 22

@@ -378,4 +498,9 @@ }) // true

```shell
import { filter } from 'xe-utils'
filter([{a: 11}, {a: 22}]], (item, key) => {
return item.a > 11
}) // [{a: 22}]
this.$utils.filter([{a: 11}, {a: 22}]], (item, key) => {
// // this 指向当前vue实例
return item.a > 11

@@ -386,8 +511,12 @@ }) // [{a: 22}]

```shell
this.$utils.find([{a: 11}, {a: 22}]], (item, key) => {
// // this 指向当前vue实例
import { find } from 'xe-utils'
find([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 55
}) // null
find([{a: 11}, {a: 22}]], (item, key) => {
return item.a === 22
}) // {a: 22}
this.$utils.find([{a: 11}, {a: 22}]], (item, key) => {
// // this 指向当前vue实例
return item.a === 22

@@ -398,4 +527,9 @@ }) // {a: 22}

```shell
import { map } from 'xe-utils'
map([{a: 11}, {a: 22}]], (item, key) => {
return item.a
}) // [11, 22]
this.$utils.map([{a: 11}, {a: 22}]], (item, key) => {
// // this 指向当前vue实例
return item.a

@@ -405,79 +539,100 @@ }) // [11, 22]

### *./core/date*
#### now ( ) 返回时间戳
```shell
this.$utils.now() // 1514096716800
import { now } from 'xe-utils'
now() // 1514096716800
```
#### stringToDate ( str, format ) 字符串转为日期(yyyy年份、MM月份、dd天、HH小时、mm分钟、ss秒、SSS毫秒)
```shell
this.$utils.stringToDate('2017-12-20') // Wed Dec 20 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.stringToDate('2017-12-20 10:10:30') // Wed Dec 20 2017 10:10:30 GMT+0800 (中国标准时间)
this.$utils.stringToDate('12/20/2017', 'MM/dd/yyyy') // Wed Dec 20 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.stringToDate('12/20/2017 10:10:30.100', 'MM/dd/yyyy HH:mm') // Wed Dec 20 2017 10:10:00 GMT+0800 (中国标准时间)
this.$utils.stringToDate('12/20/2017 10:10:30.100', 'MM/dd/yyyy HH:mm:ss.SSS') // Wed Dec 20 2017 10:10:30 GMT+0800 (中国标准时间)
import { stringToDate } 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 (中国标准时间)
```
#### dateToString ( date, format ) 日期格式化为字符串(yyyy年份、MM月份、dd天、HH小时、mm分钟、ss秒、S毫秒、E星期几、q季度)
```shell
this.$utils.dateToString(1513735830000) // '2017-12-20 10:10:30'
this.$utils.dateToString(new Date()) // '2017-12-20 10:10:30'
this.$utils.dateToString('2017-12-20 10:10:30', 'MM/dd/yyyy') // '12/20/2017'
this.$utils.dateToString(new Date(), 'yyyy-MM-dd') // '2017-12-20'
this.$utils.dateToString(new Date(), 'yyyy-MM-dd HH:mm:ss.S') // '2017-12-20 10:10:30.100'
this.$utils.dateToString(new Date(), 'yyyy年MM月dd日 HH时mm分ss秒S毫秒,星期E 第q季度') // '2017年12月20日 10时10分30秒100毫秒,星期三 第四季度'
import { dateToString } 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毫秒,星期三 第四季度'
```
#### getWhatMonth ( date, mode, month ) 返回前几个月或后几个月的日期,可以指定月初或月末,默认当前
```shell
this.$utils.getWhatMonth(new Date(), -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatMonth(1513735830000, -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatMonth('2017-12-20', -1) // Mon Nov 20 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatMonth('2017-12-20', 1) // Sat Jan 20 2018 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatMonth('2017-12-20', -1, 'first') // Wed Nov 01 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatMonth('2017-12-20', 1, 'last') // Wed Jan 31 2018 00:00:00 GMT+0800 (中国标准时间)
import { getWhatMonth } 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 (中国标准时间)
```
#### getWhatWeek ( date, mode, week ) 返回前几周或后几周的日期,可以指定星期几,默认当前
```shell
this.$utils.getWhatWeek(new Date(), -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatWeek(1513735830000, -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatWeek('2017-12-20', -1) // Sun Dec 17 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatWeek('2017-12-20', 1) // Sun Dec 31 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatWeek('2017-12-20', -1, 5) // Fri Dec 15 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatWeek('2017-12-20', 1, 0) // Sun Dec 31 2017 00:00:00 GMT+0800 (中国标准时间)
import { getWhatWeek } 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 (中国标准时间)
```
#### getWhatDay ( date, day ) 返回前几天或后几天的日期
```shell
this.$utils.getWhatDay(new Date(), -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatDay(1513735830000, -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatDay('2017-12-20', -1) // Tue Dec 19 2017 00:00:00 GMT+0800 (中国标准时间)
this.$utils.getWhatDay('2017-12-20', 1) // Tue Dec 21 2017 00:00:00 GMT+0800 (中国标准时间)
import { getWhatDay } 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 (中国标准时间)
```
#### getDaysOfMonth ( date, month ) 返回当前日期月份的天数,可以指定前几个月或后几个月,默认当前
```shell
this.$utils.getDaysOfMonth(new Date()) // 31
this.$utils.getDaysOfMonth(1513735830000) // 31
this.$utils.getDaysOfMonth('2017-12-20') // 31
this.$utils.getDaysOfMonth('2017-12-20', -1) // 30
this.$utils.getDaysOfMonth('2017-12-20', 1) // 31
import { getDaysOfMonth } 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
```
#### getDateDiff ( startDate, endDate, rules ) 返回两个日期之间差距
```shell
this.$utils.getDateDiff('2017-11-20', '2017-12-21') // {MM: 1, dd: 1}
this.$utils.getDateDiff('2017-12-20', '2017-12-21') // {dd: 1}
this.$utils.getDateDiff('2017-12-20', '2017-12-21') // {dd: 1, ss: 30}
let dateDiff = this.$utils.getDateDiff('2017-12-20 10:10:30', '2017-12-21 10:15:00')
let content = `${dateDiff.mm}分${dateDiff.ss}秒` // '4分30秒'
import { getDateDiff } 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')
const content = `${dateDiff.mm}分${dateDiff.ss}秒` // '4分30秒'
```
### *./core/number*
#### random ( min, max ) 获取一个指定范围内随机数
```shell
this.$utils.random() // 0 ~ 9
this.$utils.random(3, 6) // 3 ~ 6
this.$utils.random(10, 100) // 10 ~ 100
import { random } from 'xe-utils'
random() // 0 ~ 9
random(3, 6) // 3 ~ 6
random(10, 100) // 10 ~ 100
```
#### min ( arr, iteratee ) 获取最小值
```shell
this.$utils.min([22, 66, 77, 11]) // 11
this.$utils.min([{a: 11}, {a: 44}], 'a') // 11
import { min } from 'xe-utils'
min([22, 66, 77, 11]) // 11
min([{a: 11}, {a: 44}], 'a') // 11
min([{a: 11}, {a: 44}], (item) => {
return item.a
}) // {a: 11}
this.$utils.min([{a: 11}, {a: 44}], (item) => {
// // this 指向当前vue实例
return item.a

@@ -488,6 +643,11 @@ }) // {a: 11}

```shell
this.$utils.max([22, 66, 77, 11]) // 77
this.$utils.max([{a: 11}, {a: 44}], 'a') // 44
import { max } from 'xe-utils'
max([22, 66, 77, 11]) // 77
max([{a: 11}, {a: 44}], 'a') // 44
max([{a: 11}, {a: 44}], (item) => {
return item.a
}) // {a: 44}
this.$utils.max([{a: 11}, {a: 44}], (item) => {
// // this 指向当前vue实例
return item.a

@@ -497,35 +657,43 @@ }) // {a: 44}

### *./core/string*
#### escape ( str ) 转义HTML字符串,替换&, <, >, ", ', `字符
```shell
this.$utils.escape('<a>link</a>') // '&lt;a&gt;link&lt;/a&gt;'
import { escape } from 'xe-utils'
escape('<a>link</a>') // '&lt;a&gt;link&lt;/a&gt;'
```
#### unescape ( str ) 反转escape
```shell
this.$utils.escape('&lt;a&gt;link&lt;/a&gt;') // '<a>link</a>'
import { unescape } from 'xe-utils'
unescape('&lt;a&gt;link&lt;/a&gt;') // '<a>link</a>'
```
### *./browse/type*
#### browse ( ) 获取浏览器内核
```shell
this.$utils.browse() // {-khtml: false, -moz: false, -ms: fasle, -o: false, -webkit: true}
import { browse } from 'xe-utils'
browse() // {-khtml: false, -moz: false, -ms: fasle, -o: false, -webkit: true}
this.$browse // {-khtml: false, -moz: false, -ms: fasle, -o: false, -webkit: true}
```
### *./browse/locat*
#### locat ( ) 获取地址栏信息
```shell
this.$utils.locat() // {hash: '', host: '', hostname: '', href: '', protocol: '', port: '', origin: '', query: {...}, params: {...}, ...}
import { locat } from 'xe-utils'
locat() // {hash: '', host: '', hostname: '', href: '', protocol: '', port: '', origin: '', query: {...}, params: {...}, ...}
this.$locat() // {hash: '', host: '', hostname: '', href: '', protocol: '', port: '', origin: '', query: {...}, params: {...}, ...}
```
### *./browse/cookie*
#### cookie ( ) Cookie操作函数
```shell
this.$utils.cookie() // 获取所有
this.$utils.cookie('name') // 根据name获取
this.$utils.cookie('name', null, {expires: -1}) // 删除
this.$utils.cookie([{name: 'name', expires: -1}]) // 批量删除
this.$utils.cookie('name', 'value') // 添加/修改
this.$utils.cookie([{name: 'name', value: 'value'}]) // 批量添加/修改
this.$utils.cookie('name', 'value', {domain: 'xxx.com', path: '/', expires: 7, secure: true}) // 添加并设置domain/path/secure/expires 7天后过期
this.$utils.cookie([{name: 'name', value: 'value', domain: 'xxx.com', path: '/', expires: 7, secure: true}]) // 批量添加并设置domain/path/secure/expires 7天后过期
import { cookie } 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天后过期
```

@@ -532,0 +700,0 @@

@@ -93,3 +93,3 @@ import { random } from './number'

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Boolean}

@@ -99,3 +99,2 @@ */

if (obj) {
context = context || this
if (isArray(obj)) {

@@ -121,3 +120,3 @@ return obj.some(iteratee, context)

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Boolean}

@@ -127,3 +126,2 @@ */

if (obj) {
context = context || this
if (isArray(obj)) {

@@ -149,3 +147,3 @@ return obj.every(iteratee, context)

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Object}

@@ -155,3 +153,2 @@ */

if (obj) {
context = context || this
if (isArray(obj)) {

@@ -177,3 +174,3 @@ return obj.filter(iteratee, context)

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Object}

@@ -183,3 +180,2 @@ */

if (obj) {
context = context || this
if (isArray(obj)) {

@@ -204,3 +200,3 @@ return obj.find(iteratee, context)

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Array}

@@ -211,3 +207,2 @@ */

if (obj) {
context = context || this
if (isArray(obj)) {

@@ -214,0 +209,0 @@ return obj.map(iteratee, context)

@@ -502,3 +502,3 @@ import { stringToDate } from './date'

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Object}

@@ -508,3 +508,2 @@ */

if (obj) {
context = context || this
if (isArray(obj)) {

@@ -523,3 +522,3 @@ return obj.forEach(iteratee, context)

* @param {Function} iteratee 回调/对象属性
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Object}

@@ -531,3 +530,2 @@ */

if (obj) {
context = context || this
if (isString(iteratee)) {

@@ -558,3 +556,3 @@ attr = iteratee

* @param {Function} iteratee(item, index, obj) 回调
* @param {Object} context 上下文(this默认指向当前vue组件)
* @param {Object} context 上下文
* @return {Object}

@@ -564,3 +562,2 @@ */

var result = {}
context = context || this
each(obj, function (val, index) {

@@ -567,0 +564,0 @@ result[index] = iteratee.call(context, val, index, obj)

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