|
3 | 3 | * bbo is a utility library of zero dependencies for javascript.
|
4 | 4 | * (c) 2011 - 2021
|
5 | 5 | * https://github.com/tnfe/bbo.git
|
6 |
| - * version 1.1.25 |
| 6 | + * version 1.1.26 |
7 | 7 | */
|
8 | 8 |
|
9 | 9 | (function (global, factory) {
|
|
118 | 118 | return getTag(func) === '[object Function]';
|
119 | 119 | }
|
120 | 120 |
|
121 |
| - var version = '1.1.25'; |
| 121 | + var version = '1.1.26'; |
122 | 122 |
|
123 | 123 | var globalObject = null;
|
124 | 124 |
|
|
1014 | 1014 | return acc;
|
1015 | 1015 | }, {});
|
1016 | 1016 |
|
1017 |
| - /** |
1018 |
| - * Whether a string contains another string |
1019 |
| - */ |
1020 |
| - function containsWith(target, item) { |
1021 |
| - // discuss at: https://locutus.io/golang/strings/Contains |
1022 |
| - // original by: Kevin van Zonneveld (https://kvz.io) |
1023 |
| - // example 1: bbo.contains('Kevin', 'K') |
1024 |
| - // returns 1: true |
1025 |
| - return String(target).indexOf(item) !== -1; |
1026 |
| - } |
1027 |
| - |
1028 |
| - /************************************************************************ |
1029 |
| - * localStorage && sessionStorage |
1030 |
| - * Method for safely supporting localStorage sessionStorage 'setItem' 'getItem' 'removeItem' 'removeAll', |
1031 |
| - * Some extension method 'has' 'get' adn Store prefix |
1032 |
| - *************************************************************************/ |
1033 |
| - var storage; |
1034 |
| - |
1035 |
| - try { |
1036 |
| - var ulocalStorage = window.localStorage; |
1037 |
| - var ussesionStorage = window.sessionStorage; |
1038 |
| - |
1039 |
| - class Storage { |
1040 |
| - constructor(options) { |
1041 |
| - var _options$type = options.type, |
1042 |
| - type = _options$type === void 0 ? 'local' : _options$type, |
1043 |
| - _options$prefix = options.prefix, |
1044 |
| - prefix = _options$prefix === void 0 ? 'bbo.storage' : _options$prefix, |
1045 |
| - _options$message = options.message, |
1046 |
| - message = _options$message === void 0 ? { |
1047 |
| - setItem: 'write in', |
1048 |
| - getItem: 'read', |
1049 |
| - removeAll: 'remove all', |
1050 |
| - removeItem: 'remove item' |
1051 |
| - } : _options$message; |
1052 |
| - this.prefix = prefix; |
1053 |
| - this.type = type; |
1054 |
| - this.message = message; |
1055 |
| - |
1056 |
| - if (type === 'local') { |
1057 |
| - this._storage = ulocalStorage; |
1058 |
| - } else if (type === 'session') { |
1059 |
| - this._storage = ussesionStorage; |
1060 |
| - } |
1061 |
| - } |
1062 |
| - |
1063 |
| - doItem(func, action) { |
1064 |
| - try { |
1065 |
| - if (isFunction(func)) { |
1066 |
| - return func(); |
1067 |
| - } |
1068 |
| - } catch (err) { |
1069 |
| - this._warn(action); |
1070 |
| - |
1071 |
| - return null; |
1072 |
| - } |
1073 |
| - |
1074 |
| - return true; |
1075 |
| - } |
1076 |
| - |
1077 |
| - setItem(key, value) { |
1078 |
| - if (isObject(key)) { |
1079 |
| - Object.keys(key).forEach((k, index) => { |
1080 |
| - this.doItem(() => this._storage.setItem(`${this.prefix}.${k}`, JSON.stringify(key[k])), 'setItem'); |
1081 |
| - }); |
1082 |
| - } else { |
1083 |
| - this.doItem(() => this._storage.setItem(`${this.prefix}.${key}`, JSON.stringify(value)), 'setItem'); |
1084 |
| - } |
1085 |
| - } |
1086 |
| - |
1087 |
| - has() { |
1088 |
| - for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) { |
1089 |
| - keys[_key] = arguments[_key]; |
1090 |
| - } |
1091 |
| - |
1092 |
| - return keys.every((key, index) => this._storage.getItem(`${this.prefix}.${key}`)); |
1093 |
| - } |
1094 |
| - |
1095 |
| - get() { |
1096 |
| - var result = {}; |
1097 |
| - |
1098 |
| - for (var _len2 = arguments.length, keys = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { |
1099 |
| - keys[_key2] = arguments[_key2]; |
1100 |
| - } |
1101 |
| - |
1102 |
| - keys.forEach((key, index) => { |
1103 |
| - if (`${this._storage.getItem(`${this.prefix}.${key}`)}` !== 'null') { |
1104 |
| - try { |
1105 |
| - result[key] = JSON.parse(this._storage.getItem(`${this.prefix}.${key}`)); |
1106 |
| - } catch (err) { |
1107 |
| - console.warn(this._warn('getItem')); |
1108 |
| - } |
1109 |
| - } |
1110 |
| - }); |
1111 |
| - return result; |
1112 |
| - } |
1113 |
| - |
1114 |
| - getItem(key) { |
1115 |
| - return this.doItem(() => JSON.parse(this._storage.getItem(`${this.prefix}.${key}`)), 'getItem'); |
1116 |
| - } |
1117 |
| - |
1118 |
| - removeAll() { |
1119 |
| - Object.keys(this._storage).forEach(k => { |
1120 |
| - if (containsWith(k, this.prefix)) { |
1121 |
| - this._remove(`${k}`); |
1122 |
| - } |
1123 |
| - }); |
1124 |
| - } |
1125 |
| - |
1126 |
| - removeItem() { |
1127 |
| - for (var _len3 = arguments.length, keys = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { |
1128 |
| - keys[_key3] = arguments[_key3]; |
1129 |
| - } |
1130 |
| - |
1131 |
| - console.log(keys); |
1132 |
| - keys.forEach((key, index) => this.doItem(() => this._storage.removeItem(`${this.prefix}.${key}`), 'removeItem')); |
1133 |
| - } |
1134 |
| - |
1135 |
| - _warn(action) { |
1136 |
| - var message = this.message; |
1137 |
| - console.warn(`Unable to ${message[action] || ''} ${this.type} Storage`); |
1138 |
| - } |
1139 |
| - |
1140 |
| - _remove(keys) { |
1141 |
| - this.doItem(() => this._storage.removeItem(`${keys}`), 'removeItem'); |
1142 |
| - } |
1143 |
| - |
1144 |
| - } |
1145 |
| - |
1146 |
| - storage = (_ref) => { |
1147 |
| - var type = _ref.type, |
1148 |
| - prefix = _ref.prefix; |
1149 |
| - return new Storage({ |
1150 |
| - type: type, |
1151 |
| - prefix: prefix |
1152 |
| - }); |
1153 |
| - }; |
1154 |
| - } catch (e) { |
1155 |
| - storage = noop; |
1156 |
| - console.error(e); |
1157 |
| - } |
1158 |
| - |
1159 |
| - var storage$1 = storage; |
1160 |
| - |
1161 | 1017 | /**
|
1162 | 1018 | * getUrlParam / deleteUrlParam
|
1163 | 1019 | * From https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
|
|
2560 | 2416 | return ignore ? str.toLowerCase() === item.toLowerCase() : str === item;
|
2561 | 2417 | }
|
2562 | 2418 |
|
| 2419 | + /** |
| 2420 | + * Whether a string contains another string |
| 2421 | + */ |
| 2422 | + function containsWith(target, item) { |
| 2423 | + // discuss at: https://locutus.io/golang/strings/Contains |
| 2424 | + // original by: Kevin van Zonneveld (https://kvz.io) |
| 2425 | + // example 1: bbo.contains('Kevin', 'K') |
| 2426 | + // returns 1: true |
| 2427 | + return String(target).indexOf(item) !== -1; |
| 2428 | + } |
| 2429 | + |
2563 | 2430 | /**
|
2564 | 2431 | * XSS string filtering
|
2565 | 2432 | */
|
|
3096 | 2963 | deleteCookie: deleteCookie,
|
3097 | 2964 | delCookie: deleteCookie,
|
3098 | 2965 | parseCookie: parseCookie,
|
3099 |
| - // storage |
3100 |
| - storage: storage$1, |
3101 | 2966 | // http
|
3102 | 2967 | open: open,
|
3103 | 2968 | getUrlParam: getUrlParam,
|
|
0 commit comments