@noah-libjs/utils 0.0.8 → 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 CHANGED
@@ -1632,6 +1632,17 @@ function copyText(text) {
1632
1632
  document.body.removeChild(textareaC);
1633
1633
  return res;
1634
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
+ }
1635
1646
  function safeExec(fn) {
1636
1647
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
1637
1648
  args[_key8 - 1] = arguments[_key8];
@@ -1639,8 +1650,14 @@ function safeExec(fn) {
1639
1650
  return isFunction(fn) ? fn.apply(void 0, args) : null;
1640
1651
  }
1641
1652
  function safeGetFromFuncOrData(fn) {
1653
+ var default_v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1642
1654
  var _a;
1643
- return (_a = safeExec(fn)) !== null && _a !== void 0 ? _a : fn;
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
+ }
1644
1661
  }
1645
1662
  function numberLikeCompare(a, b) {
1646
1663
  if (a === b) return true;
@@ -1797,15 +1814,22 @@ function cache_fetch_inner(key, cb) {
1797
1814
  }, _callee10);
1798
1815
  }));
1799
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
+ }
1800
1824
  function speculate_on_display(value) {
1801
1825
  if (!value) return '';
1802
1826
  if (isNumber(value)) return value + '';
1803
1827
  if (Array.isArray(value)) {
1804
- var item0 = value[0];
1805
- return (item0 === null || item0 === void 0 ? void 0 : item0.label) || (item0 === null || item0 === void 0 ? void 0 : item0.value);
1828
+ var arr = value.map(join_option_value).filter(identity);
1829
+ return arr.join('/');
1806
1830
  }
1807
1831
  if (isObjectLike(value)) {
1808
- return value.label || value.value;
1832
+ return join_option_value(value);
1809
1833
  }
1810
1834
  if (isString(value)) {
1811
1835
  var obj = safe_json_parse(value);
@@ -1875,6 +1899,11 @@ function simple_decrypt_str(code) {
1875
1899
  }).join('');
1876
1900
  return str;
1877
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
+ }
1878
1907
  Object.assign(get_global(), {
1879
1908
  safe_async_call: safe_async_call,
1880
1909
  simple_decrypt_str: simple_decrypt_str,
@@ -2641,8 +2670,8 @@ function create_load_src() {
2641
2670
  })) : exec(items, node);
2642
2671
  };
2643
2672
  }
2644
- var load_src_ = create_load_src();
2645
2673
  function load_src(items, node) {
2674
+ var load_src_ = create_load_src();
2646
2675
  return load_src_(items, node);
2647
2676
  }
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 };
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/lib.js CHANGED
@@ -1642,6 +1642,17 @@ function copyText(text) {
1642
1642
  document.body.removeChild(textareaC);
1643
1643
  return res;
1644
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
+ }
1645
1656
  function safeExec(fn) {
1646
1657
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
1647
1658
  args[_key8 - 1] = arguments[_key8];
@@ -1649,8 +1660,14 @@ function safeExec(fn) {
1649
1660
  return isFunction(fn) ? fn.apply(void 0, args) : null;
1650
1661
  }
1651
1662
  function safeGetFromFuncOrData(fn) {
1663
+ var default_v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1652
1664
  var _a;
1653
- return (_a = safeExec(fn)) !== null && _a !== void 0 ? _a : fn;
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
+ }
1654
1671
  }
1655
1672
  function numberLikeCompare(a, b) {
1656
1673
  if (a === b) return true;
@@ -1807,15 +1824,22 @@ function cache_fetch_inner(key, cb) {
1807
1824
  }, _callee10);
1808
1825
  }));
1809
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
+ }
1810
1834
  function speculate_on_display(value) {
1811
1835
  if (!value) return '';
1812
1836
  if (isNumber(value)) return value + '';
1813
1837
  if (Array.isArray(value)) {
1814
- var item0 = value[0];
1815
- return (item0 === null || item0 === void 0 ? void 0 : item0.label) || (item0 === null || item0 === void 0 ? void 0 : item0.value);
1838
+ var arr = value.map(join_option_value).filter(identity);
1839
+ return arr.join('/');
1816
1840
  }
1817
1841
  if (isObjectLike(value)) {
1818
- return value.label || value.value;
1842
+ return join_option_value(value);
1819
1843
  }
1820
1844
  if (isString(value)) {
1821
1845
  var obj = safe_json_parse(value);
@@ -1885,6 +1909,11 @@ function simple_decrypt_str(code) {
1885
1909
  }).join('');
1886
1910
  return str;
1887
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
+ }
1888
1917
  Object.assign(get_global(), {
1889
1918
  safe_async_call: safe_async_call,
1890
1919
  simple_decrypt_str: simple_decrypt_str,
@@ -2651,8 +2680,8 @@ function create_load_src() {
2651
2680
  })) : exec(items, node);
