@alicloud/cookie
Advanced tools
Comparing version 1.4.0 to 1.4.2
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -32,9 +31,5 @@ value: true | ||
}); | ||
var _getAllCookies = _interopRequireDefault(require("./util/get-all-cookies")); | ||
var _getCookie = _interopRequireDefault(require("./util/get-cookie")); | ||
var _setCookie = _interopRequireDefault(require("./util/set-cookie")); | ||
var _deleteCookie = _interopRequireDefault(require("./util/delete-cookie")); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,5 +8,3 @@ value: true | ||
exports.default = deleteCookie; | ||
var _setCookie = _interopRequireDefault(require("./set-cookie")); | ||
/** | ||
@@ -18,5 +15,4 @@ * 删除 cookie,其实设置一个过期时间为此刻之前的时间,浏览器会自动清理过期的 cookie(其实这里设不设值都无所谓) | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
domain = _ref.domain, | ||
path = _ref.path; | ||
domain = _ref.domain, | ||
path = _ref.path; | ||
(0, _setCookie.default)(name, '', { | ||
@@ -23,0 +19,0 @@ domain: domain, |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,5 +8,3 @@ value: true | ||
exports.default = getAllCookies; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
/** | ||
@@ -21,12 +18,11 @@ * 获取当前页面可以访问到的全部 cookie | ||
} | ||
return document.cookie.split(/\s*;\s*/).reduce(function (result, v) { | ||
var _v$split = v.split('='), | ||
_v$split2 = (0, _slicedToArray2.default)(_v$split, 2), | ||
cookieName = _v$split2[0], | ||
cookieValue = _v$split2[1]; // 原来的实现有问题,set 的时候用的是 `escape`,get 的时候用的是 `decodeURIComponent`,这在大多数情况下 | ||
_v$split2 = (0, _slicedToArray2.default)(_v$split, 2), | ||
cookieName = _v$split2[0], | ||
cookieValue = _v$split2[1]; | ||
// 原来的实现有问题,set 的时候用的是 `escape`,get 的时候用的是 `decodeURIComponent`,这在大多数情况下 | ||
// 没有问题,但,当 set 了一个中文的,就会抛错「URIError: malformed URI sequence」 | ||
// 这里做一下兼容,因为大部分情况下 `decodeURIComponent(escape(value)) === value` | ||
try { | ||
@@ -37,5 +33,4 @@ result[cookieName] = decodeURIComponent(cookieValue); | ||
} | ||
return result; | ||
}, {}); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,5 +8,3 @@ value: true | ||
exports.default = getCookie; | ||
var _getAllCookies = _interopRequireDefault(require("./get-all-cookies")); | ||
/** | ||
@@ -14,0 +11,0 @@ * 获取单个 cookie |
@@ -7,7 +7,5 @@ "use strict"; | ||
exports.default = getDomain; | ||
function getDomain() { | ||
var _window = window, | ||
hostname = _window.location.hostname; | ||
hostname = _window.location.hostname; | ||
if (/^\d[\d.]*\d$/.test(hostname)) { | ||
@@ -17,5 +15,3 @@ // 纯 IP,直接返回 | ||
} | ||
var arr = hostname.split('.'); | ||
if (arr.length >= 3) { | ||
@@ -25,4 +21,3 @@ // 返回二级域名 | ||
} | ||
return hostname; | ||
} |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.default = getExpireDate; | ||
function getExpireDate(days) { | ||
@@ -10,0 +9,0 @@ if (!days) { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,7 +8,4 @@ value: true | ||
exports.default = setCookie; | ||
var _getExpireDate = _interopRequireDefault(require("./get-expire-date")); | ||
var _getDomain = _interopRequireDefault(require("./get-domain")); | ||
/** | ||
@@ -20,10 +16,9 @@ * 设置 cookie,默认为时间为 180 天,设置 extra.days 为 0 可以保存为 session cookie | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
_ref$domain = _ref.domain, | ||
domain = _ref$domain === void 0 ? (0, _getDomain.default)() : _ref$domain, | ||
_ref$path = _ref.path, | ||
path = _ref$path === void 0 ? '/' : _ref$path, | ||
_ref$days = _ref.days, | ||
days = _ref$days === void 0 ? 180 : _ref$days; | ||
_ref$domain = _ref.domain, | ||
domain = _ref$domain === void 0 ? (0, _getDomain.default)() : _ref$domain, | ||
_ref$path = _ref.path, | ||
path = _ref$path === void 0 ? '/' : _ref$path, | ||
_ref$days = _ref.days, | ||
days = _ref$days === void 0 ? 180 : _ref$days; | ||
document.cookie = ["".concat(name, "=").concat(encodeURIComponent(value)), "domain=".concat(domain), "path=".concat(path), "expires=".concat((0, _getExpireDate.default)(days))].join(';'); | ||
} |
import setCookie from './set-cookie'; | ||
/** | ||
* 删除 cookie,其实设置一个过期时间为此刻之前的时间,浏览器会自动清理过期的 cookie(其实这里设不设值都无所谓) | ||
*/ | ||
export default function deleteCookie(name) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
domain = _ref.domain, | ||
path = _ref.path; | ||
domain = _ref.domain, | ||
path = _ref.path; | ||
setCookie(name, '', { | ||
@@ -12,0 +11,0 @@ domain: domain, |
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
/** | ||
@@ -11,12 +10,11 @@ * 获取当前页面可以访问到的全部 cookie | ||
} | ||
return document.cookie.split(/\s*;\s*/).reduce(function (result, v) { | ||
var _v$split = v.split('='), | ||
_v$split2 = _slicedToArray(_v$split, 2), | ||
cookieName = _v$split2[0], | ||
cookieValue = _v$split2[1]; // 原来的实现有问题,set 的时候用的是 `escape`,get 的时候用的是 `decodeURIComponent`,这在大多数情况下 | ||
_v$split2 = _slicedToArray(_v$split, 2), | ||
cookieName = _v$split2[0], | ||
cookieValue = _v$split2[1]; | ||
// 原来的实现有问题,set 的时候用的是 `escape`,get 的时候用的是 `decodeURIComponent`,这在大多数情况下 | ||
// 没有问题,但,当 set 了一个中文的,就会抛错「URIError: malformed URI sequence」 | ||
// 这里做一下兼容,因为大部分情况下 `decodeURIComponent(escape(value)) === value` | ||
try { | ||
@@ -27,5 +25,4 @@ result[cookieName] = decodeURIComponent(cookieValue); | ||
} | ||
return result; | ||
}, {}); | ||
} |
import getAllCookies from './get-all-cookies'; | ||
/** | ||
* 获取单个 cookie | ||
*/ | ||
export default function getCookie(name) { | ||
return getAllCookies()[name]; | ||
} |
export default function getDomain() { | ||
var _window = window, | ||
hostname = _window.location.hostname; | ||
hostname = _window.location.hostname; | ||
if (/^\d[\d.]*\d$/.test(hostname)) { | ||
@@ -9,5 +8,3 @@ // 纯 IP,直接返回 | ||
} | ||
var arr = hostname.split('.'); | ||
if (arr.length >= 3) { | ||
@@ -17,4 +14,3 @@ // 返回二级域名 | ||
} | ||
return hostname; | ||
} |
import getExpireDate from './get-expire-date'; | ||
import getDomain from './get-domain'; | ||
/** | ||
* 设置 cookie,默认为时间为 180 天,设置 extra.days 为 0 可以保存为 session cookie | ||
*/ | ||
export default function setCookie(name, value) { | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
_ref$domain = _ref.domain, | ||
domain = _ref$domain === void 0 ? getDomain() : _ref$domain, | ||
_ref$path = _ref.path, | ||
path = _ref$path === void 0 ? '/' : _ref$path, | ||
_ref$days = _ref.days, | ||
days = _ref$days === void 0 ? 180 : _ref$days; | ||
_ref$domain = _ref.domain, | ||
domain = _ref$domain === void 0 ? getDomain() : _ref$domain, | ||
_ref$path = _ref.path, | ||
path = _ref$path === void 0 ? '/' : _ref$path, | ||
_ref$days = _ref.days, | ||
days = _ref$days === void 0 ? 180 : _ref$days; | ||
document.cookie = ["".concat(name, "=").concat(encodeURIComponent(value)), "domain=".concat(domain), "path=".concat(path), "expires=".concat(getExpireDate(days))].join(';'); | ||
} |
{ | ||
"name": "@alicloud/cookie", | ||
"version": "1.4.0", | ||
"version": "1.4.2", | ||
"description": "ConsoleBase Cookie", | ||
@@ -29,6 +29,6 @@ "license": "MIT", | ||
"@alicloud/console-toolkit-preset-component": "^1.2.61", | ||
"@alicloud/demo-rc-elements": "^1.10.0", | ||
"@alicloud/demo-rc-elements": "^1.10.8", | ||
"@types/react": "^17.0.48", | ||
"react": "^17.0.2", | ||
"typescript": "^4.7.4" | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -46,3 +46,3 @@ "scripts": { | ||
}, | ||
"gitHead": "3a50c1eaa823efebfa79bb16a5e042c6dfbb8bb5" | ||
"gitHead": "4b5eefd0215b1f8028fce664d64484ceeb703ef1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
259
13549