Skip to content

Commit

Permalink
Version_0.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed Nov 1, 2023
1 parent a1f137d commit 5521fc3
Show file tree
Hide file tree
Showing 60 changed files with 738 additions and 711 deletions.
1 change: 1 addition & 0 deletions config/rollup.config.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
// legacy: true,
banner: prod ? '' : common.banner,
},
external: ['moment'],
plugins: [
common.getCompiler(),
(prod && terser())
Expand Down
1 change: 1 addition & 0 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
// legacy: true,
banner: common.banner,
},
external: ['moment'],
plugins: [
common.getCompiler({
tsconfigOverride: { compilerOptions: { declaration: true, module: 'ES2015' } },
Expand Down
183 changes: 138 additions & 45 deletions dist/index.aio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* galanga 0.2.4 (https://github.com/censujiang/galanga)
* galanga 0.2.5 (https://github.com/censujiang/galanga)
* API https://galanga.censujiang.com/api/
* Copyright 2014-2023 censujiang. All Rights Reserved
* Licensed under Apache License 2.0 (https://github.com/censujiang/galanga/blob/master/LICENSE)
Expand All @@ -11,58 +11,151 @@
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.galanga = {}));
})(this, (function (exports) { 'use strict';

//操作cookie的方法
const localCookie = {
getItem: (sKey) => {
return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
},
setItem: (sKey, sValue, sPath = '/', sDomain = window.location.hostname, vEnd, bSecure) => {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
return false;
}
let sExpires = '';
if (vEnd) {
if (typeof vEnd === 'number') {
const dExpires = new Date();
dExpires.setTime(dExpires.getTime() + (vEnd * 24 * 60 * 60 * 1000));
sExpires = '; expires=' + dExpires.toUTCString();
}
else if (typeof vEnd === 'string') {
sExpires = '; expires=' + vEnd;
}
else if (vEnd instanceof Date) {
sExpires = '; expires=' + vEnd.toUTCString();
}
}
document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) +
sExpires +
(sDomain ? '; domain=' + sDomain : '') +
(sPath ? '; path=' + sPath : '') +
(bSecure ? '; secure' : '');
return true;
},
removeItem: (sKey, sPath = '/', sDomain = window.location.hostname) => {
if (!sKey || !localCookie.hasItem(sKey)) {
return false;
/*! js-cookie v3.0.5 | MIT */
/* eslint-disable no-var */
function assign (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
target[key] = source[key];
}
}
return target
}
/* eslint-enable no-var */

/* eslint-disable no-var */
var defaultConverter = {
read: function (value) {
if (value[0] === '"') {
value = value.slice(1, -1);
}
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
},
write: function (value) {
return encodeURIComponent(value).replace(
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
decodeURIComponent
)
}
};
/* eslint-enable no-var */

/* eslint-disable no-var */

function init (converter, defaultAttributes) {
function set (name, value, attributes) {
if (typeof document === 'undefined') {
return
}

attributes = assign({}, defaultAttributes, attributes);

if (typeof attributes.expires === 'number') {
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
}
if (attributes.expires) {
attributes.expires = attributes.expires.toUTCString();
}

name = encodeURIComponent(name)
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
.replace(/[()]/g, escape);

var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue
}

stringifiedAttributes += '; ' + attributeName;

if (attributes[attributeName] === true) {
continue
}

// Considers RFC 6265 section 5.2:
// ...
// 3. If the remaining unparsed-attributes contains a %x3B (";")
// character:
// Consume the characters of the unparsed-attributes up to,
// not including, the first %x3B (";") character.
// ...
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}

return (document.cookie =
name + '=' + converter.write(value, name) + stringifiedAttributes)
}

function get (name) {
if (typeof document === 'undefined' || (arguments.length && !name)) {
return
}

// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var jar = {};
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var value = parts.slice(1).join('=');

try {
var found = decodeURIComponent(parts[0]);
jar[found] = converter.read(value, found);

if (name === found) {
break
}
document.cookie = encodeURIComponent(sKey) +
'=; expires=Thu, 01 Jan 1970 00:00:00 UTC' +
(sDomain ? '; domain=' + sDomain : '') +
(sPath ? '; path=' + sPath : '') +
'; secure';
return true;
},
hasItem: function (sKey) {
return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
} catch (e) {}
}

return name ? jar[name] : jar
}

return Object.create(
{
set,
get,
remove: function (name, attributes) {
set(
name,
'',
assign({}, attributes, {
expires: -1
})
);
},
withAttributes: function (attributes) {
return init(this.converter, assign({}, this.attributes, attributes))
},
withConverter: function (converter) {
return init(assign({}, this.converter, converter), this.attributes)
}
},
keys: /* optional method: you can safely remove it! */ function () {
{
attributes: { value: Object.freeze(defaultAttributes) },
converter: { value: Object.freeze(converter) }
}
)
}

var api = init(defaultConverter, { path: '/' });

//操作cookie的方法
const localCookie = {
getItem: api.get,
setItem: api.set,
removeItem: api.remove,
keys() {
const aKeys = document.cookie.replace(/((?:^|\s*;)[^]+)(?=;|$)|^\s*|\s*(?:[^;]*)?(?:|$)/g, '').split(/\s*(?:[^;]*)?;\s*/);
for (let nIdx = 0; nIdx < aKeys.length; nIdx++) {
aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
}
return aKeys;
},
clear: function () {
clear() {
const keys = this.keys();
for (let i = 0; i < keys.length; i++) {
this.removeItem(keys[i]);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.aio.min.js

Large diffs are not rendered by default.

53 changes: 8 additions & 45 deletions dist/index.esm.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,25 @@
/*!
* galanga 0.2.4 (https://github.com/censujiang/galanga)
* galanga 0.2.5 (https://github.com/censujiang/galanga)
* API https://galanga.censujiang.com/api/
* Copyright 2014-2023 censujiang. All Rights Reserved
* Licensed under Apache License 2.0 (https://github.com/censujiang/galanga/blob/master/LICENSE)
*/

import Cookies from 'js-cookie';

//操作cookie的方法
const localCookie = {
getItem: (sKey) => {
return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
},
setItem: (sKey, sValue, sPath = '/', sDomain = window.location.hostname, vEnd, bSecure) => {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
return false;
}
let sExpires = '';
if (vEnd) {
if (typeof vEnd === 'number') {
const dExpires = new Date();
dExpires.setTime(dExpires.getTime() + (vEnd * 24 * 60 * 60 * 1000));
sExpires = '; expires=' + dExpires.toUTCString();
}
else if (typeof vEnd === 'string') {
sExpires = '; expires=' + vEnd;
}
else if (vEnd instanceof Date) {
sExpires = '; expires=' + vEnd.toUTCString();
}
}
document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) +
sExpires +
(sDomain ? '; domain=' + sDomain : '') +
(sPath ? '; path=' + sPath : '') +
(bSecure ? '; secure' : '');
return true;
},
removeItem: (sKey, sPath = '/', sDomain = window.location.hostname) => {
if (!sKey || !localCookie.hasItem(sKey)) {
return false;
}
document.cookie = encodeURIComponent(sKey) +
'=; expires=Thu, 01 Jan 1970 00:00:00 UTC' +
(sDomain ? '; domain=' + sDomain : '') +
(sPath ? '; path=' + sPath : '') +
'; secure';
return true;
},
hasItem: function (sKey) {
return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
},
keys: /* optional method: you can safely remove it! */ function () {
getItem: Cookies.get,
setItem: Cookies.set,
removeItem: Cookies.remove,
keys() {
const aKeys = document.cookie.replace(/((?:^|\s*;)[^]+)(?=;|$)|^\s*|\s*(?:[^;]*)?(?:|$)/g, '').split(/\s*(?:[^;]*)?;\s*/);
for (let nIdx = 0; nIdx < aKeys.length; nIdx++) {
aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
}
return aKeys;
},
clear: function () {
clear() {
const keys = this.keys();
for (let i = 0; i < keys.length; i++) {
this.removeItem(keys[i]);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.esm.min.js

Large diffs are not rendered by default.

53 changes: 8 additions & 45 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,27 @@
/*!
* galanga 0.2.4 (https://github.com/censujiang/galanga)
* galanga 0.2.5 (https://github.com/censujiang/galanga)
* API https://galanga.censujiang.com/api/
* Copyright 2014-2023 censujiang. All Rights Reserved
* Licensed under Apache License 2.0 (https://github.com/censujiang/galanga/blob/master/LICENSE)
*/

'use strict';

var Cookies = require('js-cookie');

//操作cookie的方法
const localCookie = {
getItem: (sKey) => {
return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
},
setItem: (sKey, sValue, sPath = '/', sDomain = window.location.hostname, vEnd, bSecure) => {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
return false;
}
let sExpires = '';
if (vEnd) {
if (typeof vEnd === 'number') {
const dExpires = new Date();
dExpires.setTime(dExpires.getTime() + (vEnd * 24 * 60 * 60 * 1000));
sExpires = '; expires=' + dExpires.toUTCString();
}
else if (typeof vEnd === 'string') {
sExpires = '; expires=' + vEnd;
}
else if (vEnd instanceof Date) {
sExpires = '; expires=' + vEnd.toUTCString();
}
}
document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) +
sExpires +
(sDomain ? '; domain=' + sDomain : '') +
(sPath ? '; path=' + sPath : '') +
(bSecure ? '; secure' : '');
return true;
},
removeItem: (sKey, sPath = '/', sDomain = window.location.hostname) => {
if (!sKey || !localCookie.hasItem(sKey)) {
return false;
}
document.cookie = encodeURIComponent(sKey) +
'=; expires=Thu, 01 Jan 1970 00:00:00 UTC' +
(sDomain ? '; domain=' + sDomain : '') +
(sPath ? '; path=' + sPath : '') +
'; secure';
return true;
},
hasItem: function (sKey) {
return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
},
keys: /* optional method: you can safely remove it! */ function () {
getItem: Cookies.get,
setItem: Cookies.set,
removeItem: Cookies.remove,
keys() {
const aKeys = document.cookie.replace(/((?:^|\s*;)[^]+)(?=;|$)|^\s*|\s*(?:[^;]*)?(?:|$)/g, '').split(/\s*(?:[^;]*)?;\s*/);
for (let nIdx = 0; nIdx < aKeys.length; nIdx++) {
aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
}
return aKeys;
},
clear: function () {
clear() {
const keys = this.keys();
for (let i = 0; i < keys.length; i++) {
this.removeItem(keys[i]);
Expand Down
Loading

0 comments on commit 5521fc3

Please sign in to comment.