@lm_fe/utils 0.1.205 → 0.1.207

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # yargs-parser +3+
1
+ # yargs-parser @0@
2
2
 
3
3
 
4
4
 
package/dist/index.js CHANGED
@@ -2061,10 +2061,13 @@ function cloneDeep(value) {
2061
2061
  return null;
2062
2062
  }
2063
2063
  }
2064
+ function hasOwn(obj, key) {
2065
+ return Object.prototype.hasOwnProperty.call(obj, key);
2066
+ }
2064
2067
  function safe_json_parse(str) {
2065
2068
  var retOnErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2066
2069
  if (!str) return retOnErr;
2067
- if (_typeof$1(str) === 'object') return str;
2070
+ if (isObject(str) || isArray(str)) return str;
2068
2071
  if (!isString(str)) return retOnErr;
2069
2072
  try {
2070
2073
  var v = JSON.parse(str);
@@ -2272,6 +2275,17 @@ function copyText(text) {
2272
2275
  document.body.removeChild(textareaC);
2273
2276
  return res;
2274
2277
  }
2278
+ function dyn_cb(cb, g_ctx) {
2279
+ try {
2280
+ cb(g_ctx());
2281
+ return false;
2282
+ } catch (error) {
2283
+ console.error('dyn_cb', {
2284
+ error: error
2285
+ });
2286
+ return true;
2287
+ }
2288
+ }
2275
2289
  function safeExec(fn) {
2276
2290
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
2277
2291
  args[_key8 - 1] = arguments[_key8];
@@ -2279,8 +2293,14 @@ function safeExec(fn) {
2279
2293
  return isFunction(fn) ? fn.apply(void 0, args) : null;
2280
2294
  }
2281
2295
  function safeGetFromFuncOrData(fn) {
2296
+ var default_v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2282
2297
  var _a;
2283
- return (_a = safeExec(fn)) !== null && _a !== void 0 ? _a : fn;
2298
+ try {
2299
+ return (_a = safeExec(fn)) !== null && _a !== void 0 ? _a : fn;
2300
+ } catch (error) {
2301
+ if (default_v) return default_v;
2302
+ throw error;
2303
+ }
2284
2304
  }
2285
2305
  function numberLikeCompare(a, b) {
2286
2306
  if (a === b) return true;
@@ -2386,46 +2406,73 @@ function safe_async_call(cb) {
2386
2406
  }, _callee8);
2387
2407
  }));
2388
2408
  }
2389
- get_global().safe_async_call = safe_async_call;
2390
2409
  var global_cache_map = {};
