@superutils/core 1.2.0 → 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/README.md +18 -7
- package/dist/index.d.ts +1176 -935
- package/dist/index.js +11 -9
- package/package.json +2 -1
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 = (
|
|
31
|
-
var isUint8Arr = (
|
|
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
|
|
@@ -769,7 +769,7 @@ var sliceMap = (data, options) => {
|
|
|
769
769
|
function sort(data, keyOrFn, options) {
|
|
770
770
|
const dataType = isArr(data) ? 1 : isMap(data) ? 2 : isSet(data) ? 3 : 0;
|
|
771
771
|
if (!dataType) return data;
|
|
772
|
-
const { ignoreCase, newInstance, reverse: reverse2, undefinedFirst } = {
|
|
772
|
+
const { asString, ignoreCase, newInstance, reverse: reverse2, undefinedFirst } = {
|
|
773
773
|
...sort.defaults,
|
|
774
774
|
...isObj(options) ? options : isObj(keyOrFn) ? keyOrFn : {}
|
|
775
775
|
};
|
|
@@ -781,7 +781,7 @@ function sort(data, keyOrFn, options) {
|
|
|
781
781
|
newInstance
|
|
782
782
|
);
|
|
783
783
|
}
|
|
784
|
-
const alt = undefinedFirst ? "" : "Z".repeat(10);
|
|
784
|
+
const alt = asString ? undefinedFirst ? "" : "Z".repeat(10) : undefinedFirst ? -Infinity : Infinity;
|
|
785
785
|
const sorted = isFn(keyOrFn) ? arrReverse(
|
|
786
786
|
// handle Set with comparator function
|
|
787
787
|
[...data.entries()].sort(keyOrFn),
|
|
@@ -789,17 +789,18 @@ function sort(data, keyOrFn, options) {
|
|
|
789
789
|
false
|
|
790
790
|
// not required because of entries() & spread
|
|
791
791
|
) : (() => {
|
|
792
|
-
|
|
793
|
-
const getVal = (
|
|
794
|
-
|
|
795
|
-
|
|
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}`;
|
|
796
797
|
return ignoreCase ? value.toLowerCase() : value;
|
|
797
798
|
};
|
|
798
|
-
const index = keyOrFn === true ? 0 : 1;
|
|
799
799
|
const [gt, lt] = reverse2 ? [-1, 1] : [1, -1];
|
|
800
800
|
if ([1, 3].includes(dataType)) {
|
|
801
801
|
return (dataType === 3 || newInstance ? [...data] : data).sort((a, b) => getVal(a) > getVal(b) ? gt : lt);
|
|
802
802
|
}
|
|
803
|
+
index = keyOrFn === true ? 0 : 1;
|
|
803
804
|
return [...data.entries()].sort(
|
|
804
805
|
(a, b) => getVal(a == null ? void 0 : a[index]) > getVal(b == null ? void 0 : b[index]) ? gt : lt
|
|
805
806
|
);
|
|
@@ -815,6 +816,7 @@ function sort(data, keyOrFn, options) {
|
|
|
815
816
|
return data;
|
|
816
817
|
}
|
|
817
818
|
sort.defaults = {
|
|
819
|
+
asString: true,
|
|
818
820
|
ignoreCase: true,
|
|
819
821
|
newInstance: false,
|
|
820
822
|
reverse: false,
|