@superutils/core 1.1.6 → 1.2.1

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/index.js CHANGED
@@ -27,8 +27,8 @@ var isArrLike = (x) => isArr(x) || x instanceof Set || x instanceof Map;
27
27
  var isArrLikeSafe = (x) => ["[object Array]", "[object Map]", "[object Set]"].includes(
28
28
  Object.prototype.toString.call(x)
29
29
  );
30
- var isArrUnique = (arr) => isArr(arr) && new Set(arr).size === arr.length;
31
- var isUint8Arr = (arr) => arr instanceof Uint8Array;
30
+ var isArrUnique = (x) => isArr(x) && new Set(x).size === x.length;
31
+ var isUint8Arr = (x) => x instanceof Uint8Array;
32
32
  var isArr_default = isArr;
33
33
 
34
34
  // src/is/isDate.ts
@@ -252,13 +252,16 @@ var objClean = (obj, keys, ignoreIfNotExist = true) => {
252
252
  };
253
253
 
254
254
  // src/obj/objKeys.ts
255
- var objKeys = (obj, sorted = true, includeSymbols = true) => fallbackIfFails_default(
256
- () => [
257
- ...includeSymbols && Object.getOwnPropertySymbols(obj) || [],
258
- ...sorted ? Object.keys(obj).sort() : Object.keys(obj)
259
- ],
260
- [],
261
- []
255
+ var objKeys = (obj, sorted = true, includeSymbols = true) => (
256
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
257
+ fallbackIfFails_default(
258
+ () => [
259
+ ...includeSymbols && Object.getOwnPropertySymbols(obj) || [],
260
+ ...sorted ? Object.keys(obj).sort() : Object.keys(obj)
261
+ ],
262
+ [],
263
+ []
264
+ )
262
265
  );
263
266
  var objKeys_default = objKeys;
264
267
 
@@ -582,10 +585,10 @@ var search = (data, options) => {
582
585
  var _a;
583
586
  const ignore = !getSize_default(data) || isEmpty(options == null ? void 0 : options.query);
584
587
  const result = isMap(options == null ? void 0 : options.result) ? options.result : /* @__PURE__ */ new Map();
585
- const asMap = (_a = options == null ? void 0 : options.asMap) != null ? _a : search.defaultOptions.asMap;
588
+ const asMap = (_a = options == null ? void 0 : options.asMap) != null ? _a : search.defaults.asMap;
586
589
  if (ignore) return asMap ? result : getValues_default(result);
587
590
  options = objCopy(
588
- search.defaultOptions,
591
+ search.defaults,
589
592
  options,
590
593
  [],
591
594
  "empty"
@@ -653,7 +656,7 @@ var search = (data, options) => {
653
656
  }
654
657
  return asMap ? result : getValues_default(result);
655
658
  };
656
- search.defaultOptions = {
659
+ search.defaults = {
657
660
  asMap: true,
658
661
  ignoreCase: true,
659
662
  limit: Infinity,
@@ -766,8 +769,8 @@ var sliceMap = (data, options) => {
766
769
  function sort(data, keyOrFn, options) {
767
770
  const dataType = isArr(data) ? 1 : isMap(data) ? 2 : isSet(data) ? 3 : 0;
768
771
  if (!dataType) return data;
769
- const { ignoreCase, newInstance, reverse: reverse2, undefinedFirst } = {
770
- ...sort.defaultOptions,
772
+ const { asString, ignoreCase, newInstance, reverse: reverse2, undefinedFirst } = {
773
+ ...sort.defaults,
771
774
  ...isObj(options) ? options : isObj(keyOrFn) ? keyOrFn : {}
772
775
  };
773
776
  if (dataType === 1 && isFn(keyOrFn)) {
@@ -778,7 +781,7 @@ function sort(data, keyOrFn, options) {
778
781
  newInstance
779
782
  );
780
783
  }
781
- const alt = undefinedFirst ? "" : "Z".repeat(10);
784
+ const alt = asString ? undefinedFirst ? "" : "Z".repeat(10) : undefinedFirst ? -Infinity : Infinity;
782
785
  const sorted = isFn(keyOrFn) ? arrReverse(
783
786
  // handle Set with comparator function
784
787
  [...data.entries()].sort(keyOrFn),
@@ -786,17 +789,18 @@ function sort(data, keyOrFn, options) {
786
789
  false
787
790
  // not required because of entries() & spread
788
791
  ) : (() => {
789
- const key = keyOrFn;
790
- const getVal = (obj) => {
791
- var _a;
792
- const value = `${(_a = isObj(obj) && key ? obj[key] : obj) != null ? _a : alt}`;
792
+ let index = 1;
793
+ const getVal = (target) => {
794
+ const val = isObj(target) && index !== 0 ? target[keyOrFn] : target;
795
+ if (!asString) return val;
796
+ const value = `${val != null ? val : alt}`;
793
797
  return ignoreCase ? value.toLowerCase() : value;
794
798
  };
795
- const index = keyOrFn === true ? 0 : 1;
796
799
  const [gt, lt] = reverse2 ? [-1, 1] : [1, -1];
797
800
  if ([1, 3].includes(dataType)) {
798
801
  return (dataType === 3 || newInstance ? [...data] : data).sort((a, b) => getVal(a) > getVal(b) ? gt : lt);
799
802
  }
803
+ index = keyOrFn === true ? 0 : 1;
800
804
  return [...data.entries()].sort(
801
805
  (a, b) => getVal(a == null ? void 0 : a[index]) > getVal(b == null ? void 0 : b[index]) ? gt : lt
802
806
  );
@@ -811,7 +815,8 @@ function sort(data, keyOrFn, options) {
811
815
  dataType === 2 ? data.set(...entry) : data.add(entry);
812
816
  return data;
813
817
  }
814
- sort.defaultOptions = {
818
+ sort.defaults = {
819
+ asString: true,
815
820
  ignoreCase: true,
816
821
  newInstance: false,
817
822
  reverse: false,
@@ -891,7 +896,7 @@ var getUrlParamRegex = (name, url, asArray = []) => {
891
896
  if (isUrl(url)) url = url.toString();
892
897
  const params = {};
893
898
  const regex = /[?&]+([^=&]+)=([^&]*)/gi;
894
- url.replace(regex, (_, name2, value) => {
899
+ url == null ? void 0 : url.replace(regex, (_, name2, value) => {
895
900
  value = decodeURIComponent(value);
896
901
  if (asArray.includes(name2) || params[name2] !== void 0) {
897
902
  params[name2] = isArr(params[name2]) ? params[name2] : [params[name2]];
package/package.json CHANGED
@@ -42,5 +42,6 @@
42
42
  "sideEffects": false,
43
43
  "type": "module",
44
44
  "types": "dist/index.d.ts",
45
- "version": "1.1.6"
45
+ "version": "1.2.1",
46
+ "gitHead": "a26f4b1bb701d99d4cb71443e18680ee3ea52974"
46
47
  }