@alexaegis/predicate 0.2.4

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/index.cjs ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const not = (predicate2) => {
4
+ return (value) => !predicate2(value);
5
+ };
6
+ const equal = (criteria) => {
7
+ return (value) => value === criteria;
8
+ };
9
+ const and = (...predicates) => {
10
+ return (value) => predicates.every((predicate2) => predicate2(value));
11
+ };
12
+ const or = (...predicates) => {
13
+ return (value) => predicates.some((predicate2) => predicate2(value));
14
+ };
15
+ const contains = (criteria) => {
16
+ return (value) => value.includes(criteria);
17
+ };
18
+ const matchRegExp = (criteria) => {
19
+ return (value) => criteria.test(value);
20
+ };
21
+ const predicate = {
22
+ not,
23
+ equal,
24
+ and,
25
+ or,
26
+ contains,
27
+ matchRegExp
28
+ };
29
+ exports.and = and;
30
+ exports.contains = contains;
31
+ exports.equal = equal;
32
+ exports.matchRegExp = matchRegExp;
33
+ exports.not = not;
34
+ exports.or = or;
35
+ exports.predicate = predicate;
36
+ //# sourceMappingURL=index.cjs.map
package/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/internal/predicates.ts"],"sourcesContent":["export type Predicate<T> = (value: T) => boolean;\n\nexport const not = <T>(predicate: Predicate<T>): Predicate<T> => {\n\treturn (value: T): boolean => !predicate(value);\n};\n\nexport const equal = <T>(criteria: T) => {\n\treturn (value: T): value is T => value === criteria;\n};\n\nexport const and = <T>(...predicates: Predicate<T>[]): Predicate<T> => {\n\treturn (value: T): boolean => predicates.every((predicate) => predicate(value));\n};\n\nexport const or = <T>(...predicates: Predicate<T>[]): Predicate<T> => {\n\treturn (value: T): boolean => predicates.some((predicate) => predicate(value));\n};\n\nexport const contains = <T extends string>(criteria: T): Predicate<string> => {\n\treturn (value: T | string): value is string => value.includes(criteria);\n};\n\nexport const matchRegExp = <T extends string>(criteria: RegExp): Predicate<string> => {\n\treturn (value: T | string): value is string => criteria.test(value);\n};\n\nexport const predicate = {\n\tnot,\n\tequal,\n\tand,\n\tor,\n\tcontains,\n\tmatchRegExp,\n} as const;\n"],"names":["predicate"],"mappings":";;AAEa,MAAA,MAAM,CAAIA,eAA0C;AAChE,SAAO,CAAC,UAAsB,CAACA,WAAU,KAAK;AAC/C;AAEa,MAAA,QAAQ,CAAI,aAAgB;AACjC,SAAA,CAAC,UAAyB,UAAU;AAC5C;AAEa,MAAA,MAAM,IAAO,eAA6C;AAC/D,SAAA,CAAC,UAAsB,WAAW,MAAM,CAACA,eAAcA,WAAU,KAAK,CAAC;AAC/E;AAEa,MAAA,KAAK,IAAO,eAA6C;AAC9D,SAAA,CAAC,UAAsB,WAAW,KAAK,CAACA,eAAcA,WAAU,KAAK,CAAC;AAC9E;AAEa,MAAA,WAAW,CAAmB,aAAmC;AAC7E,SAAO,CAAC,UAAuC,MAAM,SAAS,QAAQ;AACvE;AAEa,MAAA,cAAc,CAAmB,aAAwC;AACrF,SAAO,CAAC,UAAuC,SAAS,KAAK,KAAK;AACnE;AAEO,MAAM,YAAY;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;;;;;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './internal/predicates.js';
2
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
package/index.js ADDED
@@ -0,0 +1,36 @@
1
+ const not = (predicate2) => {
2
+ return (value) => !predicate2(value);
3
+ };
4
+ const equal = (criteria) => {
5
+ return (value) => value === criteria;
6
+ };
7
+ const and = (...predicates) => {
8
+ return (value) => predicates.every((predicate2) => predicate2(value));
9
+ };
10
+ const or = (...predicates) => {
11
+ return (value) => predicates.some((predicate2) => predicate2(value));
12
+ };
13
+ const contains = (criteria) => {
14
+ return (value) => value.includes(criteria);
15
+ };
16
+ const matchRegExp = (criteria) => {
17
+ return (value) => criteria.test(value);
18
+ };
19
+ const predicate = {
20
+ not,
21
+ equal,
22
+ and,
23
+ or,
24
+ contains,
25
+ matchRegExp
26
+ };
27
+ export {
28
+ and,
29
+ contains,
30
+ equal,
31
+ matchRegExp,
32
+ not,
33
+ or,
34
+ predicate
35
+ };
36
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/internal/predicates.ts"],"sourcesContent":["export type Predicate<T> = (value: T) => boolean;\n\nexport const not = <T>(predicate: Predicate<T>): Predicate<T> => {\n\treturn (value: T): boolean => !predicate(value);\n};\n\nexport const equal = <T>(criteria: T) => {\n\treturn (value: T): value is T => value === criteria;\n};\n\nexport const and = <T>(...predicates: Predicate<T>[]): Predicate<T> => {\n\treturn (value: T): boolean => predicates.every((predicate) => predicate(value));\n};\n\nexport const or = <T>(...predicates: Predicate<T>[]): Predicate<T> => {\n\treturn (value: T): boolean => predicates.some((predicate) => predicate(value));\n};\n\nexport const contains = <T extends string>(criteria: T): Predicate<string> => {\n\treturn (value: T | string): value is string => value.includes(criteria);\n};\n\nexport const matchRegExp = <T extends string>(criteria: RegExp): Predicate<string> => {\n\treturn (value: T | string): value is string => criteria.test(value);\n};\n\nexport const predicate = {\n\tnot,\n\tequal,\n\tand,\n\tor,\n\tcontains,\n\tmatchRegExp,\n} as const;\n"],"names":["predicate"],"mappings":"AAEa,MAAA,MAAM,CAAIA,eAA0C;AAChE,SAAO,CAAC,UAAsB,CAACA,WAAU,KAAK;AAC/C;AAEa,MAAA,QAAQ,CAAI,aAAgB;AACjC,SAAA,CAAC,UAAyB,UAAU;AAC5C;AAEa,MAAA,MAAM,IAAO,eAA6C;AAC/D,SAAA,CAAC,UAAsB,WAAW,MAAM,CAACA,eAAcA,WAAU,KAAK,CAAC;AAC/E;AAEa,MAAA,KAAK,IAAO,eAA6C;AAC9D,SAAA,CAAC,UAAsB,WAAW,KAAK,CAACA,eAAcA,WAAU,KAAK,CAAC;AAC9E;AAEa,MAAA,WAAW,CAAmB,aAAmC;AAC7E,SAAO,CAAC,UAAuC,MAAM,SAAS,QAAQ;AACvE;AAEa,MAAA,cAAc,CAAmB,aAAwC;AACrF,SAAO,CAAC,UAAuC,SAAS,KAAK,KAAK;AACnE;AAEO,MAAM,YAAY;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;"}
@@ -0,0 +1,16 @@
1
+ export type Predicate<T> = (value: T) => boolean;
2
+ export declare const not: <T>(predicate: Predicate<T>) => Predicate<T>;
3
+ export declare const equal: <T>(criteria: T) => (value: T) => value is T;
4
+ export declare const and: <T>(...predicates: Predicate<T>[]) => Predicate<T>;
5
+ export declare const or: <T>(...predicates: Predicate<T>[]) => Predicate<T>;
6
+ export declare const contains: <T extends string>(criteria: T) => Predicate<string>;
7
+ export declare const matchRegExp: <T extends string>(criteria: RegExp) => Predicate<string>;
8
+ export declare const predicate: {
9
+ readonly not: <T>(predicate: Predicate<T>) => Predicate<T>;
10
+ readonly equal: <T_1>(criteria: T_1) => (value: T_1) => value is T_1;
11
+ readonly and: <T_2>(...predicates: Predicate<T_2>[]) => Predicate<T_2>;
12
+ readonly or: <T_3>(...predicates: Predicate<T_3>[]) => Predicate<T_3>;
13
+ readonly contains: <T_4 extends string>(criteria: T_4) => Predicate<string>;
14
+ readonly matchRegExp: <T_5 extends string>(criteria: RegExp) => Predicate<string>;
15
+ };
16
+ //# sourceMappingURL=predicates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../../src/internal/predicates.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AAEjD,eAAO,MAAM,GAAG,8CAEf,CAAC;AAEF,eAAO,MAAM,KAAK,8CAEjB,CAAC;AAEF,eAAO,MAAM,GAAG,oDAEf,CAAC;AAEF,eAAO,MAAM,EAAE,oDAEd,CAAC;AAEF,eAAO,MAAM,QAAQ,qCAAoC,UAAU,MAAM,CAExE,CAAC;AAEF,eAAO,MAAM,WAAW,+BAAgC,MAAM,KAAG,UAAU,MAAM,CAEhF,CAAC;AAEF,eAAO,MAAM,SAAS;;;;;8DARmC,UAAU,MAAM,CAAC;yDAIlB,MAAM,KAAG,UAAU,MAAM,CAAC;CAWxE,CAAC"}
package/license ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Győri Sándor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@alexaegis/predicate",
3
+ "description": "Dead simple declarative predicates",
4
+ "version": "0.2.4",
5
+ "license": "MIT",
6
+ "private": false,
7
+ "archetype": {
8
+ "platform": "node",
9
+ "language": "ts",
10
+ "kind": "lib"
11
+ },
12
+ "keywords": [
13
+ "filter",
14
+ "git",
15
+ "managed-by-autotool",
16
+ "match",
17
+ "matcher",
18
+ "object",
19
+ "query"
20
+ ],
21
+ "author": {
22
+ "email": "alexaegis@gmail.com",
23
+ "name": "Alex Aegis",
24
+ "url": "https://github.com/AlexAegis"
25
+ },
26
+ "repository": {
27
+ "url": "https://github.com/AlexAegis/js-core",
28
+ "type": "git",
29
+ "directory": "packages/predicate"
30
+ },
31
+ "bugs": {
32
+ "email": "alexaegis@gmail.com",
33
+ "url": "https://github.com/AlexAegis/js-core/issues"
34
+ },
35
+ "type": "module",
36
+ "config": {
37
+ "engine-strict": true
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "engines": {
43
+ "node": ">=18.10.0",
44
+ "pnpm": ">=8.0.0"
45
+ },
46
+ "exports": {
47
+ ".": {
48
+ "types": "./index.d.ts",
49
+ "import": "./index.js",
50
+ "require": "./index.cjs",
51
+ "default": "./index.js"
52
+ },
53
+ "./readme": "./readme.md"
54
+ },
55
+ "devDependencies": {
56
+ "@alexaegis/eslint-config-vitest": "^0.3.3",
57
+ "@alexaegis/ts": "^0.3.3",
58
+ "@alexaegis/vite": "^0.3.3",
59
+ "@alexaegis/vitest": "^0.3.3",
60
+ "@types/node": "^20.3.2",
61
+ "publint": "^0.1.12",
62
+ "typescript": "^5.1.5",
63
+ "vite": "^4.3.9",
64
+ "vitest": "^0.32.2"
65
+ },
66
+ "scripts": {
67
+ "build": "turbo run build-lib_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
68
+ "build-lib_": "vite build",
69
+ "lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
70
+ "lint:depcheck_": "depcheck",
71
+ "lint:es": "turbo run lint:es_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
72
+ "lint:es_": "eslint --max-warnings=0 --fix --no-error-on-unmatched-pattern .",
73
+ "lint:format": "turbo run lint:format_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
74
+ "lint:format_": "prettier --no-plugin-search --cache-location .cache/prettier --check .",
75
+ "lint:md": "turbo run lint:md_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
76
+ "lint:md_": "remark --frail --no-stdout --silently-ignore .",
77
+ "lint:tsc": "turbo run lint:tsc_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
78
+ "lint:tsc_": "tsc --noEmit",
79
+ "publint": "turbo run publint_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
80
+ "publint_": "publint dist",
81
+ "all": "turbo run all_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
82
+ "format": "turbo run format_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
83
+ "format_": "prettier --no-plugin-search --cache-location .cache/prettier --write .",
84
+ "test": "turbo run test_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/predicate",
85
+ "test_": "vitest --passWithNoTests --coverage --run",
86
+ "test:watch": "vitest --passWithNoTests --coverage"
87
+ }
88
+ }
package/readme.md ADDED
@@ -0,0 +1,18 @@
1
+ # [@alexaegis/predicate](https://github.com/AlexAegis/js-core/tree/master/packages/predicate)
2
+
3
+ [![npm](https://img.shields.io/npm/v/@alexaegis/predicate/latest)](https://www.npmjs.com/package/@alexaegis/predicate)
4
+ [![ci](https://github.com/AlexAegis/js-core/actions/workflows/cicd.yml/badge.svg)](https://github.com/AlexAegis/js-core/actions/workflows/cicd.yml)
5
+ [![codacy](https://app.codacy.com/project/badge/Grade/402dd6d7fcbd4cde86fdf8e7d948fcde)](https://www.codacy.com/gh/AlexAegis/js-core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AlexAegis/js-core&utm_campaign=Badge_Grade)
6
+ [![codecov](https://codecov.io/gh/AlexAegis/js-core/branch/master/graph/badge.svg?token=kw8ZeoPbUh)](https://codecov.io/gh/AlexAegis/js-core)
7
+
8
+ Dead simple declarative predicates
9
+
10
+ ```ts
11
+ import { and, equal, contains } from '@alexaegis/predicate';
12
+
13
+ const predicate = or(and(contains('fo'), contains('oo')), equal('bar'));
14
+
15
+ predicate('foo'); // true
16
+ predicate('bar'); // true
17
+ predicate('zed'); // false
18
+ ```