@fluixi/utils 1.0.0-alpha.100
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/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.cjs +2858 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +2838 -0
- package/dist/lib/array/advanced.cjs +2227 -0
- package/dist/lib/array/advanced.d.ts +1116 -0
- package/dist/lib/array/advanced.d.ts.map +1 -0
- package/dist/lib/array/advanced.js +2429 -0
- package/dist/lib/array/advanced.mjs +2204 -0
- package/dist/lib/array/array.cjs +57 -0
- package/dist/lib/array/array.d.ts +6 -0
- package/dist/lib/array/array.d.ts.map +1 -0
- package/dist/lib/array/array.js +31 -0
- package/dist/lib/array/array.mjs +36 -0
- package/dist/lib/array/index.cjs +2344 -0
- package/dist/lib/array/index.d.ts +4 -0
- package/dist/lib/array/index.d.ts.map +1 -0
- package/dist/lib/array/index.js +3 -0
- package/dist/lib/array/index.mjs +2322 -0
- package/dist/lib/array/utils.cjs +103 -0
- package/dist/lib/array/utils.d.ts +100 -0
- package/dist/lib/array/utils.d.ts.map +1 -0
- package/dist/lib/array/utils.js +165 -0
- package/dist/lib/array/utils.mjs +82 -0
- package/dist/lib/color/color.cjs +2190 -0
- package/dist/lib/color/color.d.ts +366 -0
- package/dist/lib/color/color.d.ts.map +1 -0
- package/dist/lib/color/color.js +722 -0
- package/dist/lib/color/color.mjs +2167 -0
- package/dist/lib/color/constants.cjs +380 -0
- package/dist/lib/color/constants.d.ts +361 -0
- package/dist/lib/color/constants.d.ts.map +1 -0
- package/dist/lib/color/constants.js +358 -0
- package/dist/lib/color/constants.mjs +359 -0
- package/dist/lib/color/conversions.cjs +629 -0
- package/dist/lib/color/conversions.d.ts +166 -0
- package/dist/lib/color/conversions.d.ts.map +1 -0
- package/dist/lib/color/conversions.js +766 -0
- package/dist/lib/color/conversions.mjs +608 -0
- package/dist/lib/color/helpers.cjs +2534 -0
- package/dist/lib/color/helpers.d.ts +75 -0
- package/dist/lib/color/helpers.d.ts.map +1 -0
- package/dist/lib/color/helpers.js +419 -0
- package/dist/lib/color/helpers.mjs +2511 -0
- package/dist/lib/color/index.cjs +2641 -0
- package/dist/lib/color/index.d.ts +12 -0
- package/dist/lib/color/index.d.ts.map +1 -0
- package/dist/lib/color/index.js +15 -0
- package/dist/lib/color/index.mjs +2619 -0
- package/dist/lib/color/types.cjs +18 -0
- package/dist/lib/color/types.d.ts +179 -0
- package/dist/lib/color/types.d.ts.map +1 -0
- package/dist/lib/color/types.js +1 -0
- package/dist/lib/color/types.mjs +0 -0
- package/dist/lib/color/utils.cjs +962 -0
- package/dist/lib/color/utils.d.ts +199 -0
- package/dist/lib/color/utils.d.ts.map +1 -0
- package/dist/lib/color/utils.js +858 -0
- package/dist/lib/color/utils.mjs +939 -0
- package/dist/lib/compare/comparators.cjs +171 -0
- package/dist/lib/compare/comparators.d.ts +65 -0
- package/dist/lib/compare/comparators.d.ts.map +1 -0
- package/dist/lib/compare/comparators.js +210 -0
- package/dist/lib/compare/comparators.mjs +150 -0
- package/dist/lib/compare/index.cjs +172 -0
- package/dist/lib/compare/index.d.ts +2 -0
- package/dist/lib/compare/index.d.ts.map +1 -0
- package/dist/lib/compare/index.js +1 -0
- package/dist/lib/compare/index.mjs +152 -0
- package/dist/lib/cookie/codec.cjs +72 -0
- package/dist/lib/cookie/codec.d.ts +22 -0
- package/dist/lib/cookie/codec.d.ts.map +1 -0
- package/dist/lib/cookie/codec.js +67 -0
- package/dist/lib/cookie/codec.mjs +51 -0
- package/dist/lib/cookie/index.cjs +75 -0
- package/dist/lib/cookie/index.d.ts +2 -0
- package/dist/lib/cookie/index.d.ts.map +1 -0
- package/dist/lib/cookie/index.js +1 -0
- package/dist/lib/cookie/index.mjs +53 -0
- package/dist/lib/crypto/hash.cjs +83 -0
- package/dist/lib/crypto/hash.d.ts +6 -0
- package/dist/lib/crypto/hash.d.ts.map +1 -0
- package/dist/lib/crypto/hash.js +53 -0
- package/dist/lib/crypto/hash.mjs +62 -0
- package/dist/lib/crypto/index.cjs +85 -0
- package/dist/lib/crypto/index.d.ts +2 -0
- package/dist/lib/crypto/index.d.ts.map +1 -0
- package/dist/lib/crypto/index.js +1 -0
- package/dist/lib/crypto/index.mjs +62 -0
- package/dist/lib/dom/events.cjs +40 -0
- package/dist/lib/dom/events.d.ts +159 -0
- package/dist/lib/dom/events.d.ts.map +1 -0
- package/dist/lib/dom/events.js +50 -0
- package/dist/lib/dom/events.mjs +19 -0
- package/dist/lib/dom/index.cjs +78 -0
- package/dist/lib/dom/index.d.ts +3 -0
- package/dist/lib/dom/index.d.ts.map +1 -0
- package/dist/lib/dom/index.js +2 -0
- package/dist/lib/dom/index.mjs +56 -0
- package/dist/lib/dom/utils.cjs +57 -0
- package/dist/lib/dom/utils.d.ts +6 -0
- package/dist/lib/dom/utils.d.ts.map +1 -0
- package/dist/lib/dom/utils.js +37 -0
- package/dist/lib/dom/utils.mjs +36 -0
- package/dist/lib/functions/functions.cjs +366 -0
- package/dist/lib/functions/functions.d.ts +329 -0
- package/dist/lib/functions/functions.d.ts.map +1 -0
- package/dist/lib/functions/functions.js +585 -0
- package/dist/lib/functions/functions.mjs +345 -0
- package/dist/lib/functions/index.cjs +369 -0
- package/dist/lib/functions/index.d.ts +3 -0
- package/dist/lib/functions/index.d.ts.map +1 -0
- package/dist/lib/functions/index.js +1 -0
- package/dist/lib/functions/index.mjs +347 -0
- package/dist/lib/functions/types.cjs +18 -0
- package/dist/lib/functions/types.d.ts +2 -0
- package/dist/lib/functions/types.d.ts.map +1 -0
- package/dist/lib/functions/types.js +1 -0
- package/dist/lib/functions/types.mjs +0 -0
- package/dist/lib/helpers.cjs +78 -0
- package/dist/lib/helpers.d.ts +13 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/helpers.js +66 -0
- package/dist/lib/helpers.mjs +59 -0
- package/dist/lib/index.cjs +2857 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +8 -0
- package/dist/lib/index.mjs +2836 -0
- package/dist/lib/maths/constants.cjs +70 -0
- package/dist/lib/maths/constants.d.ts +84 -0
- package/dist/lib/maths/constants.d.ts.map +1 -0
- package/dist/lib/maths/constants.js +79 -0
- package/dist/lib/maths/constants.mjs +50 -0
- package/dist/lib/maths/fn/advanced.cjs +231 -0
- package/dist/lib/maths/fn/advanced.d.ts +149 -0
- package/dist/lib/maths/fn/advanced.d.ts.map +1 -0
- package/dist/lib/maths/fn/advanced.js +264 -0
- package/dist/lib/maths/fn/advanced.mjs +208 -0
- package/dist/lib/maths/fn/basic.cjs +212 -0
- package/dist/lib/maths/fn/basic.d.ts +182 -0
- package/dist/lib/maths/fn/basic.d.ts.map +1 -0
- package/dist/lib/maths/fn/basic.js +343 -0
- package/dist/lib/maths/fn/basic.mjs +191 -0
- package/dist/lib/maths/fn/complex.cjs +268 -0
- package/dist/lib/maths/fn/complex.d.ts +153 -0
- package/dist/lib/maths/fn/complex.d.ts.map +1 -0
- package/dist/lib/maths/fn/complex.js +383 -0
- package/dist/lib/maths/fn/complex.mjs +247 -0
- package/dist/lib/maths/fn/index.cjs +877 -0
- package/dist/lib/maths/fn/index.d.ts +10 -0
- package/dist/lib/maths/fn/index.d.ts.map +1 -0
- package/dist/lib/maths/fn/index.js +9 -0
- package/dist/lib/maths/fn/index.mjs +855 -0
- package/dist/lib/maths/fn/trigo.cjs +179 -0
- package/dist/lib/maths/fn/trigo.d.ts +147 -0
- package/dist/lib/maths/fn/trigo.d.ts.map +1 -0
- package/dist/lib/maths/fn/trigo.js +227 -0
- package/dist/lib/maths/fn/trigo.mjs +156 -0
- package/dist/lib/maths/fn/vector.cjs +728 -0
- package/dist/lib/maths/fn/vector.d.ts +512 -0
- package/dist/lib/maths/fn/vector.d.ts.map +1 -0
- package/dist/lib/maths/fn/vector.js +1136 -0
- package/dist/lib/maths/fn/vector.mjs +707 -0
- package/dist/lib/maths/formatter.cjs +61 -0
- package/dist/lib/maths/formatter.d.ts +35 -0
- package/dist/lib/maths/formatter.d.ts.map +1 -0
- package/dist/lib/maths/formatter.js +56 -0
- package/dist/lib/maths/formatter.mjs +40 -0
- package/dist/lib/maths/guards.cjs +164 -0
- package/dist/lib/maths/guards.d.ts +166 -0
- package/dist/lib/maths/guards.d.ts.map +1 -0
- package/dist/lib/maths/guards.js +315 -0
- package/dist/lib/maths/guards.mjs +144 -0
- package/dist/lib/maths/index.cjs +1152 -0
- package/dist/lib/maths/index.d.ts +24 -0
- package/dist/lib/maths/index.d.ts.map +1 -0
- package/dist/lib/maths/index.js +29 -0
- package/dist/lib/maths/index.mjs +1130 -0
- package/dist/lib/maths/parser.cjs +75 -0
- package/dist/lib/maths/parser.d.ts +20 -0
- package/dist/lib/maths/parser.d.ts.map +1 -0
- package/dist/lib/maths/parser.js +78 -0
- package/dist/lib/maths/parser.mjs +54 -0
- package/dist/lib/maths/random.cjs +49 -0
- package/dist/lib/maths/random.d.ts +27 -0
- package/dist/lib/maths/random.d.ts.map +1 -0
- package/dist/lib/maths/random.js +49 -0
- package/dist/lib/maths/random.mjs +28 -0
- package/dist/lib/maths/types/advanced.cjs +18 -0
- package/dist/lib/maths/types/advanced.d.ts +357 -0
- package/dist/lib/maths/types/advanced.d.ts.map +1 -0
- package/dist/lib/maths/types/advanced.js +5 -0
- package/dist/lib/maths/types/advanced.mjs +0 -0
- package/dist/lib/maths/types/basic.cjs +18 -0
- package/dist/lib/maths/types/basic.d.ts +95 -0
- package/dist/lib/maths/types/basic.d.ts.map +1 -0
- package/dist/lib/maths/types/basic.js +5 -0
- package/dist/lib/maths/types/basic.mjs +0 -0
- package/dist/lib/maths/types/index.cjs +19 -0
- package/dist/lib/maths/types/index.d.ts +4 -0
- package/dist/lib/maths/types/index.d.ts.map +1 -0
- package/dist/lib/maths/types/index.js +3 -0
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -0
- package/dist/lib/maths/types/negative.d.ts +51 -0
- package/dist/lib/maths/types/negative.d.ts.map +1 -0
- package/dist/lib/maths/types/negative.js +5 -0
- package/dist/lib/maths/types/negative.mjs +0 -0
- package/dist/lib/maths/types/operations.cjs +18 -0
- package/dist/lib/maths/types/operations.d.ts +188 -0
- package/dist/lib/maths/types/operations.d.ts.map +1 -0
- package/dist/lib/maths/types/operations.js +6 -0
- package/dist/lib/maths/types/operations.mjs +0 -0
- package/dist/lib/object/clone.cjs +88 -0
- package/dist/lib/object/clone.d.ts +46 -0
- package/dist/lib/object/clone.d.ts.map +1 -0
- package/dist/lib/object/clone.js +104 -0
- package/dist/lib/object/clone.mjs +65 -0
- package/dist/lib/object/diff.cjs +573 -0
- package/dist/lib/object/diff.d.ts +203 -0
- package/dist/lib/object/diff.d.ts.map +1 -0
- package/dist/lib/object/diff.js +805 -0
- package/dist/lib/object/diff.mjs +550 -0
- package/dist/lib/object/getter-setter.cjs +2351 -0
- package/dist/lib/object/getter-setter.d.ts +361 -0
- package/dist/lib/object/getter-setter.d.ts.map +1 -0
- package/dist/lib/object/getter-setter.js +1771 -0
- package/dist/lib/object/getter-setter.mjs +2330 -0
- package/dist/lib/object/index.cjs +3956 -0
- package/dist/lib/object/index.d.ts +13 -0
- package/dist/lib/object/index.d.ts.map +1 -0
- package/dist/lib/object/index.js +12 -0
- package/dist/lib/object/index.mjs +3936 -0
- package/dist/lib/object/merge.cjs +1029 -0
- package/dist/lib/object/merge.d.ts +93 -0
- package/dist/lib/object/merge.d.ts.map +1 -0
- package/dist/lib/object/merge.js +474 -0
- package/dist/lib/object/merge.mjs +1006 -0
- package/dist/lib/object/object.cjs +280 -0
- package/dist/lib/object/object.d.ts +128 -0
- package/dist/lib/object/object.d.ts.map +1 -0
- package/dist/lib/object/object.js +432 -0
- package/dist/lib/object/object.mjs +257 -0
- package/dist/lib/object/omit.cjs +2022 -0
- package/dist/lib/object/omit.d.ts +351 -0
- package/dist/lib/object/omit.d.ts.map +1 -0
- package/dist/lib/object/omit.js +656 -0
- package/dist/lib/object/omit.mjs +1999 -0
- package/dist/lib/object/reconcile.cjs +126 -0
- package/dist/lib/object/reconcile.d.ts +7 -0
- package/dist/lib/object/reconcile.d.ts.map +1 -0
- package/dist/lib/object/reconcile.js +122 -0
- package/dist/lib/object/reconcile.mjs +105 -0
- package/dist/lib/object/selector.cjs +303 -0
- package/dist/lib/object/selector.d.ts +50 -0
- package/dist/lib/object/selector.d.ts.map +1 -0
- package/dist/lib/object/selector.js +371 -0
- package/dist/lib/object/selector.mjs +282 -0
- package/dist/lib/object/sort.cjs +209 -0
- package/dist/lib/object/sort.d.ts +149 -0
- package/dist/lib/object/sort.d.ts.map +1 -0
- package/dist/lib/object/sort.js +298 -0
- package/dist/lib/object/sort.mjs +186 -0
- package/dist/lib/object/transform.cjs +2211 -0
- package/dist/lib/object/transform.d.ts +620 -0
- package/dist/lib/object/transform.d.ts.map +1 -0
- package/dist/lib/object/transform.js +1058 -0
- package/dist/lib/object/transform.mjs +2190 -0
- package/dist/lib/object/types.cjs +18 -0
- package/dist/lib/object/types.d.ts +250 -0
- package/dist/lib/object/types.d.ts.map +1 -0
- package/dist/lib/object/types.js +1 -0
- package/dist/lib/object/types.mjs +0 -0
- package/dist/lib/object/utils.cjs +326 -0
- package/dist/lib/object/utils.d.ts +165 -0
- package/dist/lib/object/utils.d.ts.map +1 -0
- package/dist/lib/object/utils.js +444 -0
- package/dist/lib/object/utils.mjs +305 -0
- package/dist/lib/primitive/boolean/boolean.cjs +407 -0
- package/dist/lib/primitive/boolean/boolean.d.ts +276 -0
- package/dist/lib/primitive/boolean/boolean.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/boolean.js +615 -0
- package/dist/lib/primitive/boolean/boolean.mjs +386 -0
- package/dist/lib/primitive/boolean/index.cjs +382 -0
- package/dist/lib/primitive/boolean/index.d.ts +3 -0
- package/dist/lib/primitive/boolean/index.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/index.js +2 -0
- package/dist/lib/primitive/boolean/index.mjs +359 -0
- package/dist/lib/primitive/boolean/types.cjs +18 -0
- package/dist/lib/primitive/boolean/types.d.ts +14 -0
- package/dist/lib/primitive/boolean/types.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/types.js +1 -0
- package/dist/lib/primitive/boolean/types.mjs +0 -0
- package/dist/lib/primitive/date/date.cjs +1126 -0
- package/dist/lib/primitive/date/date.d.ts +641 -0
- package/dist/lib/primitive/date/date.d.ts.map +1 -0
- package/dist/lib/primitive/date/date.js +1998 -0
- package/dist/lib/primitive/date/date.mjs +1105 -0
- package/dist/lib/primitive/date/index.cjs +1128 -0
- package/dist/lib/primitive/date/index.d.ts +3 -0
- package/dist/lib/primitive/date/index.d.ts.map +1 -0
- package/dist/lib/primitive/date/index.js +2 -0
- package/dist/lib/primitive/date/index.mjs +1105 -0
- package/dist/lib/primitive/date/types.cjs +18 -0
- package/dist/lib/primitive/date/types.d.ts +205 -0
- package/dist/lib/primitive/date/types.d.ts.map +1 -0
- package/dist/lib/primitive/date/types.js +7 -0
- package/dist/lib/primitive/date/types.mjs +0 -0
- package/dist/lib/primitive/index.cjs +2338 -0
- package/dist/lib/primitive/index.d.ts +5 -0
- package/dist/lib/primitive/index.d.ts.map +1 -0
- package/dist/lib/primitive/index.js +4 -0
- package/dist/lib/primitive/index.mjs +2316 -0
- package/dist/lib/primitive/string/index.cjs +875 -0
- package/dist/lib/primitive/string/index.d.ts +3 -0
- package/dist/lib/primitive/string/index.d.ts.map +1 -0
- package/dist/lib/primitive/string/index.js +2 -0
- package/dist/lib/primitive/string/index.mjs +852 -0
- package/dist/lib/primitive/string/parser-2.cjs +543 -0
- package/dist/lib/primitive/string/parser-2.d.ts +17 -0
- package/dist/lib/primitive/string/parser-2.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser-2.js +656 -0
- package/dist/lib/primitive/string/parser-2.mjs +522 -0
- package/dist/lib/primitive/string/parser.cjs +236 -0
- package/dist/lib/primitive/string/parser.d.ts +9 -0
- package/dist/lib/primitive/string/parser.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser.js +775 -0
- package/dist/lib/primitive/string/parser.mjs +215 -0
- package/dist/lib/primitive/string/string.cjs +926 -0
- package/dist/lib/primitive/string/string.d.ts +535 -0
- package/dist/lib/primitive/string/string.d.ts.map +1 -0
- package/dist/lib/primitive/string/string.js +1301 -0
- package/dist/lib/primitive/string/string.mjs +903 -0
- package/dist/lib/primitive/string/types.cjs +18 -0
- package/dist/lib/primitive/string/types.d.ts +318 -0
- package/dist/lib/primitive/string/types.d.ts.map +1 -0
- package/dist/lib/primitive/string/types.js +5 -0
- package/dist/lib/primitive/string/types.mjs +0 -0
- package/dist/lib/primitive/types.cjs +18 -0
- package/dist/lib/primitive/types.d.ts +27 -0
- package/dist/lib/primitive/types.d.ts.map +1 -0
- package/dist/lib/primitive/types.js +1 -0
- package/dist/lib/primitive/types.mjs +0 -0
- package/dist/lib/url/index.cjs +327 -0
- package/dist/lib/url/index.d.ts +3 -0
- package/dist/lib/url/index.d.ts.map +1 -0
- package/dist/lib/url/index.js +2 -0
- package/dist/lib/url/index.mjs +304 -0
- package/dist/lib/url/parser.cjs +325 -0
- package/dist/lib/url/parser.d.ts +216 -0
- package/dist/lib/url/parser.d.ts.map +1 -0
- package/dist/lib/url/parser.js +488 -0
- package/dist/lib/url/parser.mjs +304 -0
- package/dist/lib/url/types.cjs +18 -0
- package/dist/lib/url/types.d.ts +18 -0
- package/dist/lib/url/types.d.ts.map +1 -0
- package/dist/lib/url/types.js +1 -0
- package/dist/lib/url/types.mjs +0 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/compare/comparators.ts
|
|
21
|
+
var comparators_exports = {};
|
|
22
|
+
__export(comparators_exports, {
|
|
23
|
+
deepEqual: () => deepEqual,
|
|
24
|
+
hasLength: () => hasLength,
|
|
25
|
+
isDeepEqual: () => isDeepEqual,
|
|
26
|
+
isEqual: () => isEqual
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(comparators_exports);
|
|
29
|
+
|
|
30
|
+
// src/lib/helpers.ts
|
|
31
|
+
var import_primitive = require("@fluixi/utils/primitive");
|
|
32
|
+
var import_object = require("@fluixi/utils/object");
|
|
33
|
+
var import_array = require("@fluixi/utils/array");
|
|
34
|
+
var import_functions = require("@fluixi/utils/functions");
|
|
35
|
+
var isUndefinedOrNull = (element) => {
|
|
36
|
+
if (typeof element === "undefined" || element === null) return true;
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
function isPrimitive(v) {
|
|
40
|
+
const type = typeof v;
|
|
41
|
+
return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || (0, import_primitive.isDate)(v);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/lib/compare/comparators.ts
|
|
45
|
+
var import_object2 = require("@fluixi/utils/object");
|
|
46
|
+
var hasLength = (data) => {
|
|
47
|
+
const type = typeof data;
|
|
48
|
+
let hasValue = false;
|
|
49
|
+
if (isUndefinedOrNull(data)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
switch (type) {
|
|
53
|
+
case "string":
|
|
54
|
+
hasValue = data.length > 0;
|
|
55
|
+
break;
|
|
56
|
+
case "number":
|
|
57
|
+
hasValue = true;
|
|
58
|
+
break;
|
|
59
|
+
case "object":
|
|
60
|
+
if (Array.isArray(data)) {
|
|
61
|
+
hasValue = data.length > 0;
|
|
62
|
+
} else {
|
|
63
|
+
hasValue = Object.keys(data).length > 0;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case "boolean":
|
|
67
|
+
hasValue = data;
|
|
68
|
+
}
|
|
69
|
+
return hasValue;
|
|
70
|
+
};
|
|
71
|
+
var isDeepEqual = (compare1, compare2, keys) => {
|
|
72
|
+
if (compare1 === void 0 || compare2 === void 0) return false;
|
|
73
|
+
if (compare1 === null || compare2 === null) return compare1 === compare2;
|
|
74
|
+
if (Array.isArray(compare1) && Array.isArray(compare2)) {
|
|
75
|
+
if (compare1.length !== compare2.length) return false;
|
|
76
|
+
return compare1.every((v, i) => isDeepEqual(v, compare2[i]));
|
|
77
|
+
}
|
|
78
|
+
if (keys && keys.length > 0) {
|
|
79
|
+
if (isPrimitive(compare1) && isPrimitive(compare2))
|
|
80
|
+
return compare1 === compare2;
|
|
81
|
+
if ((0, import_object2.isObject)(compare1) && (0, import_object2.isObject)(compare2))
|
|
82
|
+
return keys.every(
|
|
83
|
+
(k) => isDeepEqual(compare1[k], compare2[k])
|
|
84
|
+
);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if ((0, import_object2.isObject)(compare1) && (0, import_object2.isObject)(compare2)) {
|
|
88
|
+
const obj1Keys = Object.keys(compare1).sort();
|
|
89
|
+
const obj2Keys = Object.keys(compare2).sort();
|
|
90
|
+
if (obj1Keys.length !== obj2Keys.length) return false;
|
|
91
|
+
return obj1Keys.every(
|
|
92
|
+
(key) => isDeepEqual(compare1[key], compare2[key])
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return compare1 === compare2;
|
|
96
|
+
};
|
|
97
|
+
function unorderedArrayEqual(a, b, opts) {
|
|
98
|
+
const used = new Uint8Array(b.length);
|
|
99
|
+
outer: for (let i = 0; i < a.length; i++) {
|
|
100
|
+
for (let j = 0; j < b.length; j++) {
|
|
101
|
+
if (!used[j] && deepEqual(a[i], b[j], opts)) {
|
|
102
|
+
used[j] = 1;
|
|
103
|
+
continue outer;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
var deepEqual = (obj1, obj2, options = {}) => {
|
|
111
|
+
if (obj1 === obj2) return true;
|
|
112
|
+
if (obj1 == null || obj2 == null) return false;
|
|
113
|
+
if (typeof obj1 !== typeof obj2) return false;
|
|
114
|
+
const isArr1 = Array.isArray(obj1);
|
|
115
|
+
const isArr2 = Array.isArray(obj2);
|
|
116
|
+
if (isArr1 !== isArr2) return false;
|
|
117
|
+
if (isArr1 && isArr2) {
|
|
118
|
+
if (obj1.length !== obj2.length) return false;
|
|
119
|
+
return options.unordered ? unorderedArrayEqual(obj1, obj2, options) : obj1.every((item, i) => deepEqual(item, obj2[i], options));
|
|
120
|
+
}
|
|
121
|
+
if (typeof obj1 !== "object") return obj1 === obj2;
|
|
122
|
+
const isDate1 = obj1 instanceof Date;
|
|
123
|
+
const isDate2 = obj2 instanceof Date;
|
|
124
|
+
if (isDate1 !== isDate2) return false;
|
|
125
|
+
if (isDate1) return obj1.getTime() === obj2.getTime();
|
|
126
|
+
const isRE1 = obj1 instanceof RegExp;
|
|
127
|
+
const isRE2 = obj2 instanceof RegExp;
|
|
128
|
+
if (isRE1 !== isRE2) return false;
|
|
129
|
+
if (isRE1) return obj1.toString() === obj2.toString();
|
|
130
|
+
const isMap1 = obj1 instanceof Map;
|
|
131
|
+
const isMap2 = obj2 instanceof Map;
|
|
132
|
+
if (isMap1 !== isMap2) return false;
|
|
133
|
+
if (isMap1) {
|
|
134
|
+
if (obj1.size !== obj2.size) return false;
|
|
135
|
+
for (const [k, v] of obj1) {
|
|
136
|
+
if (!obj2.has(k)) return false;
|
|
137
|
+
if (!deepEqual(v, obj2.get(k), options)) return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
const isSet1 = obj1 instanceof Set;
|
|
142
|
+
const isSet2 = obj2 instanceof Set;
|
|
143
|
+
if (isSet1 !== isSet2) return false;
|
|
144
|
+
if (isSet1) {
|
|
145
|
+
if (obj1.size !== obj2.size) return false;
|
|
146
|
+
const bArr = [...obj2];
|
|
147
|
+
const used = new Uint8Array(bArr.length);
|
|
148
|
+
outer: for (const v of obj1) {
|
|
149
|
+
for (let j = 0; j < bArr.length; j++) {
|
|
150
|
+
if (!used[j] && deepEqual(v, bArr[j], options)) {
|
|
151
|
+
used[j] = 1;
|
|
152
|
+
continue outer;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
if (!(0, import_object2.isObject)(obj1) || !(0, import_object2.isObject)(obj2)) return false;
|
|
160
|
+
const keys1 = Object.keys(obj1);
|
|
161
|
+
const keys2 = Object.keys(obj2);
|
|
162
|
+
if (keys1.length !== keys2.length) return false;
|
|
163
|
+
for (const key of keys1) {
|
|
164
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key)) return false;
|
|
165
|
+
if (!deepEqual(obj1[key], obj2[key], options)) return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
function isEqual(a, b) {
|
|
170
|
+
return Object.is(a, b);
|
|
171
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export declare const hasLength: (data: any) => boolean;
|
|
2
|
+
/**
|
|
3
|
+
* The isEqual function compares two objects and returns true if they are equal.
|
|
4
|
+
*
|
|
5
|
+
* @param compare1: T Define the type of object that will be passed into the function
|
|
6
|
+
* @param compare2: T Compare the two objects
|
|
7
|
+
*
|
|
8
|
+
* @return A boolean value
|
|
9
|
+
*
|
|
10
|
+
* @docauthor Ibrahima Touré
|
|
11
|
+
*/
|
|
12
|
+
export declare const isDeepEqual: <T extends string | any>(compare1: T, compare2: T, keys?: string[]) => boolean;
|
|
13
|
+
export interface DeepEqualOptions {
|
|
14
|
+
/**
|
|
15
|
+
* When `true`, arrays are compared as unordered sets: two arrays are equal
|
|
16
|
+
* if every element in the first has a deeply-equal counterpart in the second,
|
|
17
|
+
* regardless of position.
|
|
18
|
+
*
|
|
19
|
+
* The option propagates recursively, so nested arrays are also compared
|
|
20
|
+
* without order.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* deepEqual([1,2,3], [3,1,2]) // false (default)
|
|
24
|
+
* deepEqual([1,2,3], [3,1,2], { unordered: true }) // true
|
|
25
|
+
* deepEqual(
|
|
26
|
+
* [{ id: 1 }, { id: 2 }],
|
|
27
|
+
* [{ id: 2 }, { id: 1 }],
|
|
28
|
+
* { unordered: true }
|
|
29
|
+
* ) // true
|
|
30
|
+
*/
|
|
31
|
+
unordered?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Structural deep equality check.
|
|
35
|
+
*
|
|
36
|
+
* Handles: primitives, null/undefined, Date, RegExp, Array, Map, Set, and
|
|
37
|
+
* plain objects. Recurses into nested structures.
|
|
38
|
+
*
|
|
39
|
+
* @param obj1 - First value
|
|
40
|
+
* @param obj2 - Second value
|
|
41
|
+
* @param options - Comparison options (see {@link DeepEqualOptions})
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* deepEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }) // true
|
|
45
|
+
* deepEqual([1, 2, 3], [3, 2, 1]) // false
|
|
46
|
+
* deepEqual([1, 2, 3], [3, 2, 1], { unordered: true }) // true
|
|
47
|
+
* deepEqual(
|
|
48
|
+
* [{ id: 2 }, { id: 1 }],
|
|
49
|
+
* [{ id: 1 }, { id: 2 }],
|
|
50
|
+
* { unordered: true }
|
|
51
|
+
* ) // true
|
|
52
|
+
*/
|
|
53
|
+
export declare const deepEqual: (obj1: any, obj2: any, options?: DeepEqualOptions) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if two values are equal
|
|
56
|
+
* @param a - The first value to compare
|
|
57
|
+
* @param b - The second value to compare
|
|
58
|
+
* @returns True if values are equal
|
|
59
|
+
* @example
|
|
60
|
+
* isEqual(1, 1) // true
|
|
61
|
+
* isEqual(1, '1') // false
|
|
62
|
+
* isEqual(null, undefined) // false
|
|
63
|
+
*/
|
|
64
|
+
export declare function isEqual<T>(a: T, b: T): boolean;
|
|
65
|
+
//# sourceMappingURL=comparators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparators.d.ts","sourceRoot":"","sources":["../../../src/lib/compare/comparators.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,GAAI,MAAM,GAAG,YAwBlC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,GAAG,GAAG,EAChD,UAAU,CAAC,EACX,UAAU,CAAC,EACX,OAAO,MAAM,EAAE,KACd,OA6BF,CAAC;AAIF,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA8BD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS,GACpB,MAAM,GAAG,EACT,MAAM,GAAG,EACT,UAAS,gBAAqB,KAC7B,OAmFF,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAE9C"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { isPrimitive, isUndefinedOrNull } from '../helpers.js';
|
|
2
|
+
import { isObject } from '@fluixi/utils/object';
|
|
3
|
+
export const hasLength = (data) => {
|
|
4
|
+
const type = typeof data;
|
|
5
|
+
let hasValue = false;
|
|
6
|
+
if (isUndefinedOrNull(data)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
switch (type) {
|
|
10
|
+
case 'string':
|
|
11
|
+
hasValue = data.length > 0;
|
|
12
|
+
break;
|
|
13
|
+
case 'number':
|
|
14
|
+
hasValue = true;
|
|
15
|
+
break;
|
|
16
|
+
case 'object':
|
|
17
|
+
if (Array.isArray(data)) {
|
|
18
|
+
hasValue = data.length > 0;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
hasValue = Object.keys(data).length > 0;
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
case 'boolean':
|
|
25
|
+
hasValue = data;
|
|
26
|
+
}
|
|
27
|
+
return hasValue;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The isEqual function compares two objects and returns true if they are equal.
|
|
31
|
+
*
|
|
32
|
+
* @param compare1: T Define the type of object that will be passed into the function
|
|
33
|
+
* @param compare2: T Compare the two objects
|
|
34
|
+
*
|
|
35
|
+
* @return A boolean value
|
|
36
|
+
*
|
|
37
|
+
* @docauthor Ibrahima Touré
|
|
38
|
+
*/
|
|
39
|
+
export const isDeepEqual = (compare1, compare2, keys) => {
|
|
40
|
+
if (compare1 === undefined || compare2 === undefined)
|
|
41
|
+
return false;
|
|
42
|
+
if (compare1 === null || compare2 === null)
|
|
43
|
+
return compare1 === compare2;
|
|
44
|
+
if (Array.isArray(compare1) && Array.isArray(compare2)) {
|
|
45
|
+
if (compare1.length !== compare2.length)
|
|
46
|
+
return false;
|
|
47
|
+
return compare1.every((v, i) => isDeepEqual(v, compare2[i]));
|
|
48
|
+
}
|
|
49
|
+
if (keys && keys.length > 0) {
|
|
50
|
+
if (isPrimitive(compare1) && isPrimitive(compare2))
|
|
51
|
+
return compare1 === compare2;
|
|
52
|
+
if (isObject(compare1) && isObject(compare2))
|
|
53
|
+
return keys.every((k) => isDeepEqual(compare1[k], compare2[k]));
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (isObject(compare1) && isObject(compare2)) {
|
|
57
|
+
const obj1Keys = Object.keys(compare1).sort();
|
|
58
|
+
const obj2Keys = Object.keys(compare2).sort();
|
|
59
|
+
if (obj1Keys.length !== obj2Keys.length)
|
|
60
|
+
return false;
|
|
61
|
+
// Fixed: use recursive isDeepEqual instead of === for nested values
|
|
62
|
+
return obj1Keys.every((key) => isDeepEqual(compare1[key], compare2[key]));
|
|
63
|
+
}
|
|
64
|
+
return compare1 === compare2;
|
|
65
|
+
};
|
|
66
|
+
// ─── Internal helpers ─────────────────────────────────────────────────────────
|
|
67
|
+
/**
|
|
68
|
+
* O(n²) unordered array equality.
|
|
69
|
+
* Finds a unique match in `b` for every element in `a`.
|
|
70
|
+
*/
|
|
71
|
+
function unorderedArrayEqual(a, b, opts) {
|
|
72
|
+
// Each b-slot can only be consumed once
|
|
73
|
+
const used = new Uint8Array(b.length);
|
|
74
|
+
outer: for (let i = 0; i < a.length; i++) {
|
|
75
|
+
for (let j = 0; j < b.length; j++) {
|
|
76
|
+
if (!used[j] && deepEqual(a[i], b[j], opts)) {
|
|
77
|
+
used[j] = 1;
|
|
78
|
+
continue outer;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return false; // no match for a[i]
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
// ─── deepEqual ────────────────────────────────────────────────────────────────
|
|
86
|
+
/**
|
|
87
|
+
* Structural deep equality check.
|
|
88
|
+
*
|
|
89
|
+
* Handles: primitives, null/undefined, Date, RegExp, Array, Map, Set, and
|
|
90
|
+
* plain objects. Recurses into nested structures.
|
|
91
|
+
*
|
|
92
|
+
* @param obj1 - First value
|
|
93
|
+
* @param obj2 - Second value
|
|
94
|
+
* @param options - Comparison options (see {@link DeepEqualOptions})
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* deepEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }) // true
|
|
98
|
+
* deepEqual([1, 2, 3], [3, 2, 1]) // false
|
|
99
|
+
* deepEqual([1, 2, 3], [3, 2, 1], { unordered: true }) // true
|
|
100
|
+
* deepEqual(
|
|
101
|
+
* [{ id: 2 }, { id: 1 }],
|
|
102
|
+
* [{ id: 1 }, { id: 2 }],
|
|
103
|
+
* { unordered: true }
|
|
104
|
+
* ) // true
|
|
105
|
+
*/
|
|
106
|
+
export const deepEqual = (obj1, obj2, options = {}) => {
|
|
107
|
+
// Fast path: same reference, same primitive, or both null/undefined
|
|
108
|
+
if (obj1 === obj2)
|
|
109
|
+
return true;
|
|
110
|
+
// One side is null/undefined but not the other (=== already handled above)
|
|
111
|
+
if (obj1 == null || obj2 == null)
|
|
112
|
+
return false;
|
|
113
|
+
// Type mismatch
|
|
114
|
+
if (typeof obj1 !== typeof obj2)
|
|
115
|
+
return false;
|
|
116
|
+
// ── Arrays ──────────────────────────────────────────────────────────────
|
|
117
|
+
const isArr1 = Array.isArray(obj1);
|
|
118
|
+
const isArr2 = Array.isArray(obj2);
|
|
119
|
+
if (isArr1 !== isArr2)
|
|
120
|
+
return false;
|
|
121
|
+
if (isArr1 && isArr2) {
|
|
122
|
+
if (obj1.length !== obj2.length)
|
|
123
|
+
return false;
|
|
124
|
+
return options.unordered
|
|
125
|
+
? unorderedArrayEqual(obj1, obj2, options)
|
|
126
|
+
: obj1.every((item, i) => deepEqual(item, obj2[i], options));
|
|
127
|
+
}
|
|
128
|
+
// ── Primitive (non-object) types ─────────────────────────────────────────
|
|
129
|
+
if (typeof obj1 !== 'object')
|
|
130
|
+
return obj1 === obj2;
|
|
131
|
+
// ── Date ─────────────────────────────────────────────────────────────────
|
|
132
|
+
const isDate1 = obj1 instanceof Date;
|
|
133
|
+
const isDate2 = obj2 instanceof Date;
|
|
134
|
+
if (isDate1 !== isDate2)
|
|
135
|
+
return false;
|
|
136
|
+
if (isDate1)
|
|
137
|
+
return obj1.getTime() === obj2.getTime();
|
|
138
|
+
// ── RegExp ───────────────────────────────────────────────────────────────
|
|
139
|
+
const isRE1 = obj1 instanceof RegExp;
|
|
140
|
+
const isRE2 = obj2 instanceof RegExp;
|
|
141
|
+
if (isRE1 !== isRE2)
|
|
142
|
+
return false;
|
|
143
|
+
if (isRE1)
|
|
144
|
+
return obj1.toString() === obj2.toString();
|
|
145
|
+
// ── Map ──────────────────────────────────────────────────────────────────
|
|
146
|
+
const isMap1 = obj1 instanceof Map;
|
|
147
|
+
const isMap2 = obj2 instanceof Map;
|
|
148
|
+
if (isMap1 !== isMap2)
|
|
149
|
+
return false;
|
|
150
|
+
if (isMap1) {
|
|
151
|
+
if (obj1.size !== obj2.size)
|
|
152
|
+
return false;
|
|
153
|
+
for (const [k, v] of obj1) {
|
|
154
|
+
if (!obj2.has(k))
|
|
155
|
+
return false;
|
|
156
|
+
if (!deepEqual(v, obj2.get(k), options))
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
// ── Set ──────────────────────────────────────────────────────────────────
|
|
162
|
+
const isSet1 = obj1 instanceof Set;
|
|
163
|
+
const isSet2 = obj2 instanceof Set;
|
|
164
|
+
if (isSet1 !== isSet2)
|
|
165
|
+
return false;
|
|
166
|
+
if (isSet1) {
|
|
167
|
+
if (obj1.size !== obj2.size)
|
|
168
|
+
return false;
|
|
169
|
+
// Sets are inherently unordered; use the unordered algorithm for deep items
|
|
170
|
+
const bArr = [...obj2];
|
|
171
|
+
const used = new Uint8Array(bArr.length);
|
|
172
|
+
outer: for (const v of obj1) {
|
|
173
|
+
for (let j = 0; j < bArr.length; j++) {
|
|
174
|
+
if (!used[j] && deepEqual(v, bArr[j], options)) {
|
|
175
|
+
used[j] = 1;
|
|
176
|
+
continue outer;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
// ── Plain objects ─────────────────────────────────────────────────────────
|
|
184
|
+
if (!isObject(obj1) || !isObject(obj2))
|
|
185
|
+
return false;
|
|
186
|
+
const keys1 = Object.keys(obj1);
|
|
187
|
+
const keys2 = Object.keys(obj2);
|
|
188
|
+
if (keys1.length !== keys2.length)
|
|
189
|
+
return false;
|
|
190
|
+
for (const key of keys1) {
|
|
191
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key))
|
|
192
|
+
return false;
|
|
193
|
+
if (!deepEqual(obj1[key], obj2[key], options))
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Checks if two values are equal
|
|
200
|
+
* @param a - The first value to compare
|
|
201
|
+
* @param b - The second value to compare
|
|
202
|
+
* @returns True if values are equal
|
|
203
|
+
* @example
|
|
204
|
+
* isEqual(1, 1) // true
|
|
205
|
+
* isEqual(1, '1') // false
|
|
206
|
+
* isEqual(null, undefined) // false
|
|
207
|
+
*/
|
|
208
|
+
export function isEqual(a, b) {
|
|
209
|
+
return Object.is(a, b);
|
|
210
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/lib/helpers.ts
|
|
2
|
+
import {
|
|
3
|
+
isDate
|
|
4
|
+
} from "@fluixi/utils/primitive";
|
|
5
|
+
import { isClass, isObject } from "@fluixi/utils/object";
|
|
6
|
+
import { isArray } from "@fluixi/utils/array";
|
|
7
|
+
import { isFunction } from "@fluixi/utils/functions";
|
|
8
|
+
var isUndefinedOrNull = (element) => {
|
|
9
|
+
if (typeof element === "undefined" || element === null) return true;
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
function isPrimitive(v) {
|
|
13
|
+
const type = typeof v;
|
|
14
|
+
return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || isDate(v);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/lib/compare/comparators.ts
|
|
18
|
+
import { isObject as isObject2 } from "@fluixi/utils/object";
|
|
19
|
+
var hasLength = (data) => {
|
|
20
|
+
const type = typeof data;
|
|
21
|
+
let hasValue = false;
|
|
22
|
+
if (isUndefinedOrNull(data)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
switch (type) {
|
|
26
|
+
case "string":
|
|
27
|
+
hasValue = data.length > 0;
|
|
28
|
+
break;
|
|
29
|
+
case "number":
|
|
30
|
+
hasValue = true;
|
|
31
|
+
break;
|
|
32
|
+
case "object":
|
|
33
|
+
if (Array.isArray(data)) {
|
|
34
|
+
hasValue = data.length > 0;
|
|
35
|
+
} else {
|
|
36
|
+
hasValue = Object.keys(data).length > 0;
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case "boolean":
|
|
40
|
+
hasValue = data;
|
|
41
|
+
}
|
|
42
|
+
return hasValue;
|
|
43
|
+
};
|
|
44
|
+
var isDeepEqual = (compare1, compare2, keys) => {
|
|
45
|
+
if (compare1 === void 0 || compare2 === void 0) return false;
|
|
46
|
+
if (compare1 === null || compare2 === null) return compare1 === compare2;
|
|
47
|
+
if (Array.isArray(compare1) && Array.isArray(compare2)) {
|
|
48
|
+
if (compare1.length !== compare2.length) return false;
|
|
49
|
+
return compare1.every((v, i) => isDeepEqual(v, compare2[i]));
|
|
50
|
+
}
|
|
51
|
+
if (keys && keys.length > 0) {
|
|
52
|
+
if (isPrimitive(compare1) && isPrimitive(compare2))
|
|
53
|
+
return compare1 === compare2;
|
|
54
|
+
if (isObject2(compare1) && isObject2(compare2))
|
|
55
|
+
return keys.every(
|
|
56
|
+
(k) => isDeepEqual(compare1[k], compare2[k])
|
|
57
|
+
);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (isObject2(compare1) && isObject2(compare2)) {
|
|
61
|
+
const obj1Keys = Object.keys(compare1).sort();
|
|
62
|
+
const obj2Keys = Object.keys(compare2).sort();
|
|
63
|
+
if (obj1Keys.length !== obj2Keys.length) return false;
|
|
64
|
+
return obj1Keys.every(
|
|
65
|
+
(key) => isDeepEqual(compare1[key], compare2[key])
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return compare1 === compare2;
|
|
69
|
+
};
|
|
70
|
+
function unorderedArrayEqual(a, b, opts) {
|
|
71
|
+
const used = new Uint8Array(b.length);
|
|
72
|
+
outer: for (let i = 0; i < a.length; i++) {
|
|
73
|
+
for (let j = 0; j < b.length; j++) {
|
|
74
|
+
if (!used[j] && deepEqual(a[i], b[j], opts)) {
|
|
75
|
+
used[j] = 1;
|
|
76
|
+
continue outer;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
var deepEqual = (obj1, obj2, options = {}) => {
|
|
84
|
+
if (obj1 === obj2) return true;
|
|
85
|
+
if (obj1 == null || obj2 == null) return false;
|
|
86
|
+
if (typeof obj1 !== typeof obj2) return false;
|
|
87
|
+
const isArr1 = Array.isArray(obj1);
|
|
88
|
+
const isArr2 = Array.isArray(obj2);
|
|
89
|
+
if (isArr1 !== isArr2) return false;
|
|
90
|
+
if (isArr1 && isArr2) {
|
|
91
|
+
if (obj1.length !== obj2.length) return false;
|
|
92
|
+
return options.unordered ? unorderedArrayEqual(obj1, obj2, options) : obj1.every((item, i) => deepEqual(item, obj2[i], options));
|
|
93
|
+
}
|
|
94
|
+
if (typeof obj1 !== "object") return obj1 === obj2;
|
|
95
|
+
const isDate1 = obj1 instanceof Date;
|
|
96
|
+
const isDate2 = obj2 instanceof Date;
|
|
97
|
+
if (isDate1 !== isDate2) return false;
|
|
98
|
+
if (isDate1) return obj1.getTime() === obj2.getTime();
|
|
99
|
+
const isRE1 = obj1 instanceof RegExp;
|
|
100
|
+
const isRE2 = obj2 instanceof RegExp;
|
|
101
|
+
if (isRE1 !== isRE2) return false;
|
|
102
|
+
if (isRE1) return obj1.toString() === obj2.toString();
|
|
103
|
+
const isMap1 = obj1 instanceof Map;
|
|
104
|
+
const isMap2 = obj2 instanceof Map;
|
|
105
|
+
if (isMap1 !== isMap2) return false;
|
|
106
|
+
if (isMap1) {
|
|
107
|
+
if (obj1.size !== obj2.size) return false;
|
|
108
|
+
for (const [k, v] of obj1) {
|
|
109
|
+
if (!obj2.has(k)) return false;
|
|
110
|
+
if (!deepEqual(v, obj2.get(k), options)) return false;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
const isSet1 = obj1 instanceof Set;
|
|
115
|
+
const isSet2 = obj2 instanceof Set;
|
|
116
|
+
if (isSet1 !== isSet2) return false;
|
|
117
|
+
if (isSet1) {
|
|
118
|
+
if (obj1.size !== obj2.size) return false;
|
|
119
|
+
const bArr = [...obj2];
|
|
120
|
+
const used = new Uint8Array(bArr.length);
|
|
121
|
+
outer: for (const v of obj1) {
|
|
122
|
+
for (let j = 0; j < bArr.length; j++) {
|
|
123
|
+
if (!used[j] && deepEqual(v, bArr[j], options)) {
|
|
124
|
+
used[j] = 1;
|
|
125
|
+
continue outer;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (!isObject2(obj1) || !isObject2(obj2)) return false;
|
|
133
|
+
const keys1 = Object.keys(obj1);
|
|
134
|
+
const keys2 = Object.keys(obj2);
|
|
135
|
+
if (keys1.length !== keys2.length) return false;
|
|
136
|
+
for (const key of keys1) {
|
|
137
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key)) return false;
|
|
138
|
+
if (!deepEqual(obj1[key], obj2[key], options)) return false;
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
function isEqual(a, b) {
|
|
143
|
+
return Object.is(a, b);
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
deepEqual,
|
|
147
|
+
hasLength,
|
|
148
|
+
isDeepEqual,
|
|
149
|
+
isEqual
|
|
150
|
+
};
|