@noah-libjs/utils 0.0.7 → 0.0.9
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 +234 -40
- package/dist/helper.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib.js +238 -40
- package/dist/load-src.d.ts +16 -0
- package/dist/moment-help.d.ts +2 -1
- package/dist/option-help.d.ts +0 -2
- package/dist/small-fn.d.ts +8 -6
- package/dist/type-utils.d.ts +1 -0
- package/dist/typing.d.ts +40 -21
- 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);
|
|
@@ -1629,6 +1632,17 @@ function copyText(text) {
|
|
|
1629
1632
|
document.body.removeChild(textareaC);
|
|
1630
1633
|
return res;
|
|
1631
1634
|
}
|
|
1635
|
+
function dyn_cb(cb, g_ctx) {
|
|
1636
|
+
try {
|
|
1637
|
+
cb(g_ctx());
|
|
1638
|
+
return false;
|
|
1639
|
+
} catch (error) {
|
|
1640
|
+
console.error('dyn_cb', {
|
|
1641
|
+
error: error
|
|
1642
|
+
});
|
|
1643
|
+
return true;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1632
1646
|
function safeExec(fn) {
|
|
1633
1647
|
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
|
1634
1648
|
args[_key8 - 1] = arguments[_key8];
|
|
@@ -1636,8 +1650,14 @@ function safeExec(fn) {
|
|
|
1636
1650
|
return isFunction(fn) ? fn.apply(void 0, args) : null;
|
|
1637
1651
|
}
|
|
1638
1652
|
function safeGetFromFuncOrData(fn) {
|
|
1653
|
+
var default_v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1639
1654
|
var _a;
|
|
1640
|
-
|
|
1655
|
+
try {
|
|
1656
|
+
return (_a = safeExec(fn)) !== null && _a !== void 0 ? _a : fn;
|
|
1657
|
+
} catch (error) {
|
|
1658
|
+
if (default_v) return default_v;
|
|
1659
|
+
throw error;
|
|
1660
|
+
}
|
|
1641
1661
|
}
|
|
1642
1662
|
function numberLikeCompare(a, b) {
|
|
1643
1663
|
if (a === b) return true;
|
|
@@ -1743,46 +1763,73 @@ function safe_async_call(cb) {
|
|
|
1743
1763
|
}, _callee8);
|
|
1744
1764
|
}));
|
|
1745
1765
|
}
|
|
1746
|
-
get_global().safe_async_call = safe_async_call;
|
|
1747
1766
|
var global_cache_map = {};
|
|
1748
|
-
function cache_fetch(
|
|
1749
|
-
return __awaiter(this,
|
|
1767
|
+
function cache_fetch(key_1, cb_1) {
|
|
1768
|
+
return __awaiter(this, arguments, void 0, function (key, cb) {
|
|
1769
|
+
var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1770
|
+
return /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
1771
|
+
var raw;
|
|
1772
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
1773
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1774
|
+
case 0:
|
|
1775
|
+
_context9.next = 2;
|
|
1776
|
+
return cache_fetch_inner(key, cb);
|
|
1777
|
+
case 2:
|
|
1778
|
+
raw = _context9.sent;
|
|
1779
|
+
return _context9.abrupt("return", deep ? cloneDeep(raw) : raw);
|
|
1780
|
+
case 4:
|
|
1781
|
+
case "end":
|
|
1782
|
+
return _context9.stop();
|
|
1783
|
+
}
|
|
1784
|
+
}, _callee9);
|
|
1785
|
+
})();
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
function cache_fetch_inner(key, cb) {
|
|
1789
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
1750
1790
|
var _a, conf;
|
|
1751
|
-
return _regeneratorRuntime.wrap(function
|
|
1752
|
-
while (1) switch (
|
|
1791
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
1792
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1753
1793
|
case 0:
|
|
1754
1794
|
conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
|
|
1755
1795
|
if (!conf.cache) {
|
|
1756
|
-
|
|
1796
|
+
_context10.next = 3;
|
|
1757
1797
|
break;
|
|
1758
1798
|
}
|
|
1759
|
-
return
|
|
1799
|
+
return _context10.abrupt("return", conf.cache);
|
|
1760
1800
|
case 3:
|
|
1761
1801
|
if (!conf.cache_promise) {
|
|
1762
|
-
|
|
1802
|
+
_context10.next = 5;
|
|
1763
1803
|
break;
|
|
1764
1804
|
}
|
|
1765
|
-
return
|
|
1805
|
+
return _context10.abrupt("return", conf.cache_promise);
|
|
1766
1806
|
case 5:
|
|
1767
|
-
return
|
|
1807
|
+
return _context10.abrupt("return", conf.cache_promise = cb().then(function (r) {
|
|
1768
1808
|
return conf.cache = r;
|
|
1769
1809
|
}));
|
|
1770
1810
|
case 6:
|
|
1771
1811
|
case "end":
|
|
1772
|
-
return
|
|
1812
|
+
return _context10.stop();
|
|
1773
1813
|
}
|
|
1774
|
-
},
|
|
1814
|
+
}, _callee10);
|
|
1775
1815
|
}));
|
|
1776
1816
|
}
|
|
1817
|
+
function join_option_value(value) {
|
|
1818
|
+
if (!isObjectLike(value)) return value;
|
|
1819
|
+
var msg = (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.value);
|
|
1820
|
+
var text = value === null || value === void 0 ? void 0 : value.text;
|
|
1821
|
+
if (!msg) return null;
|
|
1822
|
+
return text ? "".concat(msg, "(").concat(text, ")") : msg;
|
|
1823
|
+
}
|
|
1777
1824
|
function speculate_on_display(value) {
|
|
1778
1825
|
if (!value) return '';
|
|
1779
1826
|
if (isNumber(value)) return value + '';
|
|
1780
1827
|
if (Array.isArray(value)) {
|
|
1781
|
-
var
|
|
1782
|
-
return
|
|
1828
|
+
var arr = value.map(join_option_value).filter(identity);
|
|
1829
|
+
return arr.join('/');
|
|
1783
1830
|
}
|
|
1784
1831
|
if (isObjectLike(value)) {
|
|
1785
|
-
return value
|
|
1832
|
+
return join_option_value(value);
|
|
1786
1833
|
}
|
|
1787
1834
|
if (isString(value)) {
|
|
1788
1835
|
var obj = safe_json_parse(value);
|
|
@@ -1836,19 +1883,34 @@ function simple_decrypt(code) {
|
|
|
1836
1883
|
}).join('');
|
|
1837
1884
|
return safe_json_parse(str);
|
|
1838
1885
|
}
|
|
1886
|
+
var SP = '@@';
|
|
1839
1887
|
function simple_encrypt_str(data) {
|
|
1888
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1840
1889
|
if (!data || !isString(data)) return null;
|
|
1841
1890
|
return data.split('').map(function (_, idx) {
|
|
1842
1891
|
return ~_.charCodeAt(0) + idx * 119;
|
|
1843
|
-
}).join(
|
|
1892
|
+
}).join(sp);
|
|
1844
1893
|
}
|
|
1845
1894
|
function simple_decrypt_str(code) {
|
|
1846
|
-
|
|
1847
|
-
|
|
1895
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1896
|
+
if (!code || !isString(code) || !code.includes(sp)) return null;
|
|
1897
|
+
var str = code.split(sp).map(function (_, idx) {
|
|
1848
1898
|
return String.fromCharCode(~(+_ - idx * 119));
|
|
1849
1899
|
}).join('');
|
|
1850
1900
|
return str;
|
|
1851
1901
|
}
|
|
1902
|
+
function text_ellipsis(text, max) {
|
|
1903
|
+
if (!text || !isNumber(max)) return '';
|
|
1904
|
+
if (text.length <= max) return text;
|
|
1905
|
+
return text.slice(0, max) + '...';
|
|
1906
|
+
}
|
|
1907
|
+
Object.assign(get_global(), {
|
|
1908
|
+
safe_async_call: safe_async_call,
|
|
1909
|
+
simple_decrypt_str: simple_decrypt_str,
|
|
1910
|
+
simple_encrypt_str: simple_encrypt_str
|
|
1911
|
+
});
|
|
1912
|
+
// safe_check()
|
|
1913
|
+
|
|
1852
1914
|
function getFn(format) {
|
|
1853
1915
|
function f(s) {
|
|
1854
1916
|
if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
|
|
@@ -1891,7 +1953,8 @@ function getMomentRange() {
|
|
|
1891
1953
|
// 这月: [start(m).startOf('month'), end(m).endOf('month')] as DT,
|
|
1892
1954
|
近一月: [start(m).add(-1, 'month').add(1, 'day'), end(m)],
|
|
1893
1955
|
下月: [start(m).add(1, 'month').startOf('month'), end(m).add(1, 'month').endOf('month')],
|
|
1894
|
-
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)]
|
|
1956
|
+
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)],
|
|
1957
|
+
年初至今: [start(m).startOf('year'), end(m)]
|
|
1895
1958
|
};
|
|
1896
1959
|
}
|
|
1897
1960
|
function presets_date() {
|
|
@@ -2379,24 +2442,6 @@ function presetInput(_label) {
|
|
|
2379
2442
|
label: _label
|
|
2380
2443
|
};
|
|
2381
2444
|
}
|
|
2382
|
-
function safe_fetch_options(cb) {
|
|
2383
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
2384
|
-
var arr;
|
|
2385
|
-
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
2386
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
2387
|
-
case 0:
|
|
2388
|
-
_context10.next = 2;
|
|
2389
|
-
return safe_async_call(cb);
|
|
2390
|
-
case 2:
|
|
2391
|
-
arr = _context10.sent;
|
|
2392
|
-
return _context10.abrupt("return", expect_array(arr));
|
|
2393
|
-
case 4:
|
|
2394
|
-
case "end":
|
|
2395
|
-
return _context10.stop();
|
|
2396
|
-
}
|
|
2397
|
-
}, _callee10);
|
|
2398
|
-
}));
|
|
2399
|
-
}
|
|
2400
2445
|
function getPresetOptions(key) {
|
|
2401
2446
|
var pure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2402
2447
|
var _a, _b;
|
|
@@ -2480,4 +2525,153 @@ function getDictionaryValue(type, label) {
|
|
|
2480
2525
|
function merge_dict(ops) {
|
|
2481
2526
|
Object.assign(dic_map, ops);
|
|
2482
2527
|
}
|
|
2483
|
-
|
|
2528
|
+
function create_load_src() {
|
|
2529
|
+
var cache = {};
|
|
2530
|
+
var head_el = document.getElementsByTagName("head")[0] || document.documentElement;
|
|
2531
|
+
function exec(options, node) {
|
|
2532
|
+
var opt;
|
|
2533
|
+
if (typeof options === "string") {
|
|
2534
|
+
opt = {
|
|
2535
|
+
url: options,
|
|
2536
|
+
debug: false
|
|
2537
|
+
};
|
|
2538
|
+
} else {
|
|
2539
|
+
opt = options;
|
|
2540
|
+
}
|
|
2541
|
+
var cacheId = opt.id || opt.url;
|
|
2542
|
+
var cacheEntry = cache[cacheId];
|
|
2543
|
+
if (cacheEntry) {
|
|
2544
|
+
if (!!opt.debug) {
|
|
2545
|
+
console.log("load-js: cache hit", cacheId);
|
|
2546
|
+
}
|
|
2547
|
+
return cacheEntry;
|
|
2548
|
+
} else if (opt.allowExternal !== false) {
|
|
2549
|
+
var el = getScriptById(opt.id) || getScriptByUrl(opt.url);
|
|
2550
|
+
if (el) {
|
|
2551
|
+
var promise = Promise.resolve(el);
|
|
2552
|
+
if (cacheId) {
|
|
2553
|
+
cache[cacheId] = promise;
|
|
2554
|
+
}
|
|
2555
|
+
return promise;
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
if (!opt.url && !opt.text) {
|
|
2559
|
+
throw new Error("load-js: must provide a url or text to load");
|
|
2560
|
+
}
|
|
2561
|
+
var pending = (opt.url ? loadScript : runScript)(node, createEl(opt));
|
|
2562
|
+
if (cacheId && opt.cache !== false) {
|
|
2563
|
+
cache[cacheId] = pending;
|
|
2564
|
+
}
|
|
2565
|
+
return pending;
|
|
2566
|
+
}
|
|
2567
|
+
function runScript(head, el) {
|
|
2568
|
+
head.appendChild(el);
|
|
2569
|
+
return Promise.resolve(el);
|
|
2570
|
+
}
|
|
2571
|
+
function loadScript(head, el) {
|
|
2572
|
+
return new Promise(function (resolve, reject) {
|
|
2573
|
+
// Handle Script loading
|
|
2574
|
+
var done = false;
|
|
2575
|
+
// Attach handlers for all browsers.
|
|
2576
|
+
//
|
|
2577
|
+
// References:
|
|
2578
|
+
// http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
|
|
2579
|
+
// http://stevesouders.com/efws/script-onload.php
|
|
2580
|
+
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
|
|
2581
|
+
//
|
|
2582
|
+
//@ts-ignore
|
|
2583
|
+
el.onload = el.onreadystatechange = function () {
|
|
2584
|
+
//@ts-ignore
|
|
2585
|
+
if (!done && (!el.readyState || el.readyState === "loaded" || el.readyState === "complete")) {
|
|
2586
|
+
done = true;
|
|
2587
|
+
// Handle memory leak in IE
|
|
2588
|
+
//@ts-ignore
|
|
2589
|
+
el.onload = el.onreadystatechange = null;
|
|
2590
|
+
resolve(el);
|
|
2591
|
+
}
|
|
2592
|
+
};
|
|
2593
|
+
el.onerror = reject;
|
|
2594
|
+
head.appendChild(el);
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
function createEl(opt) {
|
|
2598
|
+
var _a;
|
|
2599
|
+
if ((_a = opt.url) === null || _a === void 0 ? void 0 : _a.endsWith('css')) {
|
|
2600
|
+
return createLink(opt);
|
|
2601
|
+
}
|
|
2602
|
+
if (opt.type === 'text/css') {
|
|
2603
|
+
return createStyle(opt);
|
|
2604
|
+
}
|
|
2605
|
+
return createScript(opt);
|
|
2606
|
+
}
|
|
2607
|
+
function createScript(options) {
|
|
2608
|
+
var el = document.createElement("script");
|
|
2609
|
+
el.charset = options.charset || "utf-8";
|
|
2610
|
+
el.type = options.type || "text/javascript";
|
|
2611
|
+
el.async = !!options.async;
|
|
2612
|
+
el.id = options.id || options.url;
|
|
2613
|
+
//@ts-ignore
|
|
2614
|
+
el.loadJS = "watermark";
|
|
2615
|
+
if (options.url) {
|
|
2616
|
+
el.src = options.url;
|
|
2617
|
+
}
|
|
2618
|
+
if (options.text) {
|
|
2619
|
+
el.text = options.text;
|
|
2620
|
+
}
|
|
2621
|
+
return el;
|
|
2622
|
+
}
|
|
2623
|
+
function createLink(options) {
|
|
2624
|
+
var el = document.createElement("link");
|
|
2625
|
+
el.charset = options.charset || "utf-8";
|
|
2626
|
+
el.type = options.type || "text/css";
|
|
2627
|
+
el.id = options.id || options.url;
|
|
2628
|
+
el.rel = 'stylesheet';
|
|
2629
|
+
//@ts-ignore
|
|
2630
|
+
el.loadJS = "watermark";
|
|
2631
|
+
if (options.url) {
|
|
2632
|
+
el.href = options.url;
|
|
2633
|
+
}
|
|
2634
|
+
console.log('createLink', {
|
|
2635
|
+
options: options,
|
|
2636
|
+
el: el
|
|
2637
|
+
});
|
|
2638
|
+
return el;
|
|
2639
|
+
}
|
|
2640
|
+
function createStyle(options) {
|
|
2641
|
+
var el = document.createElement("style");
|
|
2642
|
+
el.id = options.id || options.text;
|
|
2643
|
+
//@ts-ignore
|
|
2644
|
+
el.loadJS = "watermark";
|
|
2645
|
+
if (options.text) {
|
|
2646
|
+
el.textContent = options.text;
|
|
2647
|
+
}
|
|
2648
|
+
return el;
|
|
2649
|
+
}
|
|
2650
|
+
function getScriptById(id) {
|
|
2651
|
+
var el = id && document.getElementById(id);
|
|
2652
|
+
//@ts-ignore
|
|
2653
|
+
if (el && el.loadJS !== "watermark") {
|
|
2654
|
+
console.warn("load-js: duplicate script with id:", id);
|
|
2655
|
+
return el;
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
function getScriptByUrl(url) {
|
|
2659
|
+
var el = url && document.querySelector("script[src='" + url + "']");
|
|
2660
|
+
//@ts-ignore
|
|
2661
|
+
if (el && el.loadJS !== "watermark") {
|
|
2662
|
+
console.warn("load-js: duplicate script with url:", url);
|
|
2663
|
+
return el;
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
return function load(items) {
|
|
2667
|
+
var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : head_el;
|
|
2668
|
+
return items instanceof Array ? Promise.all(items.map(function (_) {
|
|
2669
|
+
return exec(_, node);
|
|
2670
|
+
})) : exec(items, node);
|
|
2671
|
+
};
|
|
2672
|
+
}
|
|
2673
|
+
function load_src(items, node) {
|
|
2674
|
+
var load_src_ = create_load_src();
|
|
2675
|
+
return load_src_(items, node);
|
|
2676
|
+
}
|
|
2677
|
+
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, dyn_cb, 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, text_ellipsis, 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);
|
|
@@ -1639,6 +1642,17 @@ function copyText(text) {
|
|
|
1639
1642
|
document.body.removeChild(textareaC);
|
|
1640
1643
|
return res;
|
|
1641
1644
|
}
|
|
1645
|
+
function dyn_cb(cb, g_ctx) {
|
|
1646
|
+
try {
|
|
1647
|
+
cb(g_ctx());
|
|
1648
|
+
return false;
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
console.error('dyn_cb', {
|
|
1651
|
+
error: error
|
|
1652
|
+
});
|
|
1653
|
+
return true;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1642
1656
|
function safeExec(fn) {
|
|
1643
1657
|
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
|
1644
1658
|
args[_key8 - 1] = arguments[_key8];
|
|
@@ -1646,8 +1660,14 @@ function safeExec(fn) {
|
|
|
1646
1660
|
return isFunction(fn) ? fn.apply(void 0, args) : null;
|
|
1647
1661
|
}
|
|
1648
1662
|
function safeGetFromFuncOrData(fn) {
|
|
1663
|
+
var default_v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1649
1664
|
var _a;
|
|
1650
|
-
|
|
1665
|
+
try {
|
|
1666
|
+
return (_a = safeExec(fn)) !== null && _a !== void 0 ? _a : fn;
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
if (default_v) return default_v;
|
|
1669
|
+
throw error;
|
|
1670
|
+
}
|
|
1651
1671
|
}
|
|
1652
1672
|
function numberLikeCompare(a, b) {
|
|
1653
1673
|
if (a === b) return true;
|
|
@@ -1753,46 +1773,73 @@ function safe_async_call(cb) {
|
|
|
1753
1773
|
}, _callee8);
|
|
1754
1774
|
}));
|
|
1755
1775
|
}
|
|
1756
|
-
get_global().safe_async_call = safe_async_call;
|
|
1757
1776
|
var global_cache_map = {};
|
|
1758
|
-
function cache_fetch(
|
|
1759
|
-
return __awaiter(this,
|
|
1777
|
+
function cache_fetch(key_1, cb_1) {
|
|
1778
|
+
return __awaiter(this, arguments, void 0, function (key, cb) {
|
|
1779
|
+
var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1780
|
+
return /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
1781
|
+
var raw;
|
|
1782
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
1783
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1784
|
+
case 0:
|
|
1785
|
+
_context9.next = 2;
|
|
1786
|
+
return cache_fetch_inner(key, cb);
|
|
1787
|
+
case 2:
|
|
1788
|
+
raw = _context9.sent;
|
|
1789
|
+
return _context9.abrupt("return", deep ? cloneDeep(raw) : raw);
|
|
1790
|
+
case 4:
|
|
1791
|
+
case "end":
|
|
1792
|
+
return _context9.stop();
|
|
1793
|
+
}
|
|
1794
|
+
}, _callee9);
|
|
1795
|
+
})();
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
function cache_fetch_inner(key, cb) {
|
|
1799
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
1760
1800
|
var _a, conf;
|
|
1761
|
-
return _regeneratorRuntime.wrap(function
|
|
1762
|
-
while (1) switch (
|
|
1801
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
1802
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1763
1803
|
case 0:
|
|
1764
1804
|
conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
|
|
1765
1805
|
if (!conf.cache) {
|
|
1766
|
-
|
|
1806
|
+
_context10.next = 3;
|
|
1767
1807
|
break;
|
|
1768
1808
|
}
|
|
1769
|
-
return
|
|
1809
|
+
return _context10.abrupt("return", conf.cache);
|
|
1770
1810
|
case 3:
|
|
1771
1811
|
if (!conf.cache_promise) {
|
|
1772
|
-
|
|
1812
|
+
_context10.next = 5;
|
|
1773
1813
|
break;
|
|
1774
1814
|
}
|
|
1775
|
-
return
|
|
1815
|
+
return _context10.abrupt("return", conf.cache_promise);
|
|
1776
1816
|
case 5:
|
|
1777
|
-
return
|
|
1817
|
+
return _context10.abrupt("return", conf.cache_promise = cb().then(function (r) {
|
|
1778
1818
|
return conf.cache = r;
|
|
1779
1819
|
}));
|
|
1780
1820
|
case 6:
|
|
1781
1821
|
case "end":
|
|
1782
|
-
return
|
|
1822
|
+
return _context10.stop();
|
|
1783
1823
|
}
|
|
1784
|
-
},
|
|
1824
|
+
}, _callee10);
|
|
1785
1825
|
}));
|
|
1786
1826
|
}
|
|
1827
|
+
function join_option_value(value) {
|
|
1828
|
+
if (!isObjectLike(value)) return value;
|
|
1829
|
+
var msg = (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.value);
|
|
1830
|
+
var text = value === null || value === void 0 ? void 0 : value.text;
|
|
1831
|
+
if (!msg) return null;
|
|
1832
|
+
return text ? "".concat(msg, "(").concat(text, ")") : msg;
|
|
1833
|
+
}
|
|
1787
1834
|
function speculate_on_display(value) {
|
|
1788
1835
|
if (!value) return '';
|
|
1789
1836
|
if (isNumber(value)) return value + '';
|
|
1790
1837
|
if (Array.isArray(value)) {
|
|
1791
|
-
var
|
|
1792
|
-
return
|
|
1838
|
+
var arr = value.map(join_option_value).filter(identity);
|
|
1839
|
+
return arr.join('/');
|
|
1793
1840
|
}
|
|
1794
1841
|
if (isObjectLike(value)) {
|
|
1795
|
-
return value
|
|
1842
|
+
return join_option_value(value);
|
|
1796
1843
|
}
|
|
1797
1844
|
if (isString(value)) {
|
|
1798
1845
|
var obj = safe_json_parse(value);
|
|
@@ -1846,19 +1893,34 @@ function simple_decrypt(code) {
|
|
|
1846
1893
|
}).join('');
|
|
1847
1894
|
return safe_json_parse(str);
|
|
1848
1895
|
}
|
|
1896
|
+
var SP = '@@';
|
|
1849
1897
|
function simple_encrypt_str(data) {
|
|
1898
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1850
1899
|
if (!data || !isString(data)) return null;
|
|
1851
1900
|
return data.split('').map(function (_, idx) {
|
|
1852
1901
|
return ~_.charCodeAt(0) + idx * 119;
|
|
1853
|
-
}).join(
|
|
1902
|
+
}).join(sp);
|
|
1854
1903
|
}
|
|
1855
1904
|
function simple_decrypt_str(code) {
|
|
1856
|
-
|
|
1857
|
-
|
|
1905
|
+
var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
|
|
1906
|
+
if (!code || !isString(code) || !code.includes(sp)) return null;
|
|
1907
|
+
var str = code.split(sp).map(function (_, idx) {
|
|
1858
1908
|
return String.fromCharCode(~(+_ - idx * 119));
|
|
1859
1909
|
}).join('');
|
|
1860
1910
|
return str;
|
|
1861
1911
|
}
|
|
1912
|
+
function text_ellipsis(text, max) {
|
|
1913
|
+
if (!text || !isNumber(max)) return '';
|
|
1914
|
+
if (text.length <= max) return text;
|
|
1915
|
+
return text.slice(0, max) + '...';
|
|
1916
|
+
}
|
|
1917
|
+
Object.assign(get_global(), {
|
|
1918
|
+
safe_async_call: safe_async_call,
|
|
1919
|
+
simple_decrypt_str: simple_decrypt_str,
|
|
1920
|
+
simple_encrypt_str: simple_encrypt_str
|
|
1921
|
+
});
|
|
1922
|
+
// safe_check()
|
|
1923
|
+
|
|
1862
1924
|
function getFn(format) {
|
|
1863
1925
|
function f(s) {
|
|
1864
1926
|
if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
|
|
@@ -1901,7 +1963,8 @@ function getMomentRange() {
|
|
|
1901
1963
|
// 这月: [start(m).startOf('month'), end(m).endOf('month')] as DT,
|
|
1902
1964
|
近一月: [start(m).add(-1, 'month').add(1, 'day'), end(m)],
|
|
1903
1965
|
下月: [start(m).add(1, 'month').startOf('month'), end(m).add(1, 'month').endOf('month')],
|
|
1904
|
-
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)]
|
|
1966
|
+
近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)],
|
|
1967
|
+
年初至今: [start(m).startOf('year'), end(m)]
|
|
1905
1968
|
};
|
|
1906
1969
|
}
|
|
1907
1970
|
function presets_date() {
|
|
@@ -2389,24 +2452,6 @@ function presetInput(_label) {
|
|
|
2389
2452
|
label: _label
|
|
2390
2453
|
};
|
|
2391
2454
|
}
|
|
2392
|
-
function safe_fetch_options(cb) {
|
|
2393
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
2394
|
-
var arr;
|
|
2395
|
-
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
2396
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
2397
|
-
case 0:
|
|
2398
|
-
_context10.next = 2;
|
|
2399
|
-
return safe_async_call(cb);
|
|
2400
|
-
case 2:
|
|
2401
|
-
arr = _context10.sent;
|
|
2402
|
-
return _context10.abrupt("return", expect_array(arr));
|
|
2403
|
-
case 4:
|
|
2404
|
-
case "end":
|
|
2405
|
-
return _context10.stop();
|
|
2406
|
-
}
|
|
2407
|
-
}, _callee10);
|
|
2408
|
-
}));
|
|
2409
|
-
}
|
|
2410
2455
|
function getPresetOptions(key) {
|
|
2411
2456
|
var pure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2412
2457
|
var _a, _b;
|
|
@@ -2490,6 +2535,155 @@ function getDictionaryValue(type, label) {
|
|
|
2490
2535
|
function merge_dict(ops) {
|
|
2491
2536
|
Object.assign(dic_map, ops);
|
|
2492
2537
|
}
|
|
2538
|
+
function create_load_src() {
|
|
2539
|
+
var cache = {};
|
|
2540
|
+
var head_el = document.getElementsByTagName("head")[0] || document.documentElement;
|
|
2541
|
+
function exec(options, node) {
|
|
2542
|
+
var opt;
|
|
2543
|
+
if (typeof options === "string") {
|
|
2544
|
+
opt = {
|
|
2545
|
+
url: options,
|
|
2546
|
+
debug: false
|
|
2547
|
+
};
|
|
2548
|
+
} else {
|
|
2549
|
+
opt = options;
|
|
2550
|
+
}
|
|
2551
|
+
var cacheId = opt.id || opt.url;
|
|
2552
|
+
var cacheEntry = cache[cacheId];
|
|
2553
|
+
if (cacheEntry) {
|
|
2554
|
+
if (!!opt.debug) {
|
|
2555
|
+
console.log("load-js: cache hit", cacheId);
|
|
2556
|
+
}
|
|
2557
|
+
return cacheEntry;
|
|
2558
|
+
} else if (opt.allowExternal !== false) {
|
|
2559
|
+
var el = getScriptById(opt.id) || getScriptByUrl(opt.url);
|
|
2560
|
+
if (el) {
|
|
2561
|
+
var promise = Promise.resolve(el);
|
|
2562
|
+
if (cacheId) {
|
|
2563
|
+
cache[cacheId] = promise;
|
|
2564
|
+
}
|
|
2565
|
+
return promise;
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
if (!opt.url && !opt.text) {
|
|
2569
|
+
throw new Error("load-js: must provide a url or text to load");
|
|
2570
|
+
}
|
|
2571
|
+
var pending = (opt.url ? loadScript : runScript)(node, createEl(opt));
|
|
2572
|
+
if (cacheId && opt.cache !== false) {
|
|
2573
|
+
cache[cacheId] = pending;
|
|
2574
|
+
}
|
|
2575
|
+
return pending;
|
|
2576
|
+
}
|
|
2577
|
+
function runScript(head, el) {
|
|
2578
|
+
head.appendChild(el);
|
|
2579
|
+
return Promise.resolve(el);
|
|
2580
|
+
}
|
|
2581
|
+
function loadScript(head, el) {
|
|
2582
|
+
return new Promise(function (resolve, reject) {
|
|
2583
|
+
// Handle Script loading
|
|
2584
|
+
var done = false;
|
|
2585
|
+
// Attach handlers for all browsers.
|
|
2586
|
+
//
|
|
2587
|
+
// References:
|
|
2588
|
+
// http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
|
|
2589
|
+
// http://stevesouders.com/efws/script-onload.php
|
|
2590
|
+
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
|
|
2591
|
+
//
|
|
2592
|
+
//@ts-ignore
|
|
2593
|
+
el.onload = el.onreadystatechange = function () {
|
|
2594
|
+
//@ts-ignore
|
|
2595
|
+
if (!done && (!el.readyState || el.readyState === "loaded" || el.readyState === "complete")) {
|
|
2596
|
+
done = true;
|
|
2597
|
+
// Handle memory leak in IE
|
|
2598
|
+
//@ts-ignore
|
|
2599
|
+
el.onload = el.onreadystatechange = null;
|
|
2600
|
+
resolve(el);
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
el.onerror = reject;
|
|
2604
|
+
head.appendChild(el);
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
function createEl(opt) {
|
|
2608
|
+
var _a;
|
|
2609
|
+
if ((_a = opt.url) === null || _a === void 0 ? void 0 : _a.endsWith('css')) {
|
|
2610
|
+
return createLink(opt);
|
|
2611
|
+
}
|
|
2612
|
+
if (opt.type === 'text/css') {
|
|
2613
|
+
return createStyle(opt);
|
|
2614
|
+
}
|
|
2615
|
+
return createScript(opt);
|
|
2616
|
+
}
|
|
2617
|
+
function createScript(options) {
|
|
2618
|
+
var el = document.createElement("script");
|
|
2619
|
+
el.charset = options.charset || "utf-8";
|
|
2620
|
+
el.type = options.type || "text/javascript";
|
|
2621
|
+
el.async = !!options.async;
|
|
2622
|
+
el.id = options.id || options.url;
|
|
2623
|
+
//@ts-ignore
|
|
2624
|
+
el.loadJS = "watermark";
|
|
2625
|
+
if (options.url) {
|
|
2626
|
+
el.src = options.url;
|
|
2627
|
+
}
|
|
2628
|
+
if (options.text) {
|
|
2629
|
+
el.text = options.text;
|
|
2630
|
+
}
|
|
2631
|
+
return el;
|
|
2632
|
+
}
|
|
2633
|
+
function createLink(options) {
|
|
2634
|
+
var el = document.createElement("link");
|
|
2635
|
+
el.charset = options.charset || "utf-8";
|
|
2636
|
+
el.type = options.type || "text/css";
|
|
2637
|
+
el.id = options.id || options.url;
|
|
2638
|
+
el.rel = 'stylesheet';
|
|
2639
|
+
//@ts-ignore
|
|
2640
|
+
el.loadJS = "watermark";
|
|
2641
|
+
if (options.url) {
|
|
2642
|
+
el.href = options.url;
|
|
2643
|
+
}
|
|
2644
|
+
console.log('createLink', {
|
|
2645
|
+
options: options,
|
|
2646
|
+
el: el
|
|
2647
|
+
});
|
|
2648
|
+
return el;
|
|
2649
|
+
}
|
|
2650
|
+
function createStyle(options) {
|
|
2651
|
+
var el = document.createElement("style");
|
|
2652
|
+
el.id = options.id || options.text;
|
|
2653
|
+
//@ts-ignore
|
|
2654
|
+
el.loadJS = "watermark";
|
|
2655
|
+
if (options.text) {
|
|
2656
|
+
el.textContent = options.text;
|
|
2657
|
+
}
|
|
2658
|
+
return el;
|
|
2659
|
+
}
|
|
2660
|
+
function getScriptById(id) {
|
|
2661
|
+
var el = id && document.getElementById(id);
|
|
2662
|
+
//@ts-ignore
|
|
2663
|
+
if (el && el.loadJS !== "watermark") {
|
|
2664
|
+
console.warn("load-js: duplicate script with id:", id);
|
|
2665
|
+
return el;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
function getScriptByUrl(url) {
|
|
2669
|
+
var el = url && document.querySelector("script[src='" + url + "']");
|
|
2670
|
+
//@ts-ignore
|
|
2671
|
+
if (el && el.loadJS !== "watermark") {
|
|
2672
|
+
console.warn("load-js: duplicate script with url:", url);
|
|
2673
|
+
return el;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
return function load(items) {
|
|
2677
|
+
var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : head_el;
|
|
2678
|
+
return items instanceof Array ? Promise.all(items.map(function (_) {
|
|
2679
|
+
return exec(_, node);
|
|
2680
|
+
})) : exec(items, node);
|
|
2681
|
+
};
|
|
2682
|
+
}
|
|
2683
|
+
function load_src(items, node) {
|
|
2684
|
+
var load_src_ = create_load_src();
|
|
2685
|
+
return load_src_(items, node);
|
|
2686
|
+
}
|
|
2493
2687
|
Object.defineProperty(exports, 'dayjs', {
|
|
2494
2688
|
enumerable: true,
|
|
2495
2689
|
get: function get() {
|
|
@@ -2524,6 +2718,7 @@ exports.confirm_operation = confirm_operation;
|
|
|
2524
2718
|
exports.construct = construct;
|
|
2525
2719
|
exports.copyText = copyText;
|
|
2526
2720
|
exports.counting = counting;
|
|
2721
|
+
exports.create_load_src = create_load_src;
|
|
2527
2722
|
exports.crush = crush;
|
|
2528
2723
|
exports.dash = dash;
|
|
2529
2724
|
exports.dayjs_quarter = dayjs_quarter;
|
|
@@ -2533,6 +2728,7 @@ exports.diff = diff;
|
|
|
2533
2728
|
exports.diff_between = diff_between;
|
|
2534
2729
|
exports.downloadFile = downloadFile;
|
|
2535
2730
|
exports.draw = draw;
|
|
2731
|
+
exports.dyn_cb = dyn_cb;
|
|
2536
2732
|
exports.expect_array = expect_array;
|
|
2537
2733
|
exports.filter_obj_to_url_search = filter_obj_to_url_search;
|
|
2538
2734
|
exports.first = first;
|
|
@@ -2564,6 +2760,7 @@ exports.getSimpleOptions = getSimpleOptions;
|
|
|
2564
2760
|
exports.get_global = get_global;
|
|
2565
2761
|
exports.group = group;
|
|
2566
2762
|
exports.guard = guard;
|
|
2763
|
+
exports.hasOwn = hasOwn;
|
|
2567
2764
|
exports.identity = identity;
|
|
2568
2765
|
exports.image_to_base64 = image_to_base64;
|
|
2569
2766
|
exports.inRange = inRange;
|
|
@@ -2592,6 +2789,7 @@ exports.keys = keys;
|
|
|
2592
2789
|
exports.last = last;
|
|
2593
2790
|
exports.list = list;
|
|
2594
2791
|
exports.listify = listify;
|
|
2792
|
+
exports.load_src = load_src;
|
|
2595
2793
|
exports.lowerize = lowerize;
|
|
2596
2794
|
exports.map = map;
|
|
2597
2795
|
exports.mapEntries = mapEntries;
|
|
@@ -2628,7 +2826,6 @@ exports.retry = retry;
|
|
|
2628
2826
|
exports.safeExec = safeExec;
|
|
2629
2827
|
exports.safeGetFromFuncOrData = safeGetFromFuncOrData;
|
|
2630
2828
|
exports.safe_async_call = safe_async_call;
|
|
2631
|
-
exports.safe_fetch_options = safe_fetch_options;
|
|
2632
2829
|
exports.safe_json_parse = safe_json_parse;
|
|
2633
2830
|
exports.safe_json_parse_arr = safe_json_parse_arr;
|
|
2634
2831
|
exports.safe_json_stringify = safe_json_stringify;
|
|
@@ -2654,6 +2851,7 @@ exports.sort = sort;
|
|
|
2654
2851
|
exports.speculate_on_display = speculate_on_display;
|
|
2655
2852
|
exports.sum = sum;
|
|
2656
2853
|
exports.template = template;
|
|
2854
|
+
exports.text_ellipsis = text_ellipsis;
|
|
2657
2855
|
exports.throttle = throttle;
|
|
2658
2856
|
exports.title = title;
|
|
2659
2857
|
exports.toFloat = toFloat;
|
|
@@ -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;
|
|
@@ -36,5 +37,5 @@ export declare function isMoment(m: any): boolean;
|
|
|
36
37
|
*/
|
|
37
38
|
export declare function getFutureDate(num: number): any;
|
|
38
39
|
export declare function dayjs_quarter(input: Dayjs, which_quarter?: number): [Dayjs, number];
|
|
39
|
-
export declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean):
|
|
40
|
+
export declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): number;
|
|
40
41
|
export { dayjs };
|
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
|
@@ -16,9 +16,10 @@ export declare function unicodeToChar(u: number): string | null;
|
|
|
16
16
|
export declare function unicode_to_UTF8(u: number): number[] | null;
|
|
17
17
|
export declare function getFilledArray(n: number): any[];
|
|
18
18
|
export declare function copyText(text: string): boolean;
|
|
19
|
+
export declare function dyn_cb<T>(cb: (ctx: T) => void, g_ctx: () => T): boolean;
|
|
19
20
|
export declare function safeExec<T extends (...args: any) => any>(fn?: T, ...args: Parameters<T>): any;
|
|
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 safeGetFromFuncOrData(fn: any, default_v?: any): any;
|
|
22
|
+
export declare function numberLikeCompare(a: number | string | boolean | null, b: number | string | boolean | null): boolean;
|
|
22
23
|
export declare function warpBase64Type(str: string, type: 'img' | 'pdf'): string;
|
|
23
24
|
export declare function safe_number_parse(value: any, defaultValue?: number): number;
|
|
24
25
|
export declare function expect_array<T>(value?: T[] | null, default_v?: T[]): T[];
|
|
@@ -30,13 +31,14 @@ export declare function gen_encoded_char_svg(props: {
|
|
|
30
31
|
export declare function base64_to_image(base64img: string): Promise<HTMLImageElement | null>;
|
|
31
32
|
export declare function image_to_base64(img_el: HTMLImageElement): string | null;
|
|
32
33
|
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
|
|
34
|
+
export declare function safe_async_call<T extends (...args: any) => any>(cb?: T, ...args: Parameters<T>): Promise<ReturnType<T> | null>;
|
|
35
|
+
export declare function cache_fetch<T = any>(key: string, cb: () => Promise<T>, deep?: boolean): Promise<T>;
|
|
35
36
|
export declare function speculate_on_display(value?: any): string;
|
|
36
37
|
export declare function getFuckTimeInterval(star_hour?: number, end_hour?: number, min_interval?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 20 | 30): string[];
|
|
37
38
|
export declare function random_word(): string[];
|
|
38
39
|
export declare function confirm_operation(): boolean;
|
|
39
40
|
export declare function simple_encrypt(data: AnyObject | any[]): number[] | null;
|
|
40
41
|
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;
|
|
42
|
+
export declare function simple_encrypt_str(data: string, sp?: string): string | null;
|
|
43
|
+
export declare function simple_decrypt_str(code: string, sp?: string): string | null;
|
|
44
|
+
export declare function text_ellipsis(text: string, max: number): string;
|
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,21 +711,12 @@ 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
721
|
declare function get_global(): typeof globalThis;
|
|
720
722
|
declare function getSearchParamsValue(key: string): string | null;
|
|
@@ -732,9 +734,10 @@ declare function unicodeToChar(u: number): string | null;
|
|
|
732
734
|
declare function unicode_to_UTF8(u: number): number[] | null;
|
|
733
735
|
declare function getFilledArray(n: number): any[];
|
|
734
736
|
declare function copyText(text: string): boolean;
|
|
737
|
+
declare function dyn_cb<T>(cb: (ctx: T) => void, g_ctx: () => T): boolean;
|
|
735
738
|
declare function safeExec<T extends (...args: any) => any>(fn?: T, ...args: Parameters<T>): any;
|
|
736
|
-
declare function safeGetFromFuncOrData(fn: any): any;
|
|
737
|
-
declare function numberLikeCompare(a: number | string | boolean, b: number | string | boolean): boolean;
|
|
739
|
+
declare function safeGetFromFuncOrData(fn: any, default_v?: any): any;
|
|
740
|
+
declare function numberLikeCompare(a: number | string | boolean | null, b: number | string | boolean | null): boolean;
|
|
738
741
|
declare function warpBase64Type(str: string, type: 'img' | 'pdf'): string;
|
|
739
742
|
declare function safe_number_parse(value: any, defaultValue?: number): number;
|
|
740
743
|
declare function expect_array<T>(value?: T[] | null, default_v?: T[]): T[];
|
|
@@ -746,16 +749,17 @@ declare function gen_encoded_char_svg(props: {
|
|
|
746
749
|
declare function base64_to_image(base64img: string): Promise<HTMLImageElement | null>;
|
|
747
750
|
declare function image_to_base64(img_el: HTMLImageElement): string | null;
|
|
748
751
|
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
|
|
752
|
+
declare function safe_async_call<T extends (...args: any) => any>(cb?: T, ...args: Parameters<T>): Promise<ReturnType<T> | null>;
|
|
753
|
+
declare function cache_fetch<T = any>(key: string, cb: () => Promise<T>, deep?: boolean): Promise<T>;
|
|
751
754
|
declare function speculate_on_display(value?: any): string;
|
|
752
755
|
declare function getFuckTimeInterval(star_hour?: number, end_hour?: number, min_interval?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 20 | 30): string[];
|
|
753
756
|
declare function random_word(): string[];
|
|
754
757
|
declare function confirm_operation(): boolean;
|
|
755
758
|
declare function simple_encrypt(data: AnyObject | any[]): number[] | null;
|
|
756
759
|
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;
|
|
760
|
+
declare function simple_encrypt_str(data: string, sp?: string): string | null;
|
|
761
|
+
declare function simple_decrypt_str(code: string, sp?: string): string | null;
|
|
762
|
+
declare function text_ellipsis(text: string, max: number): string;
|
|
759
763
|
|
|
760
764
|
interface ILL {
|
|
761
765
|
log?(...optionalParams: any[]): void;
|
|
@@ -845,6 +849,7 @@ declare function getMomentRange(m?: any): {
|
|
|
845
849
|
近一月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
846
850
|
下月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
847
851
|
近一年: [dayjs.Dayjs, dayjs.Dayjs];
|
|
852
|
+
年初至今: [dayjs.Dayjs, dayjs.Dayjs];
|
|
848
853
|
};
|
|
849
854
|
declare function presets_date(): {
|
|
850
855
|
label: string;
|
|
@@ -856,7 +861,7 @@ declare function isMoment(m: any): boolean;
|
|
|
856
861
|
*/
|
|
857
862
|
declare function getFutureDate(num: number): any;
|
|
858
863
|
declare function dayjs_quarter(input: Dayjs, which_quarter?: number): [Dayjs, number];
|
|
859
|
-
declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean):
|
|
864
|
+
declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): number;
|
|
860
865
|
|
|
861
866
|
interface ISpectialOption {
|
|
862
867
|
sp?: ICommonOption[];
|
|
@@ -873,8 +878,6 @@ type TOptions<T extends TOptionKey | TGetOptionKey> = T extends TOptionKey ? ICo
|
|
|
873
878
|
declare function getSimpleOptions<T extends TOptionKey | TGetOptionKey>(_arr: T, options?: ISpectialOption): TOptions<T>;
|
|
874
879
|
declare function getSameOptions<T extends TOptionKey | TGetOptionKey>(_arr: T): TOptions<T>;
|
|
875
880
|
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
881
|
declare function getPresetOptions(key: string, pure?: boolean): ICommonOption[];
|
|
879
882
|
declare function getOptionLabel(k: string, value: any, defaultLabel?: string): string;
|
|
880
883
|
declare function getOptionValue(k: string, label: any): any;
|
|
@@ -916,5 +919,21 @@ declare function getDictionaryLabel(type: string, value: string | number): strin
|
|
|
916
919
|
declare function getDictionaryValue(type: string, label: string): number | null | undefined;
|
|
917
920
|
declare function merge_dict(ops: AnyObject<IDictionary>): void;
|
|
918
921
|
|
|
919
|
-
|
|
920
|
-
|
|
922
|
+
interface IOpt {
|
|
923
|
+
id?: string;
|
|
924
|
+
text?: string;
|
|
925
|
+
url?: string;
|
|
926
|
+
debug?: boolean;
|
|
927
|
+
allowExternal?: boolean;
|
|
928
|
+
cache?: boolean;
|
|
929
|
+
async?: boolean;
|
|
930
|
+
type?: 'text/css' | 'text/javascript';
|
|
931
|
+
charset?: string;
|
|
932
|
+
}
|
|
933
|
+
type TMixOpt = IOpt | string;
|
|
934
|
+
declare function create_load_src(): (items: TMixOpt | TMixOpt[], node?: HTMLHeadElement) => Promise<Element> | Promise<Element[]>;
|
|
935
|
+
declare function load_src(items: TMixOpt, node?: HTMLHeadElement): Promise<Element>;
|
|
936
|
+
declare function load_src(items: TMixOpt[], node?: HTMLHeadElement): Promise<Element[]>;
|
|
937
|
+
|
|
938
|
+
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, dyn_cb, 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, text_ellipsis, throttle, title, toFloat, toInt, toString, toggle, trim, tryit as try, tryit, uid, unicodeToChar, unicode_to_UTF8, unique, upperize, uuid, warpBase64Type, zip, zipToObject };
|
|
939
|
+
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.9",
|
|
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": "bb49d078600e65d77b842887c63be3b254faf999"
|
|
38
38
|
}
|