![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
XEUtils 是一个不依赖于任何框架的函数库,支持常用基础函数、支持任意格式的日期处理函数,cookie操作函数等...,任何使用ES6模块编程的项目都能使用。
npm install xe-utils --save
import { dateToString, stringToDate } from 'xe-utils'
const dateStr = dateToString(new Date(), 'yyyy-MM-dd')
const date = stringToDate(dateStr, 'yyyy-MM-dd')
import XEUtils from 'xe-utils'
const dateStr = XEUtils.dateToString(new Date(), 'yyyy-MM-dd')
const date = XEUtils.stringToDate(dateStr, 'yyyy-MM-dd')
export function custom1 () {
console.log('自定义函数')
}
import Vue from 'vue'
import XEUtils from 'xe-utils'
import customs from './customs'
XEUtils.mixin(customs)
// 调用自定义扩展函数
XEUtils.custom1()
import { isNaN } from 'xe-utils'
isNaN(undefined) // true
isNaN({}) // true
isNaN('num') // true
isNaN(true) // false
isNaN(null) // false
isNaN('') // false
import { isFinite } from 'xe-utils'
isFinite(NaN) // false
isFinite(0) // true
isFinite(2e64) // true
import { isArray } from 'xe-utils'
isArray(null) // false
isArray({}) // false
isArray([1,2,3]) // true
import { isFloat } from 'xe-utils'
isFloat(null) // false
isFloat(0) // false
isFloat(3) // false
isFloat(3.3) // true
import { isInteger } from 'xe-utils'
isInteger(null) // false
isInteger(3.3) // false
isInteger(3) // true
isInteger(0) // true
import { isFunction } from 'xe-utils'
isFunction({}) // false
isFunction(function(){}) // true
import { isBoolean } from 'xe-utils'
isBoolean('false') // false
isBoolean(true) // true
import { isString } from 'xe-utils'
isString(1) // false
isString(true) // false
isString('') // true
isString('abc') // true
import { isNumber } from 'xe-utils'
isNumber(null) // false
isNumber('1') // false
isNumber(1) // true
import { isRegExp } from 'xe-utils'
isRegExp(null) // false
isRegExp('a') // false
isRegExp(new RegExp('a')) // true
isRegExp(/\a/) // true
import { isObject } from 'xe-utils'
isObject(null) // true
isObject([]) // true
isObject({}) // true
isObject(123) // false
import { isPlainObject } from 'xe-utils'
isPlainObject(null) // false
isPlainObject([]) // false
isPlainObject(123) // false
isPlainObject({}) // true
import { isDate } from 'xe-utils'
isDate('2017-12-20') // false
isDate({}) // false
isDate(1514096716800) // false
isDate(new Date()) // true
import { isError } from 'xe-utils'
isError(null) // false
isError({}) // false
isError(new Error('error')) // true
import { isTypeError } from 'xe-utils'
isTypeError(null) // false
isTypeError({}) // false
isTypeError(new TypeError('error')) // true
import { isEmpty } from 'xe-utils'
isEmpty(0) // true
isEmpty('') // true
isEmpty(null) // true
isEmpty({}) // true
isEmpty([]]) // true
import { isNull } from 'xe-utils'
isNull(0) // false
isNull('') // false
isNull(null) // true
import { isSymbol } from 'xe-utils'
isSymbol('a') // false
isSymbol(Symbol('a')) // true
import { isArguments } from 'xe-utils'
isArguments([]) // false
isArguments(arguments) // true
import { isElement } from 'xe-utils'
isElement({}) // false
isElement(document.createElement('div')) // true
import { isDocument } from 'xe-utils'
isDocument(document.createElement('div')) // false
isDocument(document) // true
import { isWindow } from 'xe-utils'
isWindow(document) // false
isWindow(window) // true
import { isFormData } from 'xe-utils'
isFormData({}) // false
isFormData(new FormData()) // true
import { isLeapYear } from 'xe-utils'
isLeapYear('2018-12-01') // false
isLeapYear('2020-12-01') // true
isLeapYear(new Date('2020/12/01')) // true
import { getType } from 'xe-utils'
getType() // 'undefined'
getType(null) // 'null'
getType('') // 'string'
getType(1) // 'number'
getType([]) // 'array'
getType({}) // 'object'
getType(function(){}) // 'function'
import { uniqueId } from 'xe-utils'
uniqueId() // 1
uniqueId() // 2
import { size } from 'xe-utils'
size('123') // 3
size([1, 3]) // 2
size({a: 2, b: 5}) // 2
import { indexOf } from 'xe-utils'
indexOf([11], 22) // -1
indexOf([11, 22], 22) // 1
import { lastIndexOf } from 'xe-utils'
lastIndexOf([11], 22) // -1
lastIndexOf([11, 22], 22) // 1
import { includes } from 'xe-utils'
includes([11], 22) // false
includes([11, 22], 22) // true
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}
import { stringToJson } from 'xe-utils'
stringToJson('{"a":1}') // {a: 1}
stringToJson('[11,22]') // [11, 22]
import { jsonToString } from 'xe-utils'
jsonToString({a: 1}) // '{"a":1}'
jsonToString([11, 22]) // '[11,22]'
import { keys } from 'xe-utils'
keys({a: 11}) // ['a']
keys([11, 22]) // [0, 1]
import { values } from 'xe-utils'
values({a: 11}) // [11]
values([11, 22]) // [11, 22]
import { entries } from 'xe-utils'
entries({a: 11}) // [['a', 11]]
entries([11, 22]) // [[0, 11], [1, 22]]
import { first } from 'xe-utils'
first({a: 11, b : 22}) // 11
first([11, 22]) // 11
import { last } from 'xe-utils'
last({a: 11, b: 22}) // 22
last([11, 22]) // 22
import { each } from 'xe-utils'
const result = []
each({a: 11, b: 22}, (item, key) => {
if (key === 'b') {
result.push(item)
}
}) // [22]
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'}]}
import { mapObject } from 'xe-utils'
const result = []
mapObject([{type: 'a'}, {type: 'b'}]], (item, key) => {
return item.type
}) // {a: {type: 'a', b: {type: 'b'}}}
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
}
const v3 = clone(v1, true)
if (v1.b === v3.b) {
// false
}
import { uniq } from 'xe-utils'
uniq([11, 22, 33, 33, 22, 55]) // [11, 22, 33, 55]
import { union } from 'xe-utils'
union([11, 22], [33, 22], [44, 11]) // [11, 22, 33, 44]
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}]
import { shuffle } from 'xe-utils'
shuffle([11, 22, 33, 44, 55]) // [22, 33, 55, 11, 44]
import { sample } from 'xe-utils'
sample([11, 22, 33, 44, 55], 3) // [22, 33, 55]
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
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
import { filter } from 'xe-utils'
filter([{a: 11}, {a: 22}]], (item, key) => {
return item.a > 11
}) // [{a: 22}]
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}
import { map } from 'xe-utils'
map([{a: 11}, {a: 22}]], (item, key) => {
return item.a
}) // [11, 22]
import { now } from 'xe-utils'
now() // 1514096716800
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 (中国标准时间)
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毫秒,星期三 第四季度'
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 (中国标准时间)
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 (中国标准时间)
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 (中国标准时间)
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
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秒'
import { random } from 'xe-utils'
random() // 0 ~ 9
random(3, 6) // 3 ~ 6
random(10, 100) // 10 ~ 100
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}
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}
import { escape } from 'xe-utils'
escape('<a>link</a>') // '<a>link</a>'
import { unescape } from 'xe-utils'
unescape('<a>link</a>') // '<a>link</a>'
import { browse } from 'xe-utils'
browse() // {-khtml: false, -moz: false, -ms: fasle, -o: false, -webkit: true}
import { locat } from 'xe-utils'
locat() // {hash: '', host: '', hostname: '', href: '', protocol: '', port: '', origin: '', query: {...}, params: {...}, ...}
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天后过期
Copyright (c) 2017-present, Xu Liangzhan
FAQs
JavaScript 函数库、工具类
The npm package xe-utils receives a total of 3,751 weekly downloads. As such, xe-utils popularity was classified as popular.
We found that xe-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.