@noah-libjs/utils 0.0.6 → 0.0.8
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/es.js +206 -37
- package/dist/helper.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib.js +208 -37
- package/dist/load-src.d.ts +16 -0
- package/dist/moment-help.d.ts +1 -0
- package/dist/option-help.d.ts +0 -2
- package/dist/small-fn.d.ts +6 -6
- package/dist/type-utils.d.ts +1 -0
- package/dist/typing.d.ts +37 -20
- package/package.json +2 -2
package/dist/es.js
CHANGED
|
@@ -1418,10 +1418,13 @@ function cloneDeep(value) {
|
|
|
1418
1418
|
return null;
|
|
1419
1419
|
}
|
|
1420
1420
|
}
|
|
1421
|
+
function hasOwn(obj, key) {
|
|
1422
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1423
|
+
}
|
|
1421
1424
|
function safe_json_parse(str) {
|
|
1422
1425
|
var retOnErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1423
1426
|
if (!str) return retOnErr;
|
|
1424
|
-
if (
|
|
1427
|
+
if (isObject(str) || isArray(str)) return str;
|
|
1425
1428
|
if (!isString(str)) return retOnErr;
|
|
1426
1429
|
try {
|
|
1427
1430
|
var v = JSON.parse(str);
|
|
@@ -1500,7 +1503,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1500
1503
|
// }
|
|
1501
1504
|
function get_global() {
|
|
1502
1505
|
var _a;
|
|
1503
|
-
|
|
1506
|
+
try {
|
|
1507
|
+
return (_a = globalThis !== null && globalThis !== void 0 ? globalThis : window) !== null && _a !== void 0 ? _a : global;
|
|
1508
|
+
} catch (error) {
|
|
1509
|
+
return {};
|
|
1510
|
+
}
|
|
1504
1511
|
}
|
|
1505
1512
|
function getSearchParamsValue(key) {
|
|
1506
1513
|
var _a, _b;
|
|
@@ -1739,35 +1746,55 @@ function safe_async_call(cb) {
|
|
|
1739
1746
|
}, _callee8);
|
|
1740
1747
|
}));
|
|
1741
1748
|
}
|
|
1742
|
-
get_global().safe_async_call = safe_async_call;
|
|
1743
1749
|
var global_cache_map = {};
|
|
1744
|
-
function cache_fetch(
|
|
1745
|
-
return __awaiter(this,
|
|
1750
|
+
function cache_fetch(key_1, cb_1) {
|
|
1751
|
+
return __awaiter(this, arguments, void 0, function (key, cb) {
|
|
1752
|
+
var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1753
|
+
return /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
1754
|
+
var raw;
|
|
1755
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
1756
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1757
|
+
case 0:
|
|
1758
|
+
_context9.next = 2;
|
|
1759
|
+
return cache_fetch_inner(key, cb);
|
|
1760
|
+
case 2:
|
|
1761
|
+
raw = _context9.sent;
|
|
1762
|
+
return _context9.abrupt("return", deep ? cloneDeep(raw) : raw);
|
|
1763
|
+
case 4:
|
|
1764
|
+
case "end":
|
|
1765
|
+
return _context9.stop();
|
|
1766
|
+
}
|
|
1767
|
+
}, _callee9);
|
|
1768
|
+
})();
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
function cache_fetch_inner(key, cb) {
|
|
1772
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
1746
1773
|
var _a, conf;
|
|
1747
|
-
return _regeneratorRuntime.wrap(function
|
|
1748
|
-
while (1) switch (
|
|
1774
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
1775
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1749
1776
|
case 0:
|
|
1750
1777
|
conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
|
|
1751
1778
|
if (!conf.cache) {
|
|
1752
|
-
|
|
1779
|
+
_context10.next = 3;
|
|
1753
1780
|
break;
|
|
1754
1781
|
}
|
|
1755
|
-
return
|
|
1782
|
+
return _context10.abrupt("return", conf.cache);
|
|
1756
1783
|
case 3:
|
|
1757
1784
|
if (!conf.cache_promise) {
|
|
1758
|
-
|
|
1785
|
+
_context10.next = 5;
|
|
1759
1786
|
break;
|
|
1760
1787
|
}
|
|
1761
|
-
return
|
|
1788
|
+
return _context10.abrupt("return", conf.cache_promise);
|
|
1762
1789
|
case 5:
|
|
1763
|
-
return
|
|
1790
|
+
return _context10.abrupt("return", conf.cache_promise = cb().then(function (r) {
|
|
1764
1791
|
return conf.cache = r;
|
|
1765
1792
|
}));
|
|
1766
1793
|
case 6:
|
|
1767
1794
|
case "end":
|
|
1768
|
-
return
|
|
1795
|
+
return _context10.stop();
|
|
1769
1796
|
}
|
|
1770
|
-
},
|
|
1797
|
+
}, _callee10);
|
|
1771
1798
|
}));
|
|
1772
1799
|
}
|
|
1773
1800
|
function speculate_on_display(value) {
|
|
@@ -1832,19 +1859,29 @@ function simple_decrypt(code) {
|
|
|
1832
1859
|
}).join('');
|
|
1833
1860
|
return safe_json_parse(str);
|
|
1834
1861
|
}
|
|
1862
|
+
var SP = '@@';
|
|
1835
1863
|
function simple_encrypt_str(data) {
|
|
1864
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1836
1865
|
if (!data || !isString(data)) return null;
|
|
1837
1866
|
return data.split('').map(function (_, idx) {
|
|
1838
1867
|
return ~_.charCodeAt(0) + idx * 119;
|
|
1839
|
-
}).join(
|
|
1868
|
+
}).join(sp);
|
|
1840
1869
|
}
|
|
1841
1870
|
function simple_decrypt_str(code) {
|
|
1842
|
-
|
|
1843
|
-
|
|
1871
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1872
|
+
if (!code || !isString(code) || !code.includes(sp)) return null;
|
|
1873
|
+
var str = code.split(sp).map(function (_, idx) {
|
|
1844
1874
|
return String.fromCharCode(~(+_ - idx * 119));
|
|
1845
1875
|
}).join('');
|
|
1846
1876
|
return str;
|
|
1847
1877
|
}
|
|
1878
|
+
Object.assign(get_global(), {
|
|
1879
|
+
safe_async_call: safe_async_call,
|
|
1880
|
+
simple_decrypt_str: simple_decrypt_str,
|
|
1881
|
+
simple_encrypt_str: simple_encrypt_str
|
|
1882
|
+
});
|
|
1883
|
+
// safe_check()
|
|
1884
|
+
|
|
1848
1885
|
function getFn(format) {
|
|
1849
1886
|
function f(s) {
|
|
1850
1887
|
if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
|
|
@@ -1887,7 +1924,8 @@ function getMomentRange() {
|
|
|
1887
1924
|
// 这月: [start(m).startOf('month'), end(m).endOf('month')] as DT,
|
|
1888
1925
|
近一月: [start(m).add(-1, 'month').add(1, 'day'), end(m)],
|
|
1889
1926
|
下月: [start(m).add(1, 'month').startOf('month'), end(m).add(1, 'month').endOf('month')],
|
|
1890
|
-
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)]
|
|
1927
|
+
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)],
|
|
1928
|
+
年初至今: [start(m).startOf('year'), end(m)]
|
|
1891
1929
|
};
|
|
1892
1930
|
}
|
|
1893
1931
|
function presets_date() {
|
|
@@ -2375,24 +2413,6 @@ function presetInput(_label) {
|
|
|
2375
2413
|
label: _label
|
|
2376
2414
|
};
|
|
2377
2415
|
}
|
|
2378
|
-
function safe_fetch_options(cb) {
|
|
2379
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
2380
|
-
var arr;
|
|
2381
|
-
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
2382
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
2383
|
-
case 0:
|
|
2384
|
-
_context10.next = 2;
|
|
2385
|
-
return safe_async_call(cb);
|
|
2386
|
-
case 2:
|
|
2387
|
-
arr = _context10.sent;
|
|
2388
|
-
return _context10.abrupt("return", expect_array(arr));
|
|
2389
|
-
case 4:
|
|
2390
|
-
case "end":
|
|
2391
|
-
return _context10.stop();
|
|
2392
|
-
}
|
|
2393
|
-
}, _callee10);
|
|
2394
|
-
}));
|
|
2395
|
-
}
|
|
2396
2416
|
function getPresetOptions(key) {
|
|
2397
2417
|
var pure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2398
2418
|
var _a, _b;
|
|
@@ -2476,4 +2496,153 @@ function getDictionaryValue(type, label) {
|
|
|
2476
2496
|
function merge_dict(ops) {
|
|
2477
2497
|
Object.assign(dic_map, ops);
|
|
2478
2498
|
}
|
|
2479
|
-
|
|
2499
|
+
function create_load_src() {
|
|
2500
|
+
var cache = {};
|
|
2501
|
+
var head_el = document.getElementsByTagName("head")[0] || document.documentElement;
|
|
2502
|
+
function exec(options, node) {
|
|
2503
|
+
var opt;
|
|
2504
|
+
if (typeof options === "string") {
|
|
2505
|
+
opt = {
|
|
2506
|
+
url: options,
|
|
2507
|
+
debug: false
|
|
2508
|
+
};
|
|
2509
|
+
} else {
|
|
2510
|
+
opt = options;
|
|
2511
|
+
}
|
|
2512
|
+
var cacheId = opt.id || opt.url;
|
|
2513
|
+
var cacheEntry = cache[cacheId];
|
|
2514
|
+
if (cacheEntry) {
|
|
2515
|
+
if (!!opt.debug) {
|
|
2516
|
+
console.log("load-js: cache hit", cacheId);
|
|
2517
|
+
}
|
|
2518
|
+
return cacheEntry;
|
|
2519
|
+
} else if (opt.allowExternal !== false) {
|
|
2520
|
+
var el = getScriptById(opt.id) || getScriptByUrl(opt.url);
|
|
2521
|
+
if (el) {
|
|
2522
|
+
var promise = Promise.resolve(el);
|
|
2523
|
+
if (cacheId) {
|
|
2524
|
+
cache[cacheId] = promise;
|
|
2525
|
+
}
|
|
2526
|
+
return promise;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
if (!opt.url && !opt.text) {
|
|
2530
|
+
throw new Error("load-js: must provide a url or text to load");
|
|
2531
|
+
}
|
|
2532
|
+
var pending = (opt.url ? loadScript : runScript)(node, createEl(opt));
|
|
2533
|
+
if (cacheId && opt.cache !== false) {
|
|
2534
|
+
cache[cacheId] = pending;
|
|
2535
|
+
}
|
|
2536
|
+
return pending;
|
|
2537
|
+
}
|
|
2538
|
+
function runScript(head, el) {
|
|
2539
|
+
head.appendChild(el);
|
|
2540
|
+
return Promise.resolve(el);
|
|
2541
|
+
}
|
|
2542
|
+
function loadScript(head, el) {
|
|
2543
|
+
return new Promise(function (resolve, reject) {
|
|
2544
|
+
// Handle Script loading
|
|
2545
|
+
var done = false;
|
|
2546
|
+
// Attach handlers for all browsers.
|
|
2547
|
+
//
|
|
2548
|
+
// References:
|
|
2549
|
+
// http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
|
|
2550
|
+
// http://stevesouders.com/efws/script-onload.php
|
|
2551
|
+
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
|
|
2552
|
+
//
|
|
2553
|
+
//@ts-ignore
|
|
2554
|
+
el.onload = el.onreadystatechange = function () {
|
|
2555
|
+
//@ts-ignore
|
|
2556
|
+
if (!done && (!el.readyState || el.readyState === "loaded" || el.readyState === "complete")) {
|
|
2557
|
+
done = true;
|
|
2558
|
+
// Handle memory leak in IE
|
|
2559
|
+
//@ts-ignore
|
|
2560
|
+
el.onload = el.onreadystatechange = null;
|
|
2561
|
+
resolve(el);
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
el.onerror = reject;
|
|
2565
|
+
head.appendChild(el);
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
function createEl(opt) {
|
|
2569
|
+
var _a;
|
|
2570
|
+
if ((_a = opt.url) === null || _a === void 0 ? void 0 : _a.endsWith('css')) {
|
|
2571
|
+
return createLink(opt);
|
|
2572
|
+
}
|
|
2573
|
+
if (opt.type === 'text/css') {
|
|
2574
|
+
return createStyle(opt);
|
|
2575
|
+
}
|
|
2576
|
+
return createScript(opt);
|
|
2577
|
+
}
|
|
2578
|
+
function createScript(options) {
|
|
2579
|
+
var el = document.createElement("script");
|
|
2580
|
+
el.charset = options.charset || "utf-8";
|
|
2581
|
+
el.type = options.type || "text/javascript";
|
|
2582
|
+
el.async = !!options.async;
|
|
2583
|
+
el.id = options.id || options.url;
|
|
2584
|
+
//@ts-ignore
|
|
2585
|
+
el.loadJS = "watermark";
|
|
2586
|
+
if (options.url) {
|
|
2587
|
+
el.src = options.url;
|
|
2588
|
+
}
|
|
2589
|
+
if (options.text) {
|
|
2590
|
+
el.text = options.text;
|
|
2591
|
+
}
|
|
2592
|
+
return el;
|
|
2593
|
+
}
|
|
2594
|
+
function createLink(options) {
|
|
2595
|
+
var el = document.createElement("link");
|
|
2596
|
+
el.charset = options.charset || "utf-8";
|
|
2597
|
+
el.type = options.type || "text/css";
|
|
2598
|
+
el.id = options.id || options.url;
|
|
2599
|
+
el.rel = 'stylesheet';
|
|
2600
|
+
//@ts-ignore
|
|
2601
|
+
el.loadJS = "watermark";
|
|
2602
|
+
if (options.url) {
|
|
2603
|
+
el.href = options.url;
|
|
2604
|
+
}
|
|
2605
|
+
console.log('createLink', {
|
|
2606
|
+
options: options,
|
|
2607
|
+
el: el
|
|
2608
|
+
});
|
|
2609
|
+
return el;
|
|
2610
|
+
}
|
|
2611
|
+
function createStyle(options) {
|
|
2612
|
+
var el = document.createElement("style");
|
|
2613
|
+
el.id = options.id || options.text;
|
|
2614
|
+
//@ts-ignore
|
|
2615
|
+
el.loadJS = "watermark";
|
|
2616
|
+
if (options.text) {
|
|
2617
|
+
el.textContent = options.text;
|
|
2618
|
+
}
|
|
2619
|
+
return el;
|
|
2620
|
+
}
|
|
2621
|
+
function getScriptById(id) {
|
|
2622
|
+
var el = id && document.getElementById(id);
|
|
2623
|
+
//@ts-ignore
|
|
2624
|
+
if (el && el.loadJS !== "watermark") {
|
|
2625
|
+
console.warn("load-js: duplicate script with id:", id);
|
|
2626
|
+
return el;
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
function getScriptByUrl(url) {
|
|
2630
|
+
var el = url && document.querySelector("script[src='" + url + "']");
|
|
2631
|
+
//@ts-ignore
|
|
2632
|
+
if (el && el.loadJS !== "watermark") {
|
|
2633
|
+
console.warn("load-js: duplicate script with url:", url);
|
|
2634
|
+
return el;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
return function load(items) {
|
|
2638
|
+
var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : head_el;
|
|
2639
|
+
return items instanceof Array ? Promise.all(items.map(function (_) {
|
|
2640
|
+
return exec(_, node);
|
|
2641
|
+
})) : exec(items, node);
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
var load_src_ = create_load_src();
|
|
2645
|
+
function load_src(items, node) {
|
|
2646
|
+
return load_src_(items, node);
|
|
2647
|
+
}
|
|
2648
|
+
export { ARG_URS1_KEY, ARG_URS2_KEY, EMPTY_PLACEHOLDER, EventEmitter, MyLog, ROMAN_NUMERALS, TOKEN_KEY, all, alphabetical, _assign as assign, base64ToBinary, base64_to_image, boil, cache_fetch, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayjs_quarter, debounce, defer, diff, diff_between, downloadFile, draw, expect_array, filter_obj_to_url_search, first, flat, fork, formatDate, formatDateTime, formatDateTimeNoSecond, formatTime, gen_encoded_char_svg, get, getDictionaries, getDictionariesEnumerations, getDictionaryLabel, getDictionaryValue, getDualModeOptions, getFilledArray, getFuckTimeInterval, getFutureDate, getMomentObj, getMomentRange, getOptionLabel, getOptionValue, getPresetOptions, getSameOptions, getSearchParamsAll, getSearchParamsValue, getSimpleOptions, get_global, group, guard, hasOwn, identity, image_to_base64, inRange, intersects, invert, isArray, isBoolean, isDate, isEmpty, _isEqual as isEqual, isFloat, isFunction, isInt, isMoment, isNil, isNull, isNumber, isObject, isObjectLike, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, load_src, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, merge_dict, merge_preset_options, min, noop, numberLikeCompare, objectify, omit, optionKey不详, optionKey其他, optionKey否, parallel, partial, partob, pascal, pick, presets_date, proxied, random, randomHex, random_word, range, reduce, replace, replaceOrAppend, retry, safeExec, safeGetFromFuncOrData, safe_async_call, safe_json_parse, safe_json_parse_arr, safe_json_stringify, safe_number_parse, scrollIntoView, select, series, set, setSearchParamsAll, setSearchParamsValue, shake, shift, shuffle, sift, simple_decrypt, simple_decrypt_str, simple_encrypt, simple_encrypt_str, size, sleep, snake, sort, speculate_on_display, sum, template, throttle, title, toFloat, toInt, toString, toggle, trim, tryit as try, tryit, uid, unicodeToChar, unicode_to_UTF8, unique, upperize, uuid, warpBase64Type, zip, zipToObject };
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AnyObject } from "./type-utils";
|
|
1
2
|
export * from "radash";
|
|
2
3
|
export declare function get<T = any>(value: T, path: string, defaultValue?: T | undefined): T;
|
|
3
4
|
export declare function identity<T>(value: T): T;
|
|
@@ -8,3 +9,4 @@ export declare function size(value: any): number;
|
|
|
8
9
|
export declare function isNil(value: any): value is null | undefined;
|
|
9
10
|
export declare function toString(value: any): string;
|
|
10
11
|
export declare function cloneDeep<T>(value: T): T | null;
|
|
12
|
+
export declare function hasOwn(obj: AnyObject, key: PropertyKey): boolean;
|
package/dist/index.d.ts
CHANGED
package/dist/lib.js
CHANGED
|
@@ -1428,10 +1428,13 @@ function cloneDeep(value) {
|
|
|
1428
1428
|
return null;
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
|
+
function hasOwn(obj, key) {
|
|
1432
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1433
|
+
}
|
|
1431
1434
|
function safe_json_parse(str) {
|
|
1432
1435
|
var retOnErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1433
1436
|
if (!str) return retOnErr;
|
|
1434
|
-
if (
|
|
1437
|
+
if (isObject(str) || isArray(str)) return str;
|
|
1435
1438
|
if (!isString(str)) return retOnErr;
|
|
1436
1439
|
try {
|
|
1437
1440
|
var v = JSON.parse(str);
|
|
@@ -1510,7 +1513,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1510
1513
|
// }
|
|
1511
1514
|
function get_global() {
|
|
1512
1515
|
var _a;
|
|
1513
|
-
|
|
1516
|
+
try {
|
|
1517
|
+
return (_a = globalThis !== null && globalThis !== void 0 ? globalThis : window) !== null && _a !== void 0 ? _a : global;
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
return {};
|
|
1520
|
+
}
|
|
1514
1521
|
}
|
|
1515
1522
|
function getSearchParamsValue(key) {
|
|
1516
1523
|
var _a, _b;
|
|
@@ -1749,35 +1756,55 @@ function safe_async_call(cb) {
|
|
|
1749
1756
|
}, _callee8);
|
|
1750
1757
|
}));
|
|
1751
1758
|
}
|
|
1752
|
-
get_global().safe_async_call = safe_async_call;
|
|
1753
1759
|
var global_cache_map = {};
|
|
1754
|
-
function cache_fetch(
|
|
1755
|
-
return __awaiter(this,
|
|
1760
|
+
function cache_fetch(key_1, cb_1) {
|
|
1761
|
+
return __awaiter(this, arguments, void 0, function (key, cb) {
|
|
1762
|
+
var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1763
|
+
return /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
1764
|
+
var raw;
|
|
1765
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
1766
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1767
|
+
case 0:
|
|
1768
|
+
_context9.next = 2;
|
|
1769
|
+
return cache_fetch_inner(key, cb);
|
|
1770
|
+
case 2:
|
|
1771
|
+
raw = _context9.sent;
|
|
1772
|
+
return _context9.abrupt("return", deep ? cloneDeep(raw) : raw);
|
|
1773
|
+
case 4:
|
|
1774
|
+
case "end":
|
|
1775
|
+
return _context9.stop();
|
|
1776
|
+
}
|
|
1777
|
+
}, _callee9);
|
|
1778
|
+
})();
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
function cache_fetch_inner(key, cb) {
|
|
1782
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
1756
1783
|
var _a, conf;
|
|
1757
|
-
return _regeneratorRuntime.wrap(function
|
|
1758
|
-
while (1) switch (
|
|
1784
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
1785
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1759
1786
|
case 0:
|
|
1760
1787
|
conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
|
|
1761
1788
|
if (!conf.cache) {
|
|
1762
|
-
|
|
1789
|
+
_context10.next = 3;
|
|
1763
1790
|
break;
|
|
1764
1791
|
}
|
|
1765
|
-
return
|
|
1792
|
+
return _context10.abrupt("return", conf.cache);
|
|
1766
1793
|
case 3:
|
|
1767
1794
|
if (!conf.cache_promise) {
|
|
1768
|
-
|
|
1795
|
+
_context10.next = 5;
|
|
1769
1796
|
break;
|
|
1770
1797
|
}
|
|
1771
|
-
return
|
|
1798
|
+
return _context10.abrupt("return", conf.cache_promise);
|
|
1772
1799
|
case 5:
|
|
1773
|
-
return
|
|
1800
|
+
return _context10.abrupt("return", conf.cache_promise = cb().then(function (r) {
|
|
1774
1801
|
return conf.cache = r;
|
|
1775
1802
|
}));
|
|
1776
1803
|
case 6:
|
|
1777
1804
|
case "end":
|
|
1778
|
-
return
|
|
1805
|
+
return _context10.stop();
|
|
1779
1806
|
}
|
|
1780
|
-
},
|
|
1807
|
+
}, _callee10);
|
|
1781
1808
|
}));
|
|
1782
1809
|
}
|
|
1783
1810
|
function speculate_on_display(value) {
|
|
@@ -1842,19 +1869,29 @@ function simple_decrypt(code) {
|
|
|
1842
1869
|
}).join('');
|
|
1843
1870
|
return safe_json_parse(str);
|
|
1844
1871
|
}
|
|
1872
|
+
var SP = '@@';
|
|
1845
1873
|
function simple_encrypt_str(data) {
|
|
1874
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1846
1875
|
if (!data || !isString(data)) return null;
|
|
1847
1876
|
return data.split('').map(function (_, idx) {
|
|
1848
1877
|
return ~_.charCodeAt(0) + idx * 119;
|
|
1849
|
-
}).join(
|
|
1878
|
+
}).join(sp);
|
|
1850
1879
|
}
|
|
1851
1880
|
function simple_decrypt_str(code) {
|
|
1852
|
-
|
|
1853
|
-
|
|
1881
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1882
|
+
if (!code || !isString(code) || !code.includes(sp)) return null;
|
|
1883
|
+
var str = code.split(sp).map(function (_, idx) {
|
|
1854
1884
|
return String.fromCharCode(~(+_ - idx * 119));
|
|
1855
1885
|
}).join('');
|
|
1856
1886
|
return str;
|
|
1857
1887
|
}
|
|
1888
|
+
Object.assign(get_global(), {
|
|
1889
|
+
safe_async_call: safe_async_call,
|
|
1890
|
+
simple_decrypt_str: simple_decrypt_str,
|
|
1891
|
+
simple_encrypt_str: simple_encrypt_str
|
|
1892
|
+
});
|
|
1893
|
+
// safe_check()
|
|
1894
|
+
|
|
1858
1895
|
function getFn(format) {
|
|
1859
1896
|
function f(s) {
|
|
1860
1897
|
if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
|
|
@@ -1897,7 +1934,8 @@ function getMomentRange() {
|
|
|
1897
1934
|
// 这月: [start(m).startOf('month'), end(m).endOf('month')] as DT,
|
|
1898
1935
|
近一月: [start(m).add(-1, 'month').add(1, 'day'), end(m)],
|
|
1899
1936
|
下月: [start(m).add(1, 'month').startOf('month'), end(m).add(1, 'month').endOf('month')],
|
|
1900
|
-
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)]
|
|
1937
|
+
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)],
|
|
1938
|
+
年初至今: [start(m).startOf('year'), end(m)]
|
|
1901
1939
|
};
|
|
1902
1940
|
}
|
|
1903
1941
|
function presets_date() {
|
|
@@ -2385,24 +2423,6 @@ function presetInput(_label) {
|
|
|
2385
2423
|
label: _label
|
|
2386
2424
|
};
|
|
2387
2425
|
}
|
|
2388
|
-
function safe_fetch_options(cb) {
|
|
2389
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
2390
|
-
var arr;
|
|
2391
|
-
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
2392
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
2393
|
-
case 0:
|
|
2394
|
-
_context10.next = 2;
|
|
2395
|
-
return safe_async_call(cb);
|
|
2396
|
-
case 2:
|
|
2397
|
-
arr = _context10.sent;
|
|
2398
|
-
return _context10.abrupt("return", expect_array(arr));
|
|
2399
|
-
case 4:
|
|
2400
|
-
case "end":
|
|
2401
|
-
return _context10.stop();
|
|
2402
|
-
}
|
|
2403
|
-
}, _callee10);
|
|
2404
|
-
}));
|
|
2405
|
-
}
|
|
2406
2426
|
function getPresetOptions(key) {
|
|
2407
2427
|
var pure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2408
2428
|
var _a, _b;
|
|
@@ -2486,6 +2506,155 @@ function getDictionaryValue(type, label) {
|
|
|
2486
2506
|
function merge_dict(ops) {
|
|
2487
2507
|
Object.assign(dic_map, ops);
|
|
2488
2508
|
}
|
|
2509
|
+
function create_load_src() {
|
|
2510
|
+
var cache = {};
|
|
2511
|
+
var head_el = document.getElementsByTagName("head")[0] || document.documentElement;
|
|
2512
|
+
function exec(options, node) {
|
|
2513
|
+
var opt;
|
|
2514
|
+
if (typeof options === "string") {
|
|
2515
|
+
opt = {
|
|
2516
|
+
url: options,
|
|
2517
|
+
debug: false
|
|
2518
|
+
};
|
|
2519
|
+
} else {
|
|
2520
|
+
opt = options;
|
|
2521
|
+
}
|
|
2522
|
+
var cacheId = opt.id || opt.url;
|
|
2523
|
+
var cacheEntry = cache[cacheId];
|
|
2524
|
+
if (cacheEntry) {
|
|
2525
|
+
if (!!opt.debug) {
|
|
2526
|
+
console.log("load-js: cache hit", cacheId);
|
|
2527
|
+
}
|
|
2528
|
+
return cacheEntry;
|
|
2529
|
+
} else if (opt.allowExternal !== false) {
|
|
2530
|
+
var el = getScriptById(opt.id) || getScriptByUrl(opt.url);
|
|
2531
|
+
if (el) {
|
|
2532
|
+
var promise = Promise.resolve(el);
|
|
2533
|
+
if (cacheId) {
|
|
2534
|
+
cache[cacheId] = promise;
|
|
2535
|
+
}
|
|
2536
|
+
return promise;
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
if (!opt.url && !opt.text) {
|
|
2540
|
+
throw new Error("load-js: must provide a url or text to load");
|
|
2541
|
+
}
|
|
2542
|
+
var pending = (opt.url ? loadScript : runScript)(node, createEl(opt));
|
|
2543
|
+
if (cacheId && opt.cache !== false) {
|
|
2544
|
+
cache[cacheId] = pending;
|
|
2545
|
+
}
|
|
2546
|
+
return pending;
|
|
2547
|
+
}
|
|
2548
|
+
function runScript(head, el) {
|
|
2549
|
+
head.appendChild(el);
|
|
2550
|
+
return Promise.resolve(el);
|
|
2551
|
+
}
|
|
2552
|
+
function loadScript(head, el) {
|
|
2553
|
+
return new Promise(function (resolve, reject) {
|
|
2554
|
+
// Handle Script loading
|
|
2555
|
+
var done = false;
|
|
2556
|
+
// Attach handlers for all browsers.
|
|
2557
|
+
//
|
|
2558
|
+
// References:
|
|
2559
|
+
// http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
|
|
2560
|
+
// http://stevesouders.com/efws/script-onload.php
|
|
2561
|
+
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
|
|
2562
|
+
//
|
|
2563
|
+
//@ts-ignore
|
|
2564
|
+
el.onload = el.onreadystatechange = function () {
|
|
2565
|
+
//@ts-ignore
|
|
2566
|
+
if (!done && (!el.readyState || el.readyState === "loaded" || el.readyState === "complete")) {
|
|
2567
|
+
done = true;
|
|
2568
|
+
// Handle memory leak in IE
|
|
2569
|
+
//@ts-ignore
|
|
2570
|
+
el.onload = el.onreadystatechange = null;
|
|
2571
|
+
resolve(el);
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
el.onerror = reject;
|
|
2575
|
+
head.appendChild(el);
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
function createEl(opt) {
|
|
2579
|
+
var _a;
|
|
2580
|
+
if ((_a = opt.url) === null || _a === void 0 ? void 0 : _a.endsWith('css')) {
|
|
2581
|
+
return createLink(opt);
|
|
2582
|
+
}
|
|
2583
|
+
if (opt.type === 'text/css') {
|
|
2584
|
+
return createStyle(opt);
|
|
2585
|
+
}
|
|
2586
|
+
return createScript(opt);
|
|
2587
|
+
}
|
|
2588
|
+
function createScript(options) {
|
|
2589
|
+
var el = document.createElement("script");
|
|
2590
|
+
el.charset = options.charset || "utf-8";
|
|
2591
|
+
el.type = options.type || "text/javascript";
|
|
2592
|
+
el.async = !!options.async;
|
|
2593
|
+
el.id = options.id || options.url;
|
|
2594
|
+
//@ts-ignore
|
|
2595
|
+
el.loadJS = "watermark";
|
|
2596
|
+
if (options.url) {
|
|
2597
|
+
el.src = options.url;
|
|
2598
|
+
}
|
|
2599
|
+
if (options.text) {
|
|
2600
|
+
el.text = options.text;
|
|
2601
|
+
}
|
|
2602
|
+
return el;
|
|
2603
|
+
}
|
|
2604
|
+
function createLink(options) {
|
|
2605
|
+
var el = document.createElement("link");
|
|
2606
|
+
el.charset = options.charset || "utf-8";
|
|
2607
|
+
el.type = options.type || "text/css";
|
|
2608
|
+
el.id = options.id || options.url;
|
|
2609
|
+
el.rel = 'stylesheet';
|
|
2610
|
+
//@ts-ignore
|
|
2611
|
+
el.loadJS = "watermark";
|
|
2612
|
+
if (options.url) {
|
|
2613
|
+
el.href = options.url;
|
|
2614
|
+
}
|
|
2615
|
+
console.log('createLink', {
|
|
2616
|
+
options: options,
|
|
2617
|
+
el: el
|
|
2618
|
+
});
|
|
2619
|
+
return el;
|
|
2620
|
+
}
|
|
2621
|
+
function createStyle(options) {
|
|
2622
|
+
var el = document.createElement("style");
|
|
2623
|
+
el.id = options.id || options.text;
|
|
2624
|
+
//@ts-ignore
|
|
2625
|
+
el.loadJS = "watermark";
|
|
2626
|
+
if (options.text) {
|
|
2627
|
+
el.textContent = options.text;
|
|
2628
|
+
}
|
|
2629
|
+
return el;
|
|
2630
|
+
}
|
|
2631
|
+
function getScriptById(id) {
|
|
2632
|
+
var el = id && document.getElementById(id);
|
|
2633
|
+
//@ts-ignore
|
|
2634
|
+
if (el && el.loadJS !== "watermark") {
|
|
2635
|
+
console.warn("load-js: duplicate script with id:", id);
|
|
2636
|
+
return el;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
function getScriptByUrl(url) {
|
|
2640
|
+
var el = url && document.querySelector("script[src='" + url + "']");
|
|
2641
|
+
//@ts-ignore
|
|
2642
|
+
if (el && el.loadJS !== "watermark") {
|
|
2643
|
+
console.warn("load-js: duplicate script with url:", url);
|
|
2644
|
+
return el;
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
return function load(items) {
|
|
2648
|
+
var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : head_el;
|
|
2649
|
+
return items instanceof Array ? Promise.all(items.map(function (_) {
|
|
2650
|
+
return exec(_, node);
|
|
2651
|
+
})) : exec(items, node);
|
|
2652
|
+
};
|
|
2653
|
+
}
|
|
2654
|
+
var load_src_ = create_load_src();
|
|
2655
|
+
function load_src(items, node) {
|
|
2656
|
+
return load_src_(items, node);
|
|
2657
|
+
}
|
|
2489
2658
|
Object.defineProperty(exports, 'dayjs', {
|
|
2490
2659
|
enumerable: true,
|
|
2491
2660
|
get: function get() {
|
|
@@ -2520,6 +2689,7 @@ exports.confirm_operation = confirm_operation;
|
|
|
2520
2689
|
exports.construct = construct;
|
|
2521
2690
|
exports.copyText = copyText;
|
|
2522
2691
|
exports.counting = counting;
|
|
2692
|
+
exports.create_load_src = create_load_src;
|
|
2523
2693
|
exports.crush = crush;
|
|
2524
2694
|
exports.dash = dash;
|
|
2525
2695
|
exports.dayjs_quarter = dayjs_quarter;
|
|
@@ -2560,6 +2730,7 @@ exports.getSimpleOptions = getSimpleOptions;
|
|
|
2560
2730
|
exports.get_global = get_global;
|
|
2561
2731
|
exports.group = group;
|
|
2562
2732
|
exports.guard = guard;
|
|
2733
|
+
exports.hasOwn = hasOwn;
|
|
2563
2734
|
exports.identity = identity;
|
|
2564
2735
|
exports.image_to_base64 = image_to_base64;
|
|
2565
2736
|
exports.inRange = inRange;
|
|
@@ -2588,6 +2759,7 @@ exports.keys = keys;
|
|
|
2588
2759
|
exports.last = last;
|
|
2589
2760
|
exports.list = list;
|
|
2590
2761
|
exports.listify = listify;
|
|
2762
|
+
exports.load_src = load_src;
|
|
2591
2763
|
exports.lowerize = lowerize;
|
|
2592
2764
|
exports.map = map;
|
|
2593
2765
|
exports.mapEntries = mapEntries;
|
|
@@ -2624,7 +2796,6 @@ exports.retry = retry;
|
|
|
2624
2796
|
exports.safeExec = safeExec;
|
|
2625
2797
|
exports.safeGetFromFuncOrData = safeGetFromFuncOrData;
|
|
2626
2798
|
exports.safe_async_call = safe_async_call;
|
|
2627
|
-
exports.safe_fetch_options = safe_fetch_options;
|
|
2628
2799
|
exports.safe_json_parse = safe_json_parse;
|
|
2629
2800
|
exports.safe_json_parse_arr = safe_json_parse_arr;
|
|
2630
2801
|
exports.safe_json_stringify = safe_json_stringify;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface IOpt {
|
|
2
|
+
id?: string;
|
|
3
|
+
text?: string;
|
|
4
|
+
url?: string;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
allowExternal?: boolean;
|
|
7
|
+
cache?: boolean;
|
|
8
|
+
async?: boolean;
|
|
9
|
+
type?: 'text/css' | 'text/javascript';
|
|
10
|
+
charset?: string;
|
|
11
|
+
}
|
|
12
|
+
type TMixOpt = IOpt | string;
|
|
13
|
+
export declare function create_load_src(): (items: TMixOpt | TMixOpt[], node?: HTMLHeadElement) => Promise<Element> | Promise<Element[]>;
|
|
14
|
+
export declare function load_src(items: TMixOpt, node?: HTMLHeadElement): Promise<Element>;
|
|
15
|
+
export declare function load_src(items: TMixOpt[], node?: HTMLHeadElement): Promise<Element[]>;
|
|
16
|
+
export {};
|
package/dist/moment-help.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare function getMomentRange(m?: any): {
|
|
|
25
25
|
近一月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
26
26
|
下月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
27
27
|
近一年: [dayjs.Dayjs, dayjs.Dayjs];
|
|
28
|
+
年初至今: [dayjs.Dayjs, dayjs.Dayjs];
|
|
28
29
|
};
|
|
29
30
|
export declare function presets_date(): {
|
|
30
31
|
label: string;
|
package/dist/option-help.d.ts
CHANGED
|
@@ -15,8 +15,6 @@ type TOptions<T extends TOptionKey | TGetOptionKey> = T extends TOptionKey ? ICo
|
|
|
15
15
|
export declare function getSimpleOptions<T extends TOptionKey | TGetOptionKey>(_arr: T, options?: ISpectialOption): TOptions<T>;
|
|
16
16
|
export declare function getSameOptions<T extends TOptionKey | TGetOptionKey>(_arr: T): TOptions<T>;
|
|
17
17
|
export declare function getDualModeOptions<T extends TOptionKey | TGetOptionKey>(arr: T, options?: ISpectialOption): readonly [TOptions<T>, TOptions<T>];
|
|
18
|
-
export type T_FETCH_OPTIONS = () => (Promise<ICommonOption[]> | ICommonOption[]);
|
|
19
|
-
export declare function safe_fetch_options(cb: T_FETCH_OPTIONS): Promise<ICommonOption[]>;
|
|
20
18
|
export declare function getPresetOptions(key: string, pure?: boolean): ICommonOption[];
|
|
21
19
|
export declare function getOptionLabel(k: string, value: any, defaultLabel?: string): string;
|
|
22
20
|
export declare function getOptionValue(k: string, label: any): any;
|
package/dist/small-fn.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyObject } from "./type-utils";
|
|
2
2
|
export type TCommonFileType = 'application/vnd.ms-excel' | 'text/csv;charset=utf-8' | 'application/msword';
|
|
3
|
-
export declare function get_global():
|
|
3
|
+
export declare function get_global(): typeof globalThis;
|
|
4
4
|
export declare function getSearchParamsValue(key: string): string | null;
|
|
5
5
|
export declare function getSearchParamsAll(url?: URL): AnyObject<string>;
|
|
6
6
|
export declare function setSearchParamsValue(key: string, value: string | number): URL;
|
|
@@ -18,7 +18,7 @@ export declare function getFilledArray(n: number): any[];
|
|
|
18
18
|
export declare function copyText(text: string): boolean;
|
|
19
19
|
export declare function safeExec<T extends (...args: any) => any>(fn?: T, ...args: Parameters<T>): any;
|
|
20
20
|
export declare function safeGetFromFuncOrData(fn: any): any;
|
|
21
|
-
export declare function numberLikeCompare(a: number | string | boolean, b: number | string | boolean): boolean;
|
|
21
|
+
export declare function numberLikeCompare(a: number | string | boolean | null, b: number | string | boolean | null): boolean;
|
|
22
22
|
export declare function warpBase64Type(str: string, type: 'img' | 'pdf'): string;
|
|
23
23
|
export declare function safe_number_parse(value: any, defaultValue?: number): number;
|
|
24
24
|
export declare function expect_array<T>(value?: T[] | null, default_v?: T[]): T[];
|
|
@@ -30,13 +30,13 @@ export declare function gen_encoded_char_svg(props: {
|
|
|
30
30
|
export declare function base64_to_image(base64img: string): Promise<HTMLImageElement | null>;
|
|
31
31
|
export declare function image_to_base64(img_el: HTMLImageElement): string | null;
|
|
32
32
|
export declare function filter_obj_to_url_search(obj: Object | any[]): any;
|
|
33
|
-
export declare function safe_async_call<T extends (...args: any) => any>(cb
|
|
34
|
-
export declare function cache_fetch<T = any>(key: string, cb: () => Promise<T
|
|
33
|
+
export declare function safe_async_call<T extends (...args: any) => any>(cb?: T, ...args: Parameters<T>): Promise<ReturnType<T> | null>;
|
|
34
|
+
export declare function cache_fetch<T = any>(key: string, cb: () => Promise<T>, deep?: boolean): Promise<T>;
|
|
35
35
|
export declare function speculate_on_display(value?: any): string;
|
|
36
36
|
export declare function getFuckTimeInterval(star_hour?: number, end_hour?: number, min_interval?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 20 | 30): string[];
|
|
37
37
|
export declare function random_word(): string[];
|
|
38
38
|
export declare function confirm_operation(): boolean;
|
|
39
39
|
export declare function simple_encrypt(data: AnyObject | any[]): number[] | null;
|
|
40
40
|
export declare function simple_decrypt(code: number[]): AnyObject | null;
|
|
41
|
-
export declare function simple_encrypt_str(data: string): string | null;
|
|
42
|
-
export declare function simple_decrypt_str(code: string): string | null;
|
|
41
|
+
export declare function simple_encrypt_str(data: string, sp?: string): string | null;
|
|
42
|
+
export declare function simple_decrypt_str(code: string, sp?: string): string | null;
|
package/dist/type-utils.d.ts
CHANGED
package/dist/typing.d.ts
CHANGED
|
@@ -17,6 +17,17 @@ interface ICommonOption {
|
|
|
17
17
|
code?: any;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
type PropertyKey$1 = string | number | symbol;
|
|
21
|
+
type PartialAll<T> = {
|
|
22
|
+
[P in keyof T]?: T[P] extends Array<any> ? Partial<T[P][number]>[] : Partial<T[P]>;
|
|
23
|
+
};
|
|
24
|
+
type PartialSome<T, K extends keyof T> = {
|
|
25
|
+
[P in K]?: T[P];
|
|
26
|
+
} & Pick<T, Exclude<keyof T, K>>;
|
|
27
|
+
type AnyObject<T = any> = {
|
|
28
|
+
[x: string]: T;
|
|
29
|
+
};
|
|
30
|
+
|
|
20
31
|
/**
|
|
21
32
|
* Sorts an array of items into groups. The return value is a map where the keys are
|
|
22
33
|
* the group ids the given getGroupId function produced and the value is an array of
|
|
@@ -700,23 +711,14 @@ declare function size(value: any): number;
|
|
|
700
711
|
declare function isNil(value: any): value is null | undefined;
|
|
701
712
|
declare function toString(value: any): string;
|
|
702
713
|
declare function cloneDeep<T>(value: T): T | null;
|
|
714
|
+
declare function hasOwn(obj: AnyObject, key: PropertyKey): boolean;
|
|
703
715
|
|
|
704
716
|
declare function safe_json_parse<T = any>(str?: any, retOnErr?: T | null): T | null;
|
|
705
717
|
declare function safe_json_stringify(obj?: any): string;
|
|
706
718
|
declare function safe_json_parse_arr<T = any>(str?: any, retOnErr?: T[]): T[];
|
|
707
719
|
|
|
708
|
-
type PartialAll<T> = {
|
|
709
|
-
[P in keyof T]?: T[P] extends Array<any> ? Partial<T[P][number]>[] : Partial<T[P]>;
|
|
710
|
-
};
|
|
711
|
-
type PartialSome<T, K extends keyof T> = {
|
|
712
|
-
[P in K]?: T[P];
|
|
713
|
-
} & Pick<T, Exclude<keyof T, K>>;
|
|
714
|
-
type AnyObject<T = any> = {
|
|
715
|
-
[x: string]: T;
|
|
716
|
-
};
|
|
717
|
-
|
|
718
720
|
type TCommonFileType = 'application/vnd.ms-excel' | 'text/csv;charset=utf-8' | 'application/msword';
|
|
719
|
-
declare function get_global():
|
|
721
|
+
declare function get_global(): typeof globalThis;
|
|
720
722
|
declare function getSearchParamsValue(key: string): string | null;
|
|
721
723
|
declare function getSearchParamsAll(url?: URL): AnyObject<string>;
|
|
722
724
|
declare function setSearchParamsValue(key: string, value: string | number): URL;
|
|
@@ -734,7 +736,7 @@ declare function getFilledArray(n: number): any[];
|
|
|
734
736
|
declare function copyText(text: string): boolean;
|
|
735
737
|
declare function safeExec<T extends (...args: any) => any>(fn?: T, ...args: Parameters<T>): any;
|
|
736
738
|
declare function safeGetFromFuncOrData(fn: any): any;
|
|
737
|
-
declare function numberLikeCompare(a: number | string | boolean, b: number | string | boolean): boolean;
|
|
739
|
+
declare function numberLikeCompare(a: number | string | boolean | null, b: number | string | boolean | null): boolean;
|
|
738
740
|
declare function warpBase64Type(str: string, type: 'img' | 'pdf'): string;
|
|
739
741
|
declare function safe_number_parse(value: any, defaultValue?: number): number;
|
|
740
742
|
declare function expect_array<T>(value?: T[] | null, default_v?: T[]): T[];
|
|
@@ -746,16 +748,16 @@ declare function gen_encoded_char_svg(props: {
|
|
|
746
748
|
declare function base64_to_image(base64img: string): Promise<HTMLImageElement | null>;
|
|
747
749
|
declare function image_to_base64(img_el: HTMLImageElement): string | null;
|
|
748
750
|
declare function filter_obj_to_url_search(obj: Object | any[]): any;
|
|
749
|
-
declare function safe_async_call<T extends (...args: any) => any>(cb
|
|
750
|
-
declare function cache_fetch<T = any>(key: string, cb: () => Promise<T
|
|
751
|
+
declare function safe_async_call<T extends (...args: any) => any>(cb?: T, ...args: Parameters<T>): Promise<ReturnType<T> | null>;
|
|
752
|
+
declare function cache_fetch<T = any>(key: string, cb: () => Promise<T>, deep?: boolean): Promise<T>;
|
|
751
753
|
declare function speculate_on_display(value?: any): string;
|
|
752
754
|
declare function getFuckTimeInterval(star_hour?: number, end_hour?: number, min_interval?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 20 | 30): string[];
|
|
753
755
|
declare function random_word(): string[];
|
|
754
756
|
declare function confirm_operation(): boolean;
|
|
755
757
|
declare function simple_encrypt(data: AnyObject | any[]): number[] | null;
|
|
756
758
|
declare function simple_decrypt(code: number[]): AnyObject | null;
|
|
757
|
-
declare function simple_encrypt_str(data: string): string | null;
|
|
758
|
-
declare function simple_decrypt_str(code: string): string | null;
|
|
759
|
+
declare function simple_encrypt_str(data: string, sp?: string): string | null;
|
|
760
|
+
declare function simple_decrypt_str(code: string, sp?: string): string | null;
|
|
759
761
|
|
|
760
762
|
interface ILL {
|
|
761
763
|
log?(...optionalParams: any[]): void;
|
|
@@ -845,6 +847,7 @@ declare function getMomentRange(m?: any): {
|
|
|
845
847
|
近一月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
846
848
|
下月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
847
849
|
近一年: [dayjs.Dayjs, dayjs.Dayjs];
|
|
850
|
+
年初至今: [dayjs.Dayjs, dayjs.Dayjs];
|
|
848
851
|
};
|
|
849
852
|
declare function presets_date(): {
|
|
850
853
|
label: string;
|
|
@@ -873,8 +876,6 @@ type TOptions<T extends TOptionKey | TGetOptionKey> = T extends TOptionKey ? ICo
|
|
|
873
876
|
declare function getSimpleOptions<T extends TOptionKey | TGetOptionKey>(_arr: T, options?: ISpectialOption): TOptions<T>;
|
|
874
877
|
declare function getSameOptions<T extends TOptionKey | TGetOptionKey>(_arr: T): TOptions<T>;
|
|
875
878
|
declare function getDualModeOptions<T extends TOptionKey | TGetOptionKey>(arr: T, options?: ISpectialOption): readonly [TOptions<T>, TOptions<T>];
|
|
876
|
-
type T_FETCH_OPTIONS = () => (Promise<ICommonOption[]> | ICommonOption[]);
|
|
877
|
-
declare function safe_fetch_options(cb: T_FETCH_OPTIONS): Promise<ICommonOption[]>;
|
|
878
879
|
declare function getPresetOptions(key: string, pure?: boolean): ICommonOption[];
|
|
879
880
|
declare function getOptionLabel(k: string, value: any, defaultLabel?: string): string;
|
|
880
881
|
declare function getOptionValue(k: string, label: any): any;
|
|
@@ -916,5 +917,21 @@ declare function getDictionaryLabel(type: string, value: string | number): strin
|
|
|
916
917
|
declare function getDictionaryValue(type: string, label: string): number | null | undefined;
|
|
917
918
|
declare function merge_dict(ops: AnyObject<IDictionary>): void;
|
|
918
919
|
|
|
919
|
-
|
|
920
|
-
|
|
920
|
+
interface IOpt {
|
|
921
|
+
id?: string;
|
|
922
|
+
text?: string;
|
|
923
|
+
url?: string;
|
|
924
|
+
debug?: boolean;
|
|
925
|
+
allowExternal?: boolean;
|
|
926
|
+
cache?: boolean;
|
|
927
|
+
async?: boolean;
|
|
928
|
+
type?: 'text/css' | 'text/javascript';
|
|
929
|
+
charset?: string;
|
|
930
|
+
}
|
|
931
|
+
type TMixOpt = IOpt | string;
|
|
932
|
+
declare function create_load_src(): (items: TMixOpt | TMixOpt[], node?: HTMLHeadElement) => Promise<Element> | Promise<Element[]>;
|
|
933
|
+
declare function load_src(items: TMixOpt, node?: HTMLHeadElement): Promise<Element>;
|
|
934
|
+
declare function load_src(items: TMixOpt[], node?: HTMLHeadElement): Promise<Element[]>;
|
|
935
|
+
|
|
936
|
+
export { ARG_URS1_KEY, ARG_URS2_KEY, AggregateError, EMPTY_PLACEHOLDER, EventEmitter, MyLog, ROMAN_NUMERALS, TOKEN_KEY, all, alphabetical, assign, base64ToBinary, base64_to_image, boil, cache_fetch, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayjs_quarter, debounce, defer, diff, diff_between, downloadFile, draw, expect_array, filter_obj_to_url_search, first, flat, fork, formatDate, formatDateTime, formatDateTimeNoSecond, formatTime, gen_encoded_char_svg, get, getDictionaries, getDictionariesEnumerations, getDictionaryLabel, getDictionaryValue, getDualModeOptions, getFilledArray, getFuckTimeInterval, getFutureDate, getMomentObj, getMomentRange, getOptionLabel, getOptionValue, getPresetOptions, getSameOptions, getSearchParamsAll, getSearchParamsValue, getSimpleOptions, get_global, group, guard, hasOwn, identity, image_to_base64, inRange, intersects, invert, isArray, isBoolean, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isMoment, isNil, isNull, isNumber, isObject, isObjectLike, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, load_src, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, merge_dict, merge_preset_options, min, noop, numberLikeCompare, objectify, omit, optionKey不详, optionKey其他, optionKey否, parallel, partial, partob, pascal, pick, presets_date, proxied, random, randomHex, random_word, range, reduce, replace, replaceOrAppend, retry, safeExec, safeGetFromFuncOrData, safe_async_call, safe_json_parse, safe_json_parse_arr, safe_json_stringify, safe_number_parse, scrollIntoView, select, series, set, setSearchParamsAll, setSearchParamsValue, shake, shift, shuffle, sift, simple_decrypt, simple_decrypt_str, simple_encrypt, simple_encrypt_str, size, sleep, snake, sort, speculate_on_display, sum, template, throttle, title, toFloat, toInt, toString, toggle, trim, tryit as try, tryit, uid, unicodeToChar, unicode_to_UTF8, unique, upperize, uuid, warpBase64Type, zip, zipToObject };
|
|
937
|
+
export type { AnyObject, Dayjs, DayjsConfigType, ICommonOption, PartialAll, PartialSome, PropertyKey$1 as PropertyKey, TCommonFileType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noah-libjs/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"keywords": [],
|
|
35
35
|
"author": "",
|
|
36
36
|
"license": "MIT",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a50958bb900a9e145a8a722b69c639cac93d2094"
|
|
38
38
|
}
|