2391
- function cache_fetch(key, cb) {
2392
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee9() {
2410
+ function cache_fetch(key_1, cb_1) {
2411
+ return __awaiter(this, arguments, void 0, function (key, cb) {
2412
+ var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2413
+ return /*#__PURE__*/regenerator.mark(function _callee9() {
2414
+ var raw;
2415
+ return regenerator.wrap(function _callee9$(_context9) {
2416
+ while (1) switch (_context9.prev = _context9.next) {
2417
+ case 0:
2418
+ _context9.next = 2;
2419
+ return cache_fetch_inner(key, cb);
2420
+ case 2:
2421
+ raw = _context9.sent;
2422
+ return _context9.abrupt("return", deep ? cloneDeep(raw) : raw);
2423
+ case 4:
2424
+ case "end":
2425
+ return _context9.stop();
2426
+ }
2427
+ }, _callee9);
2428
+ })();
2429
+ });
2430
+ }
2431
+ function cache_fetch_inner(key, cb) {
2432
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee10() {
2393
2433
  var _a, conf;
2394
- return regenerator.wrap(function _callee9$(_context9) {
2395
- while (1) switch (_context9.prev = _context9.next) {
2434
+ return regenerator.wrap(function _callee10$(_context10) {
2435
+ while (1) switch (_context10.prev = _context10.next) {
2396
2436
  case 0:
2397
2437
  conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
2398
2438
  if (!conf.cache) {
2399
- _context9.next = 3;
2439
+ _context10.next = 3;
2400
2440
  break;
2401
2441
  }
2402
- return _context9.abrupt("return", conf.cache);
2442
+ return _context10.abrupt("return", conf.cache);
2403
2443
  case 3:
2404
2444
  if (!conf.cache_promise) {
2405
- _context9.next = 5;
2445
+ _context10.next = 5;
2406
2446
  break;
2407
2447
  }
2408
- return _context9.abrupt("return", conf.cache_promise);
2448
+ return _context10.abrupt("return", conf.cache_promise);
2409
2449
  case 5:
2410
- return _context9.abrupt("return", conf.cache_promise = cb().then(function (r) {
2450
+ return _context10.abrupt("return", conf.cache_promise = cb().then(function (r) {
2411
2451
  return conf.cache = r;
2412
2452
  }));
2413
2453
  case 6:
2414
2454
  case "end":
2415
- return _context9.stop();
2455
+ return _context10.stop();
2416
2456
  }
2417
- }, _callee9);
2457
+ }, _callee10);
2418
2458
  }));
2419
2459
  }
2460
+ function join_option_value(value) {
2461
+ if (!isObjectLike(value)) return value;
2462
+ var msg = (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.value);
2463
+ var text = value === null || value === void 0 ? void 0 : value.text;
2464
+ if (!msg) return null;
2465
+ return text ? "".concat(msg, "(").concat(text, ")") : msg;
2466
+ }
2420
2467
  function speculate_on_display(value) {
2421
2468
  if (!value) return '';
2422
2469
  if (isNumber(value)) return value + '';
2423
2470
  if (Array.isArray(value)) {
2424
- var item0 = value[0];
2425
- return (item0 === null || item0 === void 0 ? void 0 : item0.label) || (item0 === null || item0 === void 0 ? void 0 : item0.value);
2471
+ var arr = value.map(join_option_value).filter(identity);
2472
+ return arr.join('/');
2426
2473
  }
2427
2474
  if (isObjectLike(value)) {
2428
- return value.label || value.value;
2475
+ return join_option_value(value);
2429
2476
  }
2430
2477
  if (isString(value)) {
2431
2478
  var obj = safe_json_parse(value);
@@ -2479,19 +2526,50 @@ function simple_decrypt(code) {
2479
2526
  }).join('');
2480
2527
  return safe_json_parse(str);
2481
2528
  }
2529
+ var SP = '@@';
2482
2530
  function simple_encrypt_str(data) {
2531
+ var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
2483
2532
  if (!data || !isString(data)) return null;
2484
2533
  return data.split('').map(function (_, idx) {
2485
2534
  return ~_.charCodeAt(0) + idx * 119;
2486
- }).join('@@');
2535
+ }).join(sp);
2487
2536
  }
2488
2537
  function simple_decrypt_str(code) {
2489
- if (!code || !isString(code)) return null;
2490
- var str = code.split('@@').map(function (_, idx) {
2538
+ var sp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SP;
2539
+ if (!code || !isString(code) || !code.includes(sp)) return null;
2540
+ var str = code.split(sp).map(function (_, idx) {
2491
2541
  return String.fromCharCode(~(+_ - idx * 119));
2492
2542
  }).join('');
2493
2543
  return str;
2494
2544
  }
2545
+ function text_ellipsis(text, max) {
2546
+ if (!text || !isNumber(max)) return '';
2547
+ if (text.length <= max) return text;
2548
+ return text.slice(0, max) + '...';
2549
+ }
2550
+ function calc_number(data) {
2551
+ if (isNil(data)) return 0;
2552
+ var data_to_calc = null;
2553
+ if (isArray(data)) data_to_calc = data.map(calc_number);
2554
+ if (isObject(data)) data_to_calc = Object.values(data).map(calc_number);
2555
+ if (isString(data) || isBoolean(data) || isNumber(data)) {
2556
+ var v = Number(data);
2557
+ if (!isNaN(v)) data_to_calc = [v];
2558
+ }
2559
+ if (data_to_calc) return data_to_calc.filter(function (_) {
2560
+ return isNumber(_) && !isNaN(_);
2561
+ }).reduce(function (sum, a) {
2562
+ return sum + a;
2563
+ }, 0);
2564
+ return 0;
2565
+ }
2566
+ Object.assign(get_global(), {
2567
+ safe_async_call: safe_async_call,
2568
+ simple_decrypt_str: simple_decrypt_str,
2569
+ simple_encrypt_str: simple_encrypt_str
2570
+ });
2571
+ // safe_check()
2572
+
2495
2573
  function getFn(format) {
2496
2574
  function f(s) {
2497
2575
  if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
@@ -2534,7 +2612,8 @@ function getMomentRange() {
2534
2612
  // 这月: [start(m).startOf('month'), end(m).endOf('month')] as DT,
2535
2613
  近一月: [start(m).add(-1, 'month').add(1, 'day'), end(m)],
2536
2614
  下月: [start(m).add(1, 'month').startOf('month'), end(m).add(1, 'month').endOf('month')],
2537
- 近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)]
2615
+ 近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)],
2616
+ 年初至今: [start(m).startOf('year'), end(m)]
2538
2617
  };
2539
2618
  }
2540
2619
  function presets_date() {
@@ -3022,24 +3101,6 @@ function presetInput(_label) {
3022
3101
  label: _label
3023
3102
  };
3024
3103
  }
3025
- function safe_fetch_options(cb) {
3026
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee10() {
3027
- var arr;
3028
- return regenerator.wrap(function _callee10$(_context10) {
3029
- while (1) switch (_context10.prev = _context10.next) {
3030
- case 0:
3031
- _context10.next = 2;
3032
- return safe_async_call(cb);
3033
- case 2:
3034
- arr = _context10.sent;
3035
- return _context10.abrupt("return", expect_array(arr));
3036
- case 4:
3037
- case "end":
3038
- return _context10.stop();
3039
- }
3040
- }, _callee10);
3041
- }));
3042
- }
3043
3104
  function getPresetOptions(key) {
3044
3105
  var pure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3045
3106
  var _a, _b;
@@ -3123,6 +3184,155 @@ function getDictionaryValue(type, label) {
3123
3184
  function merge_dict(ops) {
3124
3185
  Object.assign(dic_map, ops);
3125
3186
  }
3187
+ function create_load_src() {
3188
+ var cache = {};
3189
+ var head_el = document.getElementsByTagName("head")[0] || document.documentElement;
3190
+ function exec(options, node) {
3191
+ var opt;
3192
+ if (typeof options === "string") {
3193
+ opt = {
3194
+ url: options,
3195
+ debug: false
3196
+ };
3197
+ } else {
3198
+ opt = options;
3199
+ }
3200
+ var cacheId = opt.id || opt.url;
3201
+ var cacheEntry = cache[cacheId];
3202
+ if (cacheEntry) {
3203
+ if (!!opt.debug) {
3204
+ console.log("load-js: cache hit", cacheId);
3205
+ }
3206
+ return cacheEntry;
3207
+ } else if (opt.allowExternal !== false) {
3208
+ var el = getScriptById(opt.id) || getScriptByUrl(opt.url);
3209
+ if (el) {
3210
+ var promise = Promise.resolve(el);
3211
+ if (cacheId) {
3212
+ cache[cacheId] = promise;
3213
+ }
3214
+ return promise;
3215
+ }
3216
+ }
3217
+ if (!opt.url && !opt.text) {
3218
+ throw new Error("load-js: must provide a url or text to load");
3219
+ }
3220
+ var pending = (opt.url ? loadScript : runScript)(node, createEl(opt));
3221
+ if (cacheId && opt.cache !== false) {
3222
+ cache[cacheId] = pending;
3223
+ }
3224
+ return pending;
3225
+ }
3226
+ function runScript(head, el) {
3227
+ head.appendChild(el);
3228
+ return Promise.resolve(el);
3229
+ }
3230
+ function loadScript(head, el) {
3231
+ return new Promise(function (resolve, reject) {
3232
+ // Handle Script loading
3233
+ var done = false;
3234
+ // Attach handlers for all browsers.
3235
+ //
3236
+ // References:
3237
+ // http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
3238
+ // http://stevesouders.com/efws/script-onload.php
3239
+ // https://www.html5rocks.com/en/tutorials/speed/script-loading/
3240
+ //
3241
+ //@ts-ignore
3242
+ el.onload = el.onreadystatechange = function () {
3243
+ //@ts-ignore
3244
+ if (!done && (!el.readyState || el.readyState === "loaded" || el.readyState === "complete")) {
3245
+ done = true;
3246
+ // Handle memory leak in IE
3247
+ //@ts-ignore
3248
+ el.onload = el.onreadystatechange = null;
3249
+ resolve(el);
3250
+ }
3251
+ };
3252
+ el.onerror = reject;
3253
+ head.appendChild(el);
3254
+ });
3255
+ }
3256
+ function createEl(opt) {
3257
+ var _a;
3258
+ if ((_a = opt.url) === null || _a === void 0 ? void 0 : _a.endsWith('css')) {
3259
+ return createLink(opt);
3260
+ }
3261
+ if (opt.type === 'text/css') {
3262
+ return createStyle(opt);
3263
+ }
3264
+ return createScript(opt);
3265
+ }
3266
+ function createScript(options) {
3267
+ var el = document.createElement("script");
3268
+ el.charset = options.charset || "utf-8";
3269
+ el.type = options.type || "text/javascript";
3270
+ el.async = !!options.async;
3271
+ el.id = options.id || options.url;
3272
+ //@ts-ignore
3273
+ el.loadJS = "watermark";
3274
+ if (options.url) {
3275
+ el.src = options.url;
3276
+ }
3277
+ if (options.text) {
3278
+ el.text = options.text;
3279
+ }
3280
+ return el;
3281
+ }
3282
+ function createLink(options) {
3283
+ var el = document.createElement("link");
3284
+ el.charset = options.charset || "utf-8";
3285
+ el.type = options.type || "text/css";
3286
+ el.id = options.id || options.url;
3287
+ el.rel = 'stylesheet';
3288
+ //@ts-ignore
3289
+ el.loadJS = "watermark";
3290
+ if (options.url) {
3291
+ el.href = options.url;
3292
+ }
3293
+ console.log('createLink', {
3294
+ options: options,
3295
+ el: el
3296
+ });
3297
+ return el;
3298
+ }
3299
+ function createStyle(options) {
3300
+ var el = document.createElement("style");
3301
+ el.id = options.id || options.text;
3302
+ //@ts-ignore
3303
+ el.loadJS = "watermark";
3304
+ if (options.text) {
3305
+ el.textContent = options.text;
3306
+ }
3307
+ return el;
3308
+ }
3309
+ function getScriptById(id) {
3310
+ var el = id && document.getElementById(id);
3311
+ //@ts-ignore
3312
+ if (el && el.loadJS !== "watermark") {
3313
+ console.warn("load-js: duplicate script with id:", id);
3314
+ return el;
3315
+ }
3316
+ }
3317
+ function getScriptByUrl(url) {
3318
+ var el = url && document.querySelector("script[src='" + url + "']");
3319
+ //@ts-ignore
3320
+ if (el && el.loadJS !== "watermark") {
3321
+ console.warn("load-js: duplicate script with url:", url);
3322
+ return el;
3323
+ }
3324
+ }
3325
+ return function load(items) {
3326
+ var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : head_el;
3327
+ return items instanceof Array ? Promise.all(items.map(function (_) {
3328
+ return exec(_, node);
3329
+ })) : exec(items, node);
3330
+ };
3331
+ }
3332
+ function load_src(items, node) {
3333
+ var load_src_ = create_load_src();
3334
+ return load_src_(items, node);
3335
+ }
3126
3336
 
3127
3337
  // legacy
3128
3338
  var EventEmitter_Old = /*#__PURE__*/function () {
@@ -4524,5 +4734,5 @@ function TempNode(props) {
4524
4734
  fallback: /*#__PURE__*/React.createElement("div", null)
4525
4735
  }, /*#__PURE__*/React.createElement(Comp, null));
4526
4736
  }
4527
- export { ARG_URS1_KEY$1 as ARG_URS1_KEY, ARG_URS2_KEY$1 as ARG_URS2_KEY, AppEnv, BaseWsService, Browser, EMPTY_PLACEHOLDER$1 as EMPTY_PLACEHOLDER, EnumItem, EventBus, EventEmitter, EventEmitter_Old, GetAgeByBirthDay, MyLog, ROMAN_NUMERALS, Request, TOKEN_KEY$1 as TOKEN_KEY, all, alphabetical, appEnv, asRequest, _assign as assign, base64ToBinary, base64_to_image, boil, cache_fetch, calEddByLmp, calGestationalWeekByLmp, calGestationalWeekBySureEdd, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, codeMessage, compose, confirm_operation, construct, copyText, counting, crush, dash, dayjs_quarter, debounce, defer, diff, diff_between, downloadFile, draw, event, expect_array, filter_obj_to_url_search, first, flat, fork, formatDate, formatDateTime, formatDateTimeNoSecond, formatRangeDate, formatRangeDateTime, formatTime, format_gp, fubaoRequest, genEnum, genHappyPath, gen_encoded_char_svg, gen_id_form_item_config, get, getBMI, getChromeVersion, getDataSource, getDays, getDictionaries, getDictionariesEnumerations, getDictionaryLabel, getDictionaryValue, getDiffYears, getDualModeOptions, getExpected, getFilledArray, getFuckTimeInterval, getFutureDate, getGesWeek, getGestationalDays, getGestationalWeekBySureEdd, getHappyConfig, getMomentObj, getMomentRange, getOptionLabel, getOptionValue, getOrderTime, getPresetOptions, getSameOptions, getSearchParamsAll, getSearchParamsValue, getSimpleOptions, getTimeSlice, get_global, get_global_happy_arg, group, guard, identity, image_to_base64, inRange, intersects, invert, isArray, isBoolean, isDate, isEmpty, _isEqual as isEqual, isFloat, isFunction, isIE, isInt, isMoment, isNil, isNull, isNumber, isObject, isObjectLike, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, makeEventStore, map, mapEntries, mapKeys, mapValues, marshalGestationWeek, max, memo, menopauseWeek, merge, merge_dict, merge_preset_options, min, noop, numberLikeCompare, objectify, omit, optionKey不详, optionKey其他, optionKey否, parallel, partial, partob, pascal, pick, presets_date, protocolCheck, proxied, random, randomHex, random_word, range, rawRequest, reduce, replace, replaceOrAppend, request, retry, safeExec, safeGetFromFuncOrData, safe_async_call, safe_fetch_options, 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, temp_reander, template, throttle, title, toFloat, toInt, toString, toggle, transmit_happy, transmit_happy_pre, trim, tryit as try, tryit, uid, unicodeToChar, unicode_to_UTF8, unique, unmarshalGestationWeek, upperize, uuid, warpBase64Type, zip, zipToObject };
4737
+ export { ARG_URS1_KEY$1 as ARG_URS1_KEY, ARG_URS2_KEY$1 as ARG_URS2_KEY, AppEnv, BaseWsService, Browser, EMPTY_PLACEHOLDER$1 as EMPTY_PLACEHOLDER, EnumItem, EventBus, EventEmitter, EventEmitter_Old, GetAgeByBirthDay, MyLog, ROMAN_NUMERALS, Request, TOKEN_KEY$1 as TOKEN_KEY, all, alphabetical, appEnv, asRequest, _assign as assign, base64ToBinary, base64_to_image, boil, cache_fetch, calEddByLmp, calGestationalWeekByLmp, calGestationalWeekBySureEdd, calc_number, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, codeMessage, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayjs_quarter, debounce, defer, diff, diff_between, downloadFile, draw, dyn_cb, event, expect_array, filter_obj_to_url_search, first, flat, fork, formatDate, formatDateTime, formatDateTimeNoSecond, formatRangeDate, formatRangeDateTime, formatTime, format_gp, fubaoRequest, genEnum, genHappyPath, gen_encoded_char_svg, gen_id_form_item_config, get, getBMI, getChromeVersion, getDataSource, getDays, getDictionaries, getDictionariesEnumerations, getDictionaryLabel, getDictionaryValue, getDiffYears, getDualModeOptions, getExpected, getFilledArray, getFuckTimeInterval, getFutureDate, getGesWeek, getGestationalDays, getGestationalWeekBySureEdd, getHappyConfig, getMomentObj, getMomentRange, getOptionLabel, getOptionValue, getOrderTime, getPresetOptions, getSameOptions, getSearchParamsAll, getSearchParamsValue, getSimpleOptions, getTimeSlice, get_global, get_global_happy_arg, group, guard, hasOwn, identity, image_to_base64, inRange, intersects, invert, isArray, isBoolean, isDate, isEmpty, _isEqual as isEqual, isFloat, isFunction, isIE, isInt, isMoment, isNil, isNull, isNumber, isObject, isObjectLike, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, load_src, lowerize, makeEventStore, map, mapEntries, mapKeys, mapValues, marshalGestationWeek, max, memo, menopauseWeek, merge, merge_dict, merge_preset_options, min, noop, numberLikeCompare, objectify, omit, optionKey不详, optionKey其他, optionKey否, parallel, partial, partob, pascal, pick, presets_date, protocolCheck, proxied, random, randomHex, random_word, range, rawRequest, reduce, replace, replaceOrAppend, request, 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, temp_reander, template, text_ellipsis, throttle, title, toFloat, toInt, toString, toggle, transmit_happy, transmit_happy_pre, trim, tryit as try, tryit, uid, unicodeToChar, unicode_to_UTF8, unique, unmarshalGestationWeek, upperize, uuid, warpBase64Type, zip, zipToObject };
4528
4738
  //# sourceMappingURL=index.js.map