@alibarbar/common 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +28 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -4
- package/dist/storage.cjs +28 -6
- package/dist/storage.d.mts +9 -77
- package/dist/storage.d.ts +9 -77
- package/dist/storage.js +28 -4
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -2371,7 +2371,8 @@ var cookie = {
|
|
|
2371
2371
|
const cookieKey = trimmed.substring(0, eqIndex).trim();
|
|
2372
2372
|
const cookieValue = trimmed.substring(eqIndex + 1).trim();
|
|
2373
2373
|
if (cookieKey === name) {
|
|
2374
|
-
|
|
2374
|
+
const decoded = decodeURIComponent(cookieValue);
|
|
2375
|
+
return decoded === "" ? void 0 : decoded;
|
|
2375
2376
|
}
|
|
2376
2377
|
}
|
|
2377
2378
|
return void 0;
|
|
@@ -2396,18 +2397,23 @@ var cookie = {
|
|
|
2396
2397
|
const cookies = {};
|
|
2397
2398
|
document.cookie.split(";").forEach((cookieStr) => {
|
|
2398
2399
|
const trimmed = cookieStr.trim();
|
|
2400
|
+
if (!trimmed) return;
|
|
2399
2401
|
const eqIndex = trimmed.indexOf("=");
|
|
2400
2402
|
if (eqIndex === -1) return;
|
|
2401
2403
|
const key = trimmed.substring(0, eqIndex).trim();
|
|
2402
2404
|
const value = trimmed.substring(eqIndex + 1).trim();
|
|
2403
2405
|
if (key && value) {
|
|
2404
|
-
|
|
2406
|
+
const decodedKey = decodeURIComponent(key);
|
|
2407
|
+
const decodedValue = decodeURIComponent(value);
|
|
2408
|
+
if (decodedValue !== "") {
|
|
2409
|
+
cookies[decodedKey] = decodedValue;
|
|
2410
|
+
}
|
|
2405
2411
|
}
|
|
2406
2412
|
});
|
|
2407
2413
|
return cookies;
|
|
2408
2414
|
}
|
|
2409
2415
|
};
|
|
2410
|
-
var
|
|
2416
|
+
var secureStorage = {
|
|
2411
2417
|
/**
|
|
2412
2418
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
2413
2419
|
* @param key - 键
|
|
@@ -2454,6 +2460,24 @@ var storage = {
|
|
|
2454
2460
|
clear() {
|
|
2455
2461
|
localStorage.clear();
|
|
2456
2462
|
sessionStorage.clear();
|
|
2463
|
+
},
|
|
2464
|
+
/**
|
|
2465
|
+
* 获取所有键名
|
|
2466
|
+
* @returns 键名数组
|
|
2467
|
+
*/
|
|
2468
|
+
keys() {
|
|
2469
|
+
const localKeys = localStorage.keys();
|
|
2470
|
+
const sessionKeys = [];
|
|
2471
|
+
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
2472
|
+
try {
|
|
2473
|
+
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
2474
|
+
const key = window.sessionStorage.key(i);
|
|
2475
|
+
if (key) sessionKeys.push(key);
|
|
2476
|
+
}
|
|
2477
|
+
} catch (error) {
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
return Array.from(/* @__PURE__ */ new Set([...localKeys, ...sessionKeys]));
|
|
2457
2481
|
}
|
|
2458
2482
|
};
|
|
2459
2483
|
|
|
@@ -4463,7 +4487,6 @@ exports.kebabCase = kebabCase;
|
|
|
4463
4487
|
exports.keys = keys;
|
|
4464
4488
|
exports.lcm = lcm;
|
|
4465
4489
|
exports.lighten = lighten;
|
|
4466
|
-
exports.localStorage = localStorage;
|
|
4467
4490
|
exports.mapKeys = mapKeys;
|
|
4468
4491
|
exports.mapValues = mapValues;
|
|
4469
4492
|
exports.mask = mask;
|
|
@@ -4500,7 +4523,7 @@ exports.rsaDecrypt = rsaDecrypt;
|
|
|
4500
4523
|
exports.rsaEncrypt = rsaEncrypt;
|
|
4501
4524
|
exports.sample = sample;
|
|
4502
4525
|
exports.scrollTo = scrollTo;
|
|
4503
|
-
exports.
|
|
4526
|
+
exports.secureStorage = secureStorage;
|
|
4504
4527
|
exports.set = set;
|
|
4505
4528
|
exports.setCommonParams = setCommonParams;
|
|
4506
4529
|
exports.setQueryParams = setQueryParams;
|
|
@@ -4515,7 +4538,6 @@ exports.snakeCase = snakeCase;
|
|
|
4515
4538
|
exports.sortBy = sortBy;
|
|
4516
4539
|
exports.splitFileIntoChunks = splitFileIntoChunks;
|
|
4517
4540
|
exports.startOfDay = startOfDay;
|
|
4518
|
-
exports.storage = storage;
|
|
4519
4541
|
exports.take = take;
|
|
4520
4542
|
exports.takeWhile = takeWhile;
|
|
4521
4543
|
exports.template = template;
|
package/dist/index.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ export { HSL, RGB, contrast, darken, hexToRgb, hslToRgb, lighten, mix, rgbToHex,
|
|
|
9
9
|
export { CurrencyCode, Locale, TranslationDictionary, createTranslator, formatCurrencyI18n, formatDateI18n, formatNumberI18n, formatRelativeTime, getLocale, pluralize, translate } from './i18n.mjs';
|
|
10
10
|
export { calculateBlobMD5, calculateFileMD5, formatFileSize, getFileExtension, getFileNameWithoutExtension, splitFileIntoChunks } from './file.mjs';
|
|
11
11
|
export { A as ApiResponse, h as ChunkInfo, b as ChunkUploadResponse, C as ChunkUploader, d as CompleteUploadResponse, U as UploadInitRequest, a as UploadInitResponse, f as UploadOptions, e as UploadProgress, g as UploadStatus, c as createUploader, u as uploadFile } from './index-DchqyDBQ.mjs';
|
|
12
|
-
export { StorageInitOptions, StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys,
|
|
12
|
+
export { StorageInitOptions, StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair } from './storage.mjs';
|
|
13
13
|
export { checkOnline, downloadFile, fetchWithRetry, fetchWithTimeout, request } from './network.mjs';
|
|
14
14
|
export { $, $$, addClass, copyToClipboard, getElementOffset, getScrollPosition, getStyle, isInViewport, removeClass, scrollTo, setStyle, toggleClass } from './dom.mjs';
|
|
15
15
|
export { csvToJson, jsonToCsv, jsonToXml, jsonToYaml, xmlToJson, yamlToJson } from './transform.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { HSL, RGB, contrast, darken, hexToRgb, hslToRgb, lighten, mix, rgbToHex,
|
|
|
9
9
|
export { CurrencyCode, Locale, TranslationDictionary, createTranslator, formatCurrencyI18n, formatDateI18n, formatNumberI18n, formatRelativeTime, getLocale, pluralize, translate } from './i18n.js';
|
|
10
10
|
export { calculateBlobMD5, calculateFileMD5, formatFileSize, getFileExtension, getFileNameWithoutExtension, splitFileIntoChunks } from './file.js';
|
|
11
11
|
export { A as ApiResponse, h as ChunkInfo, b as ChunkUploadResponse, C as ChunkUploader, d as CompleteUploadResponse, U as UploadInitRequest, a as UploadInitResponse, f as UploadOptions, e as UploadProgress, g as UploadStatus, c as createUploader, u as uploadFile } from './index-DchqyDBQ.js';
|
|
12
|
-
export { StorageInitOptions, StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys,
|
|
12
|
+
export { StorageInitOptions, StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair } from './storage.js';
|
|
13
13
|
export { checkOnline, downloadFile, fetchWithRetry, fetchWithTimeout, request } from './network.js';
|
|
14
14
|
export { $, $$, addClass, copyToClipboard, getElementOffset, getScrollPosition, getStyle, isInViewport, removeClass, scrollTo, setStyle, toggleClass } from './dom.js';
|
|
15
15
|
export { csvToJson, jsonToCsv, jsonToXml, jsonToYaml, xmlToJson, yamlToJson } from './transform.js';
|
package/dist/index.js
CHANGED
|
@@ -2364,7 +2364,8 @@ var cookie = {
|
|
|
2364
2364
|
const cookieKey = trimmed.substring(0, eqIndex).trim();
|
|
2365
2365
|
const cookieValue = trimmed.substring(eqIndex + 1).trim();
|
|
2366
2366
|
if (cookieKey === name) {
|
|
2367
|
-
|
|
2367
|
+
const decoded = decodeURIComponent(cookieValue);
|
|
2368
|
+
return decoded === "" ? void 0 : decoded;
|
|
2368
2369
|
}
|
|
2369
2370
|
}
|
|
2370
2371
|
return void 0;
|
|
@@ -2389,18 +2390,23 @@ var cookie = {
|
|
|
2389
2390
|
const cookies = {};
|
|
2390
2391
|
document.cookie.split(";").forEach((cookieStr) => {
|
|
2391
2392
|
const trimmed = cookieStr.trim();
|
|
2393
|
+
if (!trimmed) return;
|
|
2392
2394
|
const eqIndex = trimmed.indexOf("=");
|
|
2393
2395
|
if (eqIndex === -1) return;
|
|
2394
2396
|
const key = trimmed.substring(0, eqIndex).trim();
|
|
2395
2397
|
const value = trimmed.substring(eqIndex + 1).trim();
|
|
2396
2398
|
if (key && value) {
|
|
2397
|
-
|
|
2399
|
+
const decodedKey = decodeURIComponent(key);
|
|
2400
|
+
const decodedValue = decodeURIComponent(value);
|
|
2401
|
+
if (decodedValue !== "") {
|
|
2402
|
+
cookies[decodedKey] = decodedValue;
|
|
2403
|
+
}
|
|
2398
2404
|
}
|
|
2399
2405
|
});
|
|
2400
2406
|
return cookies;
|
|
2401
2407
|
}
|
|
2402
2408
|
};
|
|
2403
|
-
var
|
|
2409
|
+
var secureStorage = {
|
|
2404
2410
|
/**
|
|
2405
2411
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
2406
2412
|
* @param key - 键
|
|
@@ -2447,6 +2453,24 @@ var storage = {
|
|
|
2447
2453
|
clear() {
|
|
2448
2454
|
localStorage.clear();
|
|
2449
2455
|
sessionStorage.clear();
|
|
2456
|
+
},
|
|
2457
|
+
/**
|
|
2458
|
+
* 获取所有键名
|
|
2459
|
+
* @returns 键名数组
|
|
2460
|
+
*/
|
|
2461
|
+
keys() {
|
|
2462
|
+
const localKeys = localStorage.keys();
|
|
2463
|
+
const sessionKeys = [];
|
|
2464
|
+
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
2465
|
+
try {
|
|
2466
|
+
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
2467
|
+
const key = window.sessionStorage.key(i);
|
|
2468
|
+
if (key) sessionKeys.push(key);
|
|
2469
|
+
}
|
|
2470
|
+
} catch (error) {
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
return Array.from(/* @__PURE__ */ new Set([...localKeys, ...sessionKeys]));
|
|
2450
2474
|
}
|
|
2451
2475
|
};
|
|
2452
2476
|
|
|
@@ -4319,4 +4343,4 @@ function convertRes2Blob(response) {
|
|
|
4319
4343
|
}
|
|
4320
4344
|
}
|
|
4321
4345
|
|
|
4322
|
-
export { $, $$, BinaryTree, ChunkUploader, DataQueue, Graph, LRUCache, LinkedList, Queue, Stack, Tracker, UploadStatus, addClass, addDays, addMonths, addYears, aesGCMDecrypt, aesGCMEncrypt, base64Decode, base64Encode, batch, binarySearch, bubbleSort, buildUrl, calculateBlobMD5, calculateFileMD5, camelCase, capitalize, ceil, checkOnline, chunk, clamp, clearPersistedKeys, compact, computeHMAC, contrast, cookie, copyToClipboard, createTracker, createTranslator, createUploader, csvToJson, darken, debounce, deepClone, deepMerge, defaults, deriveKeyFromPassword, diffDays, difference, downloadFile, drop, dropWhile, endOfDay, escapeHtml, exportPrivateKey, exportPublicKey, factorial, fetchWithRetry, fetchWithTimeout, fibonacci, fibonacciSequence, findIndexBy, flatten, floor, flush, formatBytes, formatCurrency, formatCurrencyI18n, formatDate, formatDateI18n, formatFileSize, formatNumber, formatNumberI18n, formatRelativeTime, gcd, generateHMACKey, generateRSAKeyPair, generateRandomString, generateUUID, get, getDateFormatByGMT, getElementOffset, getFileExtension, getFileNameWithoutExtension, getKeyUsageCount, getLocale, getQuarter, getQueryParams, getRelativeTime, getScrollPosition, getStorageKeyPair, getStyle, getTimeFromGMT, getTracker, getWeekNumber, groupBy, hash, hexToRgb, highlight, hslToRgb, importPrivateKey, importPublicKey, initTracker, initializeStorageKeys, intersection, invert, isAbsoluteUrl, isBetween, isEmpty, isEmptyObject, isEqual, isFloat, isInViewport, isInteger, isNumeric, isToday, isValidDomain, isValidEmail, isValidHexColor, isValidIP, isValidIdCard, isValidJSON, isValidPhone, isValidUUID, isValidUrl, isWeekday, isWeekend, isYesterday, joinUrl, jsonToCsv, jsonToXml, jsonToYaml, kebabCase, keys, lcm, lighten,
|
|
4346
|
+
export { $, $$, BinaryTree, ChunkUploader, DataQueue, Graph, LRUCache, LinkedList, Queue, Stack, Tracker, UploadStatus, addClass, addDays, addMonths, addYears, aesGCMDecrypt, aesGCMEncrypt, base64Decode, base64Encode, batch, binarySearch, bubbleSort, buildUrl, calculateBlobMD5, calculateFileMD5, camelCase, capitalize, ceil, checkOnline, chunk, clamp, clearPersistedKeys, compact, computeHMAC, contrast, cookie, copyToClipboard, createTracker, createTranslator, createUploader, csvToJson, darken, debounce, deepClone, deepMerge, defaults, deriveKeyFromPassword, diffDays, difference, downloadFile, drop, dropWhile, endOfDay, escapeHtml, exportPrivateKey, exportPublicKey, factorial, fetchWithRetry, fetchWithTimeout, fibonacci, fibonacciSequence, findIndexBy, flatten, floor, flush, formatBytes, formatCurrency, formatCurrencyI18n, formatDate, formatDateI18n, formatFileSize, formatNumber, formatNumberI18n, formatRelativeTime, gcd, generateHMACKey, generateRSAKeyPair, generateRandomString, generateUUID, get, getDateFormatByGMT, getElementOffset, getFileExtension, getFileNameWithoutExtension, getKeyUsageCount, getLocale, getQuarter, getQueryParams, getRelativeTime, getScrollPosition, getStorageKeyPair, getStyle, getTimeFromGMT, getTracker, getWeekNumber, groupBy, hash, hexToRgb, highlight, hslToRgb, importPrivateKey, importPublicKey, initTracker, initializeStorageKeys, intersection, invert, isAbsoluteUrl, isBetween, isEmpty, isEmptyObject, isEqual, isFloat, isInViewport, isInteger, isNumeric, isToday, isValidDomain, isValidEmail, isValidHexColor, isValidIP, isValidIdCard, isValidJSON, isValidPhone, isValidUUID, isValidUrl, isWeekday, isWeekend, isYesterday, joinUrl, jsonToCsv, jsonToXml, jsonToYaml, kebabCase, keys, lcm, lighten, mapKeys, mapValues, mask, maskEmail, maskPhone, memoize, merge, mergeSort, mix, normalizeUrl, omit, omitBy, once, parseNumber, parseUrl, partition, pascalCase, percent, pick, pickBy, pluralize, quickSort, random, removeAccents, removeClass, removeQueryParams, request, resetKeyUsageCount, retry, rgbToHex, rgbToHsl, round, rsaDecrypt, rsaEncrypt, sample, scrollTo, secureStorage, set, setCommonParams, setQueryParams, setServiceEventHandlers, setStorageKeyPair, setStyle, setUserInfo, sha256, shuffle, slugify, snakeCase, sortBy, splitFileIntoChunks, startOfDay, take, takeWhile, template, throttle, timeout, toFixed, toggleClass, trackClick, trackEvent, trackExposure, trackPageView, transform, translate, truncate, unescapeHtml, union, unique, unzip, updateQueryParams, uploadFile, values, verifyHMAC, xmlToJson, yamlToJson, zip };
|
package/dist/storage.cjs
CHANGED
|
@@ -845,7 +845,8 @@ var cookie = {
|
|
|
845
845
|
const cookieKey = trimmed.substring(0, eqIndex).trim();
|
|
846
846
|
const cookieValue = trimmed.substring(eqIndex + 1).trim();
|
|
847
847
|
if (cookieKey === name) {
|
|
848
|
-
|
|
848
|
+
const decoded = decodeURIComponent(cookieValue);
|
|
849
|
+
return decoded === "" ? void 0 : decoded;
|
|
849
850
|
}
|
|
850
851
|
}
|
|
851
852
|
return void 0;
|
|
@@ -870,18 +871,23 @@ var cookie = {
|
|
|
870
871
|
const cookies = {};
|
|
871
872
|
document.cookie.split(";").forEach((cookieStr) => {
|
|
872
873
|
const trimmed = cookieStr.trim();
|
|
874
|
+
if (!trimmed) return;
|
|
873
875
|
const eqIndex = trimmed.indexOf("=");
|
|
874
876
|
if (eqIndex === -1) return;
|
|
875
877
|
const key = trimmed.substring(0, eqIndex).trim();
|
|
876
878
|
const value = trimmed.substring(eqIndex + 1).trim();
|
|
877
879
|
if (key && value) {
|
|
878
|
-
|
|
880
|
+
const decodedKey = decodeURIComponent(key);
|
|
881
|
+
const decodedValue = decodeURIComponent(value);
|
|
882
|
+
if (decodedValue !== "") {
|
|
883
|
+
cookies[decodedKey] = decodedValue;
|
|
884
|
+
}
|
|
879
885
|
}
|
|
880
886
|
});
|
|
881
887
|
return cookies;
|
|
882
888
|
}
|
|
883
889
|
};
|
|
884
|
-
var
|
|
890
|
+
var secureStorage = {
|
|
885
891
|
/**
|
|
886
892
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
887
893
|
* @param key - 键
|
|
@@ -928,6 +934,24 @@ var storage = {
|
|
|
928
934
|
clear() {
|
|
929
935
|
localStorage.clear();
|
|
930
936
|
sessionStorage.clear();
|
|
937
|
+
},
|
|
938
|
+
/**
|
|
939
|
+
* 获取所有键名
|
|
940
|
+
* @returns 键名数组
|
|
941
|
+
*/
|
|
942
|
+
keys() {
|
|
943
|
+
const localKeys = localStorage.keys();
|
|
944
|
+
const sessionKeys = [];
|
|
945
|
+
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
946
|
+
try {
|
|
947
|
+
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
948
|
+
const key = window.sessionStorage.key(i);
|
|
949
|
+
if (key) sessionKeys.push(key);
|
|
950
|
+
}
|
|
951
|
+
} catch (error) {
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return Array.from(/* @__PURE__ */ new Set([...localKeys, ...sessionKeys]));
|
|
931
955
|
}
|
|
932
956
|
};
|
|
933
957
|
|
|
@@ -936,8 +960,6 @@ exports.cookie = cookie;
|
|
|
936
960
|
exports.getKeyUsageCount = getKeyUsageCount;
|
|
937
961
|
exports.getStorageKeyPair = getStorageKeyPair;
|
|
938
962
|
exports.initializeStorageKeys = initializeStorageKeys;
|
|
939
|
-
exports.localStorage = localStorage;
|
|
940
963
|
exports.resetKeyUsageCount = resetKeyUsageCount;
|
|
941
|
-
exports.
|
|
964
|
+
exports.secureStorage = secureStorage;
|
|
942
965
|
exports.setStorageKeyPair = setStorageKeyPair;
|
|
943
|
-
exports.storage = storage;
|
package/dist/storage.d.mts
CHANGED
|
@@ -70,80 +70,6 @@ declare function getKeyUsageCount(): number;
|
|
|
70
70
|
* 重置密钥使用计数
|
|
71
71
|
*/
|
|
72
72
|
declare function resetKeyUsageCount(): void;
|
|
73
|
-
/**
|
|
74
|
-
* localStorage封装(支持过期时间和RSA加密)
|
|
75
|
-
*/
|
|
76
|
-
declare const localStorage: {
|
|
77
|
-
/**
|
|
78
|
-
* 设置值
|
|
79
|
-
* @param key - 键
|
|
80
|
-
* @param value - 值
|
|
81
|
-
* @param options - 选项(过期时间、密钥等)
|
|
82
|
-
* @returns Promise<void>
|
|
83
|
-
*/
|
|
84
|
-
set<T>(key: string, value: T, options?: {
|
|
85
|
-
expiry?: number;
|
|
86
|
-
publicKey?: CryptoKey;
|
|
87
|
-
}): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* 获取值
|
|
90
|
-
* @param key - 键
|
|
91
|
-
* @param options - 选项(默认值、私钥等)
|
|
92
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
93
|
-
*/
|
|
94
|
-
get<T>(key: string, options?: {
|
|
95
|
-
defaultValue?: T;
|
|
96
|
-
privateKey?: CryptoKey;
|
|
97
|
-
}): Promise<T | undefined>;
|
|
98
|
-
/**
|
|
99
|
-
* 移除值
|
|
100
|
-
* @param key - 键
|
|
101
|
-
*/
|
|
102
|
-
remove(key: string): void;
|
|
103
|
-
/**
|
|
104
|
-
* 清空所有值
|
|
105
|
-
*/
|
|
106
|
-
clear(): void;
|
|
107
|
-
/**
|
|
108
|
-
* 获取所有键
|
|
109
|
-
* @returns 键数组
|
|
110
|
-
*/
|
|
111
|
-
keys(): string[];
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* sessionStorage封装(支持RSA加密)
|
|
115
|
-
*/
|
|
116
|
-
declare const sessionStorage: {
|
|
117
|
-
/**
|
|
118
|
-
* 设置值
|
|
119
|
-
* @param key - 键
|
|
120
|
-
* @param value - 值
|
|
121
|
-
* @param options - 选项(公钥等)
|
|
122
|
-
* @returns Promise<void>
|
|
123
|
-
*/
|
|
124
|
-
set<T>(key: string, value: T, options?: {
|
|
125
|
-
publicKey?: CryptoKey;
|
|
126
|
-
}): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* 获取值
|
|
129
|
-
* @param key - 键
|
|
130
|
-
* @param options - 选项(默认值、私钥等)
|
|
131
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
132
|
-
*/
|
|
133
|
-
get<T>(key: string, options?: {
|
|
134
|
-
defaultValue?: T;
|
|
135
|
-
privateKey?: CryptoKey;
|
|
136
|
-
}): Promise<T | undefined>;
|
|
137
|
-
/**
|
|
138
|
-
* 移除值
|
|
139
|
-
* @param key - 键
|
|
140
|
-
*/
|
|
141
|
-
remove(key: string): void;
|
|
142
|
-
/**
|
|
143
|
-
* 清空所有值
|
|
144
|
-
*/
|
|
145
|
-
clear(): void;
|
|
146
|
-
};
|
|
147
73
|
/**
|
|
148
74
|
* Cookie操作封装
|
|
149
75
|
*/
|
|
@@ -183,9 +109,10 @@ declare const cookie: {
|
|
|
183
109
|
getAll(): Record<string, string>;
|
|
184
110
|
};
|
|
185
111
|
/**
|
|
186
|
-
*
|
|
112
|
+
* 统一安全存储接口(自动选择存储方式,支持RSA加密)
|
|
113
|
+
* 这是推荐的主要导出接口
|
|
187
114
|
*/
|
|
188
|
-
declare const
|
|
115
|
+
declare const secureStorage: {
|
|
189
116
|
/**
|
|
190
117
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
191
118
|
* @param key - 键
|
|
@@ -216,6 +143,11 @@ declare const storage: {
|
|
|
216
143
|
* 清空所有值
|
|
217
144
|
*/
|
|
218
145
|
clear(): void;
|
|
146
|
+
/**
|
|
147
|
+
* 获取所有键名
|
|
148
|
+
* @returns 键名数组
|
|
149
|
+
*/
|
|
150
|
+
keys(): string[];
|
|
219
151
|
};
|
|
220
152
|
|
|
221
|
-
export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys,
|
|
153
|
+
export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair };
|
package/dist/storage.d.ts
CHANGED
|
@@ -70,80 +70,6 @@ declare function getKeyUsageCount(): number;
|
|
|
70
70
|
* 重置密钥使用计数
|
|
71
71
|
*/
|
|
72
72
|
declare function resetKeyUsageCount(): void;
|
|
73
|
-
/**
|
|
74
|
-
* localStorage封装(支持过期时间和RSA加密)
|
|
75
|
-
*/
|
|
76
|
-
declare const localStorage: {
|
|
77
|
-
/**
|
|
78
|
-
* 设置值
|
|
79
|
-
* @param key - 键
|
|
80
|
-
* @param value - 值
|
|
81
|
-
* @param options - 选项(过期时间、密钥等)
|
|
82
|
-
* @returns Promise<void>
|
|
83
|
-
*/
|
|
84
|
-
set<T>(key: string, value: T, options?: {
|
|
85
|
-
expiry?: number;
|
|
86
|
-
publicKey?: CryptoKey;
|
|
87
|
-
}): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* 获取值
|
|
90
|
-
* @param key - 键
|
|
91
|
-
* @param options - 选项(默认值、私钥等)
|
|
92
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
93
|
-
*/
|
|
94
|
-
get<T>(key: string, options?: {
|
|
95
|
-
defaultValue?: T;
|
|
96
|
-
privateKey?: CryptoKey;
|
|
97
|
-
}): Promise<T | undefined>;
|
|
98
|
-
/**
|
|
99
|
-
* 移除值
|
|
100
|
-
* @param key - 键
|
|
101
|
-
*/
|
|
102
|
-
remove(key: string): void;
|
|
103
|
-
/**
|
|
104
|
-
* 清空所有值
|
|
105
|
-
*/
|
|
106
|
-
clear(): void;
|
|
107
|
-
/**
|
|
108
|
-
* 获取所有键
|
|
109
|
-
* @returns 键数组
|
|
110
|
-
*/
|
|
111
|
-
keys(): string[];
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* sessionStorage封装(支持RSA加密)
|
|
115
|
-
*/
|
|
116
|
-
declare const sessionStorage: {
|
|
117
|
-
/**
|
|
118
|
-
* 设置值
|
|
119
|
-
* @param key - 键
|
|
120
|
-
* @param value - 值
|
|
121
|
-
* @param options - 选项(公钥等)
|
|
122
|
-
* @returns Promise<void>
|
|
123
|
-
*/
|
|
124
|
-
set<T>(key: string, value: T, options?: {
|
|
125
|
-
publicKey?: CryptoKey;
|
|
126
|
-
}): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* 获取值
|
|
129
|
-
* @param key - 键
|
|
130
|
-
* @param options - 选项(默认值、私钥等)
|
|
131
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
132
|
-
*/
|
|
133
|
-
get<T>(key: string, options?: {
|
|
134
|
-
defaultValue?: T;
|
|
135
|
-
privateKey?: CryptoKey;
|
|
136
|
-
}): Promise<T | undefined>;
|
|
137
|
-
/**
|
|
138
|
-
* 移除值
|
|
139
|
-
* @param key - 键
|
|
140
|
-
*/
|
|
141
|
-
remove(key: string): void;
|
|
142
|
-
/**
|
|
143
|
-
* 清空所有值
|
|
144
|
-
*/
|
|
145
|
-
clear(): void;
|
|
146
|
-
};
|
|
147
73
|
/**
|
|
148
74
|
* Cookie操作封装
|
|
149
75
|
*/
|
|
@@ -183,9 +109,10 @@ declare const cookie: {
|
|
|
183
109
|
getAll(): Record<string, string>;
|
|
184
110
|
};
|
|
185
111
|
/**
|
|
186
|
-
*
|
|
112
|
+
* 统一安全存储接口(自动选择存储方式,支持RSA加密)
|
|
113
|
+
* 这是推荐的主要导出接口
|
|
187
114
|
*/
|
|
188
|
-
declare const
|
|
115
|
+
declare const secureStorage: {
|
|
189
116
|
/**
|
|
190
117
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
191
118
|
* @param key - 键
|
|
@@ -216,6 +143,11 @@ declare const storage: {
|
|
|
216
143
|
* 清空所有值
|
|
217
144
|
*/
|
|
218
145
|
clear(): void;
|
|
146
|
+
/**
|
|
147
|
+
* 获取所有键名
|
|
148
|
+
* @returns 键名数组
|
|
149
|
+
*/
|
|
150
|
+
keys(): string[];
|
|
219
151
|
};
|
|
220
152
|
|
|
221
|
-
export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys,
|
|
153
|
+
export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair };
|
package/dist/storage.js
CHANGED
|
@@ -843,7 +843,8 @@ var cookie = {
|
|
|
843
843
|
const cookieKey = trimmed.substring(0, eqIndex).trim();
|
|
844
844
|
const cookieValue = trimmed.substring(eqIndex + 1).trim();
|
|
845
845
|
if (cookieKey === name) {
|
|
846
|
-
|
|
846
|
+
const decoded = decodeURIComponent(cookieValue);
|
|
847
|
+
return decoded === "" ? void 0 : decoded;
|
|
847
848
|
}
|
|
848
849
|
}
|
|
849
850
|
return void 0;
|
|
@@ -868,18 +869,23 @@ var cookie = {
|
|
|
868
869
|
const cookies = {};
|
|
869
870
|
document.cookie.split(";").forEach((cookieStr) => {
|
|
870
871
|
const trimmed = cookieStr.trim();
|
|
872
|
+
if (!trimmed) return;
|
|
871
873
|
const eqIndex = trimmed.indexOf("=");
|
|
872
874
|
if (eqIndex === -1) return;
|
|
873
875
|
const key = trimmed.substring(0, eqIndex).trim();
|
|
874
876
|
const value = trimmed.substring(eqIndex + 1).trim();
|
|
875
877
|
if (key && value) {
|
|
876
|
-
|
|
878
|
+
const decodedKey = decodeURIComponent(key);
|
|
879
|
+
const decodedValue = decodeURIComponent(value);
|
|
880
|
+
if (decodedValue !== "") {
|
|
881
|
+
cookies[decodedKey] = decodedValue;
|
|
882
|
+
}
|
|
877
883
|
}
|
|
878
884
|
});
|
|
879
885
|
return cookies;
|
|
880
886
|
}
|
|
881
887
|
};
|
|
882
|
-
var
|
|
888
|
+
var secureStorage = {
|
|
883
889
|
/**
|
|
884
890
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
885
891
|
* @param key - 键
|
|
@@ -926,7 +932,25 @@ var storage = {
|
|
|
926
932
|
clear() {
|
|
927
933
|
localStorage.clear();
|
|
928
934
|
sessionStorage.clear();
|
|
935
|
+
},
|
|
936
|
+
/**
|
|
937
|
+
* 获取所有键名
|
|
938
|
+
* @returns 键名数组
|
|
939
|
+
*/
|
|
940
|
+
keys() {
|
|
941
|
+
const localKeys = localStorage.keys();
|
|
942
|
+
const sessionKeys = [];
|
|
943
|
+
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
944
|
+
try {
|
|
945
|
+
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
946
|
+
const key = window.sessionStorage.key(i);
|
|
947
|
+
if (key) sessionKeys.push(key);
|
|
948
|
+
}
|
|
949
|
+
} catch (error) {
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return Array.from(/* @__PURE__ */ new Set([...localKeys, ...sessionKeys]));
|
|
929
953
|
}
|
|
930
954
|
};
|
|
931
955
|
|
|
932
|
-
export { clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys,
|
|
956
|
+
export { clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alibarbar/common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Alibarbar 通用工具库",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -139,6 +139,8 @@
|
|
|
139
139
|
"format": "prettier --write \"src/**/*.{ts,json,md}\"",
|
|
140
140
|
"format:check": "prettier --check \"src/**/*.{ts,json,md}\"",
|
|
141
141
|
"prepublishOnly": "npm run build && npm run test",
|
|
142
|
+
"prepack": "npm run build",
|
|
143
|
+
"pack:dry-run": "npm pack --dry-run",
|
|
142
144
|
"type-check": "tsc --noEmit",
|
|
143
145
|
"analyze": "echo 'Bundle size analysis - check dist/ directory'",
|
|
144
146
|
"precommit": "npm run lint && npm run format:check && npm run type-check",
|