@noah-libjs/utils 0.0.56 → 0.0.58
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 +43 -1
- package/dist/helper.d.ts +2 -0
- package/dist/lib.js +44 -0
- package/dist/typing.d.ts +3 -1
- package/package.json +2 -2
package/dist/es.js
CHANGED
|
@@ -1421,6 +1421,48 @@ function cloneDeep(value) {
|
|
|
1421
1421
|
function hasOwn(obj, key) {
|
|
1422
1422
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1423
1423
|
}
|
|
1424
|
+
function object_to_formData(obj) {
|
|
1425
|
+
var formData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new FormData();
|
|
1426
|
+
var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
1427
|
+
for (var key in obj) {
|
|
1428
|
+
var value = obj[key];
|
|
1429
|
+
var dataKey = parentKey ? "".concat(parentKey, ".").concat(key) : key;
|
|
1430
|
+
if (value === null || value === undefined) {
|
|
1431
|
+
formData.append(dataKey, '');
|
|
1432
|
+
} else if (value instanceof File) {
|
|
1433
|
+
formData.append(dataKey, value);
|
|
1434
|
+
} else if (_typeof(value) === 'object') {
|
|
1435
|
+
// 递归处理对象/数组
|
|
1436
|
+
object_to_formData(value, formData, dataKey);
|
|
1437
|
+
} else {
|
|
1438
|
+
formData.append(dataKey, value);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
return formData;
|
|
1442
|
+
}
|
|
1443
|
+
function object_to_searchparams(obj) {
|
|
1444
|
+
var params = new URLSearchParams();
|
|
1445
|
+
var _loop = function _loop(key) {
|
|
1446
|
+
var value = obj[key];
|
|
1447
|
+
// 过滤 undefined,null 转空字符串
|
|
1448
|
+
if (value === undefined) return 1; // continue
|
|
1449
|
+
if (value === null) value = "";
|
|
1450
|
+
// 数组处理:如 ids: [1,2,3] → ids=1&ids=2&ids=3
|
|
1451
|
+
if (Array.isArray(value)) {
|
|
1452
|
+
value.forEach(function (item) {
|
|
1453
|
+
params.append(key, item);
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
// 普通值直接添加
|
|
1457
|
+
else {
|
|
1458
|
+
params.append(key, value);
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
for (var key in obj) {
|
|
1462
|
+
if (_loop(key)) continue;
|
|
1463
|
+
}
|
|
1464
|
+
return params;
|
|
1465
|
+
}
|
|
1424
1466
|
function safe_json_parse(str) {
|
|
1425
1467
|
var retOnErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1426
1468
|
if (!str) return retOnErr;
|
|
@@ -2717,4 +2759,4 @@ function load_src(items, node) {
|
|
|
2717
2759
|
var load_src_ = create_load_src();
|
|
2718
2760
|
return load_src_(items, node);
|
|
2719
2761
|
}
|
|
2720
|
-
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, calc_number, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayOf, 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_evaluate_context, 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 };
|
|
2762
|
+
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, calc_number, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayOf, 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, object_to_formData, object_to_searchparams, 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_evaluate_context, 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
|
@@ -10,3 +10,5 @@ export declare function isNil(value: any): value is null | undefined;
|
|
|
10
10
|
export declare function toString(value: any): string;
|
|
11
11
|
export declare function cloneDeep<T>(value: T): T | null;
|
|
12
12
|
export declare function hasOwn(obj: AnyObject, key: PropertyKey): boolean;
|
|
13
|
+
export declare function object_to_formData(obj: AnyObject, formData?: FormData, parentKey?: string): FormData;
|
|
14
|
+
export declare function object_to_searchparams(obj: AnyObject): URLSearchParams;
|
package/dist/lib.js
CHANGED
|
@@ -1431,6 +1431,48 @@ function cloneDeep(value) {
|
|
|
1431
1431
|
function hasOwn(obj, key) {
|
|
1432
1432
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1433
1433
|
}
|
|
1434
|
+
function object_to_formData(obj) {
|
|
1435
|
+
var formData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new FormData();
|
|
1436
|
+
var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
1437
|
+
for (var key in obj) {
|
|
1438
|
+
var value = obj[key];
|
|
1439
|
+
var dataKey = parentKey ? "".concat(parentKey, ".").concat(key) : key;
|
|
1440
|
+
if (value === null || value === undefined) {
|
|
1441
|
+
formData.append(dataKey, '');
|
|
1442
|
+
} else if (value instanceof File) {
|
|
1443
|
+
formData.append(dataKey, value);
|
|
1444
|
+
} else if (_typeof(value) === 'object') {
|
|
1445
|
+
// 递归处理对象/数组
|
|
1446
|
+
object_to_formData(value, formData, dataKey);
|
|
1447
|
+
} else {
|
|
1448
|
+
formData.append(dataKey, value);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
return formData;
|
|
1452
|
+
}
|
|
1453
|
+
function object_to_searchparams(obj) {
|
|
1454
|
+
var params = new URLSearchParams();
|
|
1455
|
+
var _loop = function _loop(key) {
|
|
1456
|
+
var value = obj[key];
|
|
1457
|
+
// 过滤 undefined,null 转空字符串
|
|
1458
|
+
if (value === undefined) return 1; // continue
|
|
1459
|
+
if (value === null) value = "";
|
|
1460
|
+
// 数组处理:如 ids: [1,2,3] → ids=1&ids=2&ids=3
|
|
1461
|
+
if (Array.isArray(value)) {
|
|
1462
|
+
value.forEach(function (item) {
|
|
1463
|
+
params.append(key, item);
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
// 普通值直接添加
|
|
1467
|
+
else {
|
|
1468
|
+
params.append(key, value);
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
for (var key in obj) {
|
|
1472
|
+
if (_loop(key)) continue;
|
|
1473
|
+
}
|
|
1474
|
+
return params;
|
|
1475
|
+
}
|
|
1434
1476
|
function safe_json_parse(str) {
|
|
1435
1477
|
var retOnErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1436
1478
|
if (!str) return retOnErr;
|
|
@@ -2847,6 +2889,8 @@ exports.merge_preset_options = merge_preset_options;
|
|
|
2847
2889
|
exports.min = min;
|
|
2848
2890
|
exports.noop = noop;
|
|
2849
2891
|
exports.numberLikeCompare = numberLikeCompare;
|
|
2892
|
+
exports.object_to_formData = object_to_formData;
|
|
2893
|
+
exports.object_to_searchparams = object_to_searchparams;
|
|
2850
2894
|
exports.objectify = objectify;
|
|
2851
2895
|
exports.omit = omit;
|
|
2852
2896
|
exports["optionKey不详"] = optionKey不详;
|
package/dist/typing.d.ts
CHANGED
|
@@ -714,6 +714,8 @@ declare function isNil(value: any): value is null | undefined;
|
|
|
714
714
|
declare function toString(value: any): string;
|
|
715
715
|
declare function cloneDeep<T>(value: T): T | null;
|
|
716
716
|
declare function hasOwn(obj: AnyObject, key: PropertyKey): boolean;
|
|
717
|
+
declare function object_to_formData(obj: AnyObject, formData?: FormData, parentKey?: string): FormData;
|
|
718
|
+
declare function object_to_searchparams(obj: AnyObject): URLSearchParams;
|
|
717
719
|
|
|
718
720
|
declare function safe_json_parse<T = any>(str?: any, retOnErr?: T | null): T | null;
|
|
719
721
|
declare function safe_json_stringify(obj?: any): string;
|
|
@@ -942,5 +944,5 @@ declare function create_load_src(): (items: TMixOpt | TMixOpt[], node?: HTMLHead
|
|
|
942
944
|
declare function load_src(items: TMixOpt, node?: HTMLHeadElement): Promise<Element>;
|
|
943
945
|
declare function load_src(items: TMixOpt[], node?: HTMLHeadElement): Promise<Element[]>;
|
|
944
946
|
|
|
945
|
-
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, calc_number, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayOf, 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_evaluate_context, 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 };
|
|
947
|
+
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, calc_number, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, create_load_src, crush, dash, dayOf, 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, object_to_formData, object_to_searchparams, 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_evaluate_context, 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 };
|
|
946
948
|
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.58",
|
|
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": "53cc4a32579d7255f622cfb51a73678a45962f56"
|
|
38
38
|
}
|