@rcompat/test 0.0.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/LICENSE +19 -0
- package/lib/private/equals.d.ts +3 -0
- package/lib/private/equals.js +22 -0
- package/lib/private/includes.d.ts +3 -0
- package/lib/private/includes.js +22 -0
- package/lib/private/to-object.d.ts +6 -0
- package/lib/private/to-object.js +2 -0
- package/lib/private/types/array.d.ts +8 -0
- package/lib/private/types/array.js +28 -0
- package/lib/private/types/date.d.ts +8 -0
- package/lib/private/types/date.js +6 -0
- package/lib/private/types/map.d.ts +9 -0
- package/lib/private/types/map.js +8 -0
- package/lib/private/types/null.d.ts +5 -0
- package/lib/private/types/null.js +3 -0
- package/lib/private/types/record.d.ts +9 -0
- package/lib/private/types/record.js +10 -0
- package/lib/private/types/scalar.d.ts +10 -0
- package/lib/private/types/scalar.js +7 -0
- package/lib/private/types/set.d.ts +9 -0
- package/lib/private/types/set.js +12 -0
- package/lib/private/types/string.d.ts +8 -0
- package/lib/private/types/string.js +6 -0
- package/lib/public/equals.d.ts +2 -0
- package/lib/public/equals.js +2 -0
- package/lib/public/includes.d.ts +2 -0
- package/lib/public/includes.js +2 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) Terrablue <terrablue@proton.me> and contributors.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import array from "#types/array";
|
|
2
|
+
import date from "#types/date";
|
|
3
|
+
import map from "#types/map";
|
|
4
|
+
import nul from "#types/null";
|
|
5
|
+
import record from "#types/record";
|
|
6
|
+
import scalar from "#types/scalar";
|
|
7
|
+
import set from "#types/set";
|
|
8
|
+
const checks = [
|
|
9
|
+
[scalar.is, (x, y) => scalar.is(y) && scalar.equal(x, y)],
|
|
10
|
+
[nul.is, (_, y) => nul.is(y)],
|
|
11
|
+
[date.is, (x, y) => date.is(y) && date.equal(x, y)],
|
|
12
|
+
[array.is, (x, y) => array.is(y) && array.equal(x, y)],
|
|
13
|
+
[set.is, (x, y) => set.is(y) && set.equal(x, y)],
|
|
14
|
+
[map.is, (x, y) => map.is(y) && map.equal(x, y)],
|
|
15
|
+
[record.is, (x, y) => record.is(y) && record.equal(x, y)],
|
|
16
|
+
[(_) => true, (_, _1) => false]
|
|
17
|
+
];
|
|
18
|
+
const equals = (x, y) => typeof x === typeof y
|
|
19
|
+
? checks.find(([predicate]) => predicate(x))[1](x, y)
|
|
20
|
+
: false;
|
|
21
|
+
export { equals as default };
|
|
22
|
+
//# sourceMappingURL=equals.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import equals from "#equals";
|
|
2
|
+
import array from "#types/array";
|
|
3
|
+
import date from "#types/date";
|
|
4
|
+
import map from "#types/map";
|
|
5
|
+
import record from "#types/record";
|
|
6
|
+
import set from "#types/set";
|
|
7
|
+
import string from "#types/string";
|
|
8
|
+
const includes = (x, y) => typeof x === typeof y
|
|
9
|
+
? equals(x, y)
|
|
10
|
+
? true
|
|
11
|
+
: [
|
|
12
|
+
[string.is, (x, y) => string.is(y) && string.include(x, y)],
|
|
13
|
+
[date.is, (x, y) => date.is(y) && date.include(x, y)],
|
|
14
|
+
[array.is, (x, y) => array.is(y) && array.include(x, y)],
|
|
15
|
+
[set.is, (x, y) => set.is(y) && set.include(x, y)],
|
|
16
|
+
[map.is, (x, y) => map.is(y) && map.include(x, y)],
|
|
17
|
+
[record.is, (x, y) => record.is(y) && record.include(x, y)],
|
|
18
|
+
[() => true, () => false],
|
|
19
|
+
].find(([predicate]) => predicate(x))[1](x, y)
|
|
20
|
+
: false;
|
|
21
|
+
export { includes as default };
|
|
22
|
+
//# sourceMappingURL=includes.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
equal: <T extends unknown[]>(x: T, y: T) => boolean;
|
|
3
|
+
include: <T extends unknown[]>(x: T, y: T) => boolean;
|
|
4
|
+
is: (x: unknown) => x is unknown[];
|
|
5
|
+
partial: <t extends unknown[]>(x: t, y: t) => boolean;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import equals from "#equals";
|
|
2
|
+
import includes from "#includes";
|
|
3
|
+
const is = (x) => Array.isArray(x);
|
|
4
|
+
const partial = (x, y) => x.reduce((equal, xi, i) => equal && equals(xi, y[i]), true);
|
|
5
|
+
const equal = (x, y) => partial(x, y) && partial(y, x);
|
|
6
|
+
const include = (x, y) => {
|
|
7
|
+
// empty array is always included
|
|
8
|
+
if (y.length === 0) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (x.length < y.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
// find index of first member
|
|
15
|
+
const index = x.findIndex(m => includes(m, y[0]));
|
|
16
|
+
// not found
|
|
17
|
+
if (index === -1) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// assert subarray size can match
|
|
21
|
+
if (x.slice(index).length < y.length) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
// compare rest of members from y[1]]
|
|
25
|
+
return y.slice(1).reduce((included, member, i) => included && includes(x[index + i + 1], member), true);
|
|
26
|
+
};
|
|
27
|
+
export default { equal, include, is, partial };
|
|
28
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
equal: <T extends Date>(x: T, y: T) => boolean;
|
|
3
|
+
include: <T extends Date>(x: T, y: T) => boolean;
|
|
4
|
+
is: (x: unknown) => x is Date;
|
|
5
|
+
partial: <T extends Date>(x: T, y: T) => boolean;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type UnknownMap = Map<PropertyKey, unknown>;
|
|
2
|
+
declare const _default: {
|
|
3
|
+
equal: <T extends UnknownMap>(x: T, y: T) => boolean;
|
|
4
|
+
include: <T extends UnknownMap>(x: T, y: T) => boolean;
|
|
5
|
+
is: (x: unknown) => x is UnknownMap;
|
|
6
|
+
partial: <T extends UnknownMap>(x: T, y: T) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import to_object from "#to-object";
|
|
2
|
+
import record from "#types/record";
|
|
3
|
+
const is = (x) => x instanceof Map;
|
|
4
|
+
const include = (x, y) => record.include(to_object(x), to_object(y));
|
|
5
|
+
const equal = (x, y) => record.equal(to_object(x), to_object(y));
|
|
6
|
+
const partial = equal;
|
|
7
|
+
export default { equal, include, is, partial };
|
|
8
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Dictionary from "@rcompat/record/Dictionary";
|
|
2
|
+
declare const _default: {
|
|
3
|
+
equal: <T extends Dictionary>(x: T, y: T) => boolean;
|
|
4
|
+
include: <T extends Dictionary>(x: T, y: T) => boolean;
|
|
5
|
+
is: (x: unknown) => x is Dictionary;
|
|
6
|
+
partial: <t extends Dictionary>(x: t, y: t) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import equals from "#equals";
|
|
2
|
+
import includes from "#includes";
|
|
3
|
+
const is_null = (x) => x === null;
|
|
4
|
+
const is = (x) => typeof x === "object" && !is_null(x);
|
|
5
|
+
const partial = (x, y) => Object.keys(x).reduce((equal, key) => equal && equals(x[key], y[key]), true);
|
|
6
|
+
const equal = (x, y) => Object.keys(x).length === Object.keys(y).length && partial(x, y);
|
|
7
|
+
const include = (x, y) => Object.keys(x).length >= Object.keys(y).length &&
|
|
8
|
+
Object.keys(y).reduce((included, key) => included && includes(x[key], y[key]), true);
|
|
9
|
+
export default { equal, include, is, partial };
|
|
10
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const scalars: string[];
|
|
2
|
+
type Scalar = typeof scalars[number];
|
|
3
|
+
declare const _default: {
|
|
4
|
+
equal: <T>(x: T, y: T) => boolean;
|
|
5
|
+
include: <T>(x: T, y: T) => boolean;
|
|
6
|
+
is: (x: unknown) => x is Scalar;
|
|
7
|
+
partial: <T>(x: T, y: T) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=scalar.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const scalars = ["bigint", "boolean", "number", "string", "symbol", "undefined"];
|
|
2
|
+
const is = (x) => scalars.includes(typeof x);
|
|
3
|
+
const equal = (x, y) => x === y || Object.is(x, y);
|
|
4
|
+
const include = equal;
|
|
5
|
+
const partial = equal;
|
|
6
|
+
export default { equal, include, is, partial };
|
|
7
|
+
//# sourceMappingURL=scalar.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type UnknownSet = Set<unknown>;
|
|
2
|
+
declare const _default: {
|
|
3
|
+
equal: <T extends UnknownSet>(x: T, y: T) => boolean;
|
|
4
|
+
include: <T extends UnknownSet>(x: T, y: T) => boolean;
|
|
5
|
+
is: (x: unknown) => x is UnknownSet;
|
|
6
|
+
partial: <t extends unknown[]>(x: t, y: t) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=set.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import equals from "#equals";
|
|
2
|
+
import includes from "#includes";
|
|
3
|
+
const is = (x) => x instanceof Set;
|
|
4
|
+
const partial = (x, y) => x.reduce((equal, xi) => equal && y.find(yj => equals(yj, xi)) !== undefined, true);
|
|
5
|
+
const equal = (x, y) => x.isSubsetOf(y) && y.isSubsetOf(x)
|
|
6
|
+
|| x.size === y.size
|
|
7
|
+
&& partial([...x], [...y])
|
|
8
|
+
&& partial([...y], [...x]);
|
|
9
|
+
const deep_compare = (x, y) => y.reduce((included, yi) => included && x.find(xj => includes(xj, yi)) !== undefined, true);
|
|
10
|
+
const include = (x, y) => y.isSubsetOf(x) || x.size >= y.size && deep_compare([...x], [...y]);
|
|
11
|
+
export default { equal, include, is, partial };
|
|
12
|
+
//# sourceMappingURL=set.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
equal: <T extends string>(x: T, y: T) => boolean;
|
|
3
|
+
include: <T extends string>(x: T, y: T) => boolean;
|
|
4
|
+
is: (x: unknown) => x is string;
|
|
5
|
+
partial: <T extends string>(x: T, y: T) => boolean;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=string.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rcompat/test",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "test module",
|
|
5
|
+
"bugs": "https://github.com/rcompat/rcompat/issues",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"/lib/**/*.js",
|
|
9
|
+
"/lib/**/*.d.ts",
|
|
10
|
+
"!/**/*.spec.*"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/rcompat/rcompat",
|
|
15
|
+
"directory": "packages/test"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@rcompat/record": "^0.6.1",
|
|
19
|
+
"@rcompat/core": "^0.6.0"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"imports": {
|
|
23
|
+
"#types/*": {
|
|
24
|
+
"livetypes": "./src/private/types/*.ts",
|
|
25
|
+
"default": "./lib/private/types/*.js"
|
|
26
|
+
},
|
|
27
|
+
"#*": {
|
|
28
|
+
"livetypes": "./src/private/*.ts",
|
|
29
|
+
"default": "./lib/private/*.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
"./*": {
|
|
34
|
+
"livetypes": "./src/public/*.ts",
|
|
35
|
+
"default": "./lib/public/*.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "npm run clean && tsc",
|
|
40
|
+
"clean": "rm -rf ./lib",
|
|
41
|
+
"test": "tsx --conditions=livetypes ../../node_modules/debris/src/bin.js"
|
|
42
|
+
}
|
|
43
|
+
}
|