Skip to content

Commit

Permalink
1.5.21
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Apr 28, 2018
1 parent 3c684d6 commit 766d095
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
16 changes: 11 additions & 5 deletions dist/xe-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* xe-utils.js v1.5.20
* xe-utils.js v1.5.21
* (c) 2017-2018 Xu Liangzhan
* ISC License.
* @preserve
Expand All @@ -13,7 +13,7 @@

function XEUtils () { }

XEUtils.version = '1.5.20'
XEUtils.version = '1.5.21'

/**
* 数组去重
Expand Down Expand Up @@ -928,6 +928,9 @@
browse: browse
}

var decode = decodeURIComponent
var encode = encodeURIComponent

/**
* cookie操作函数
* @param String/Array/Object name 键/数组/对象
Expand All @@ -942,6 +945,9 @@
function cookie (name, value, options) {
var inserts = []
var isDoc = typeof document !== 'undefined'
if (this && this.$context) {
this.$context = null
}
if (baseExports.isArray(name)) {
inserts = name
} else if (arguments.length > 1) {
Expand All @@ -955,7 +961,7 @@
var opts = baseExports.objectAssign({}, obj)
var values = []
if (opts.name) {
values.push(encodeURIComponent(opts.name) + '=' + encodeURIComponent(baseExports.isObject(opts.value) ? JSON.stringify(opts.value) : opts.value))
values.push(encode(opts.name) + '=' + encode(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()
}
Expand All @@ -973,7 +979,7 @@
if (isDoc && document.cookie) {
baseExports.arrayEach(document.cookie.split('; '), function (val) {
var keyIndex = val.indexOf('=')
result[decodeURIComponent(val.substring(0, keyIndex))] = decodeURIComponent(val.substring(keyIndex + 1) || '')
result[decode(val.substring(0, keyIndex))] = decode(val.substring(keyIndex + 1) || '')
})
}
return arguments.length === 1 ? result[name] : result
Expand Down Expand Up @@ -1424,7 +1430,7 @@
*/
XEUtils.mixin = function (methods) {
methodExports.objectEach(methods, function (fn, name) {
XEUtils[name] = methodExports.isFunction(fn) ? function () {
XEUtils[name] = 'cookie'.indexOf(name) === -1 && methodExports.isFunction(fn) ? function () {
var result = fn.apply(XEUtils.$context, arguments)
XEUtils.$context = null
return result
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.20",
"version": "1.5.21",
"description": "XEUtils 函数库",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var methodExports = require('../method')
*/
XEUtils.mixin = function (methods) {
methodExports.objectEach(methods, function (fn, name) {
XEUtils[name] = methodExports.isFunction(fn) ? function () {
XEUtils[name] = 'cookie'.indexOf(name) === -1 && methodExports.isFunction(fn) ? function () {
var result = fn.apply(XEUtils.$context, arguments)
XEUtils.$context = null
return result
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,6 +2,6 @@

function XEUtils () {}

XEUtils.version = '1.5.20'
XEUtils.version = '1.5.21'

module.exports = XEUtils
10 changes: 8 additions & 2 deletions src/method/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

var baseExports = require('./base')

var decode = decodeURIComponent
var encode = encodeURIComponent

/**
* cookie操作函数
* @param String/Array/Object name 键/数组/对象
Expand All @@ -16,6 +19,9 @@ var baseExports = require('./base')
function cookie (name, value, options) {
var inserts = []
var isDoc = typeof document !== 'undefined'
if (this && this.$context) {
this.$context = null
}
if (baseExports.isArray(name)) {
inserts = name
} else if (arguments.length > 1) {
Expand All @@ -29,7 +35,7 @@ function cookie (name, value, options) {
var opts = baseExports.objectAssign({}, obj)
var values = []
if (opts.name) {
values.push(encodeURIComponent(opts.name) + '=' + encodeURIComponent(baseExports.isObject(opts.value) ? JSON.stringify(opts.value) : opts.value))
values.push(encode(opts.name) + '=' + encode(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()
}
Expand All @@ -47,7 +53,7 @@ function cookie (name, value, options) {
if (isDoc && document.cookie) {
baseExports.arrayEach(document.cookie.split('; '), function (val) {
var keyIndex = val.indexOf('=')
result[decodeURIComponent(val.substring(0, keyIndex))] = decodeURIComponent(val.substring(keyIndex + 1) || '')
result[decode(val.substring(0, keyIndex))] = decode(val.substring(keyIndex + 1) || '')
})
}
return arguments.length === 1 ? result[name] : result
Expand Down

0 comments on commit 766d095

Please sign in to comment.