2652
2681
  };
2653
2682
  }
2654
- var load_src_ = create_load_src();
2655
2683
  function load_src(items, node) {
2684
+ var load_src_ = create_load_src();
2656
2685
  return load_src_(items, node);
2657
2686
  }
2658
2687
  Object.defineProperty(exports, 'dayjs', {
@@ -2699,6 +2728,7 @@ exports.diff = diff;
2699
2728
  exports.diff_between = diff_between;
2700
2729
  exports.downloadFile = downloadFile;
2701
2730
  exports.draw = draw;
2731
+ exports.dyn_cb = dyn_cb;
2702
2732
  exports.expect_array = expect_array;
2703
2733
  exports.filter_obj_to_url_search = filter_obj_to_url_search;
2704
2734
  exports.first = first;
@@ -2821,6 +2851,7 @@ exports.sort = sort;
2821
2851
  exports.speculate_on_display = speculate_on_display;
2822
2852
  exports.sum = sum;
2823
2853
  exports.template = template;
2854
+ exports.text_ellipsis = text_ellipsis;
2824
2855
  exports.throttle = throttle;
2825
2856
  exports.title = title;
2826
2857
  exports.toFloat = toFloat;
@@ -37,5 +37,5 @@ export declare function isMoment(m: any): boolean;
37
37
  */
38
38
  export declare function getFutureDate(num: number): any;
39
39
  export declare function dayjs_quarter(input: Dayjs, which_quarter?: number): [Dayjs, number];
40
- export declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): any;
40
+ export declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): number;
41
41
  export { dayjs };
@@ -16,8 +16,9 @@ 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 safeGetFromFuncOrData(fn: any, default_v?: any): any;
21
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;
@@ -40,3 +41,4 @@ export declare function simple_encrypt(data: AnyObject | any[]): number[] | null
40
41
  export declare function simple_decrypt(code: number[]): AnyObject | null;
41
42
  export declare function simple_encrypt_str(data: string, sp?: string): string | null;
42
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/typing.d.ts CHANGED
@@ -734,8 +734,9 @@ declare function unicodeToChar(u: number): string | null;
734
734
  declare function unicode_to_UTF8(u: number): number[] | null;
735
735
  declare function getFilledArray(n: number): any[];
736
736
  declare function copyText(text: string): boolean;
737
+ declare function dyn_cb<T>(cb: (ctx: T) => void, g_ctx: () => T): boolean;
737
738
  declare function safeExec<T extends (...args: any) => any>(fn?: T, ...args: Parameters<T>): any;
738
- declare function safeGetFromFuncOrData(fn: any): any;
739
+ declare function safeGetFromFuncOrData(fn: any, default_v?: any): any;
739
740
  declare function numberLikeCompare(a: number | string | boolean | null, b: number | string | boolean | null): boolean;
740
741
  declare function warpBase64Type(str: string, type: 'img' | 'pdf'): string;
741
742
  declare function safe_number_parse(value: any, defaultValue?: number): number;
@@ -758,6 +759,7 @@ declare function simple_encrypt(data: AnyObject | any[]): number[] | null;
758
759
  declare function simple_decrypt(code: number[]): AnyObject | null;
759
760
  declare function simple_encrypt_str(data: string, sp?: string): string | null;
760
761
  declare function simple_decrypt_str(code: string, sp?: string): string | null;
762
+ declare function text_ellipsis(text: string, max: number): string;
761
763
 
762
764
  interface ILL {
763
765
  log?(...optionalParams: any[]): void;
@@ -859,7 +861,7 @@ declare function isMoment(m: any): boolean;
859
861
  */
860
862
  declare function getFutureDate(num: number): any;
861
863
  declare function dayjs_quarter(input: Dayjs, which_quarter?: number): [Dayjs, number];
862
- declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): any;
864
+ declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): number;
863
865
 
864
866
  interface ISpectialOption {
865
867
  sp?: ICommonOption[];
@@ -933,5 +935,5 @@ declare function create_load_src(): (items: TMixOpt | TMixOpt[], node?: HTMLHead
933
935
  declare function load_src(items: TMixOpt, node?: HTMLHeadElement): Promise<Element>;
934
936
  declare function load_src(items: TMixOpt[], node?: HTMLHeadElement): Promise<Element[]>;
935
937
 
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 };
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 };
937
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.8",
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": "a50958bb900a9e145a8a722b69c639cac93d2094"
37
+ "gitHead": "bb49d078600e65d77b842887c63be3b254faf999"
38
38
  }