@briza/illogical 1.4.3 → 1.5.2

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.
Files changed (35) hide show
  1. package/changelog.md +13 -0
  2. package/lib/illogical.esm.js +82 -176
  3. package/lib/illogical.js +82 -175
  4. package/package.json +23 -23
  5. package/readme.md +21 -7
  6. package/types/common/evaluable.d.ts +57 -57
  7. package/types/common/type-check.d.ts +28 -32
  8. package/types/common/util.d.ts +11 -11
  9. package/types/expression/comparison/eq.d.ts +18 -22
  10. package/types/expression/comparison/ge.d.ts +18 -22
  11. package/types/expression/comparison/gt.d.ts +18 -22
  12. package/types/expression/comparison/in.d.ts +23 -27
  13. package/types/expression/comparison/index.d.ts +45 -49
  14. package/types/expression/comparison/le.d.ts +18 -22
  15. package/types/expression/comparison/lt.d.ts +18 -22
  16. package/types/expression/comparison/ne.d.ts +18 -22
  17. package/types/expression/comparison/not-in.d.ts +23 -27
  18. package/types/expression/comparison/overlap.d.ts +23 -27
  19. package/types/expression/comparison/prefix.d.ts +23 -27
  20. package/types/expression/comparison/present.d.ts +25 -29
  21. package/types/expression/comparison/suffix.d.ts +23 -27
  22. package/types/expression/comparison/undefined.d.ts +28 -32
  23. package/types/expression/logical/and.d.ts +23 -27
  24. package/types/expression/logical/index.d.ts +32 -36
  25. package/types/expression/logical/nor.d.ts +23 -27
  26. package/types/expression/logical/not.d.ts +23 -27
  27. package/types/expression/logical/or.d.ts +23 -27
  28. package/types/expression/logical/xor.d.ts +23 -27
  29. package/types/index.d.ts +73 -71
  30. package/types/operand/collection.d.ts +36 -40
  31. package/types/operand/index.d.ts +25 -29
  32. package/types/operand/reference.d.ts +44 -48
  33. package/types/operand/value.d.ts +31 -35
  34. package/types/parser/index.d.ts +39 -43
  35. package/types/parser/options.d.ts +61 -65
@@ -1,27 +1,23 @@
1
- /**
2
- * Logical expression module.
3
- * @module illogical/expression/logical
4
- */
5
- import { Context, Evaluable, Result } from '../../common/evaluable';
6
- import { Logical } from '../logical';
7
- export declare const OPERATOR: unique symbol;
8
- /**
9
- * Xor logical expression
10
- */
11
- export declare class Xor extends Logical {
12
- /**
13
- * @constructor
14
- * @param {Evaluable[]} operands Collection of operands.
15
- */
16
- constructor(operands: Evaluable[]);
17
- /**
18
- * Evaluate in the given context.
19
- * @param {Context} ctx
20
- * @return {Result}
21
- */
22
- evaluate(ctx: Context): Result;
23
- /**
24
- * {@link Evaluable.simplify}
25
- */
26
- simplify(...args: [Context, string[]]): boolean | Evaluable;
27
- }
1
+ import { Context, Evaluable, Result, SimplifyArgs } from '../../common/evaluable';
2
+ import { Logical } from '../logical';
3
+ export declare const OPERATOR: unique symbol;
4
+ /**
5
+ * Xor logical expression
6
+ */
7
+ export declare class Xor extends Logical {
8
+ /**
9
+ * @constructor
10
+ * @param {Evaluable[]} operands Collection of operands.
11
+ */
12
+ constructor(operands: Evaluable[]);
13
+ /**
14
+ * Evaluate in the given context.
15
+ * @param {Context} ctx
16
+ * @return {Result}
17
+ */
18
+ evaluate(ctx: Context): Result;
19
+ /**
20
+ * {@link Evaluable.simplify}
21
+ */
22
+ simplify(...args: SimplifyArgs): boolean | Evaluable;
23
+ }
package/types/index.d.ts CHANGED
@@ -1,71 +1,73 @@
1
- /**
2
- * Main module.
3
- * @module illogical
4
- */
5
- import { Context, Evaluable } from './common/evaluable';
6
- import { OPERATOR as OPERATOR_EQ } from './expression/comparison/eq';
7
- import { OPERATOR as OPERATOR_GE } from './expression/comparison/ge';
8
- import { OPERATOR as OPERATOR_GT } from './expression/comparison/gt';
9
- import { OPERATOR as OPERATOR_IN } from './expression/comparison/in';
10
- import { OPERATOR as OPERATOR_LE } from './expression/comparison/le';
11
- import { OPERATOR as OPERATOR_LT } from './expression/comparison/lt';
12
- import { OPERATOR as OPERATOR_NE } from './expression/comparison/ne';
13
- import { OPERATOR as OPERATOR_NOT_IN } from './expression/comparison/not-in';
14
- import { OPERATOR as OPERATOR_OVERLAP } from './expression/comparison/overlap';
15
- import { OPERATOR as OPERATOR_PREFIX } from './expression/comparison/prefix';
16
- import { OPERATOR as OPERATOR_PRESENT } from './expression/comparison/present';
17
- import { OPERATOR as OPERATOR_SUFFIX } from './expression/comparison/suffix';
18
- import { OPERATOR as OPERATOR_UNDEFINED } from './expression/comparison/undefined';
19
- import { OPERATOR as OPERATOR_AND } from './expression/logical/and';
20
- import { OPERATOR as OPERATOR_NOR } from './expression/logical/nor';
21
- import { OPERATOR as OPERATOR_NOT } from './expression/logical/not';
22
- import { OPERATOR as OPERATOR_OR } from './expression/logical/or';
23
- import { OPERATOR as OPERATOR_XOR } from './expression/logical/xor';
24
- import { ExpressionInput, Input } from './parser';
25
- import { Options } from './parser/options';
26
- export { OPERATOR_EQ, OPERATOR_NE, OPERATOR_GT, OPERATOR_GE, OPERATOR_LT, OPERATOR_LE, OPERATOR_IN, OPERATOR_NOT_IN, OPERATOR_PREFIX, OPERATOR_SUFFIX, OPERATOR_OVERLAP, OPERATOR_UNDEFINED, OPERATOR_PRESENT, OPERATOR_AND, OPERATOR_OR, OPERATOR_NOR, OPERATOR_XOR, OPERATOR_NOT, };
27
- /**
28
- * Condition engine
29
- */
30
- declare class Engine {
31
- private readonly parser;
32
- /**
33
- * @constructor
34
- * @param {Options?} options Parser options.
35
- */
36
- constructor(options?: Partial<Options>);
37
- /**
38
- * Evaluate the expression.
39
- * @param {ExpressionInput} exp Raw expression.
40
- * @param {Context} ctx Evaluation data context.
41
- * @return {boolean}
42
- */
43
- evaluate(exp: ExpressionInput, ctx: Context): boolean;
44
- /**
45
- * Get expression statement
46
- * @param {ExpressionInput} exp Raw expression.
47
- * @return {string}
48
- */
49
- statement(exp: ExpressionInput): string;
50
- /**
51
- * Parse expression.
52
- * @param {ExpressionInput} exp Raw expression.
53
- * @return {Evaluable}
54
- */
55
- parse(exp: ExpressionInput): Evaluable;
56
- /**
57
- * Simplifies an expression with values in context.
58
- *
59
- * This method tries to evaluate all the expressions and reduce them to its corresponding boolean value.
60
- * If a value required for the expression is not present in the context, the minimal corresponding expression
61
- * will be returned.
62
- *
63
- * @param {ExpressionInput} exp Raw expression.
64
- * @param {Context} context Evaluation data context.
65
- * @param {string[]} ignoreKeys keys to be considered present even if their not present in the context.
66
- * Default to empty array
67
- * @returns {Inpunt | boolean}
68
- */
69
- simplify(exp: ExpressionInput, context: Context, ignoreKeys?: string[]): Input | boolean;
70
- }
71
- export default Engine;
1
+ /**
2
+ * Main module.
3
+ * @module illogical
4
+ */
5
+ import { Context, Evaluable } from './common/evaluable';
6
+ import { OPERATOR as OPERATOR_EQ } from './expression/comparison/eq';
7
+ import { OPERATOR as OPERATOR_GE } from './expression/comparison/ge';
8
+ import { OPERATOR as OPERATOR_GT } from './expression/comparison/gt';
9
+ import { OPERATOR as OPERATOR_IN } from './expression/comparison/in';
10
+ import { OPERATOR as OPERATOR_LE } from './expression/comparison/le';
11
+ import { OPERATOR as OPERATOR_LT } from './expression/comparison/lt';
12
+ import { OPERATOR as OPERATOR_NE } from './expression/comparison/ne';
13
+ import { OPERATOR as OPERATOR_NOT_IN } from './expression/comparison/not-in';
14
+ import { OPERATOR as OPERATOR_OVERLAP } from './expression/comparison/overlap';
15
+ import { OPERATOR as OPERATOR_PREFIX } from './expression/comparison/prefix';
16
+ import { OPERATOR as OPERATOR_PRESENT } from './expression/comparison/present';
17
+ import { OPERATOR as OPERATOR_SUFFIX } from './expression/comparison/suffix';
18
+ import { OPERATOR as OPERATOR_UNDEFINED } from './expression/comparison/undefined';
19
+ import { OPERATOR as OPERATOR_AND } from './expression/logical/and';
20
+ import { OPERATOR as OPERATOR_NOR } from './expression/logical/nor';
21
+ import { OPERATOR as OPERATOR_NOT } from './expression/logical/not';
22
+ import { OPERATOR as OPERATOR_OR } from './expression/logical/or';
23
+ import { OPERATOR as OPERATOR_XOR } from './expression/logical/xor';
24
+ import { ExpressionInput, Input } from './parser';
25
+ import { Options } from './parser/options';
26
+ export { OPERATOR_EQ, OPERATOR_NE, OPERATOR_GT, OPERATOR_GE, OPERATOR_LT, OPERATOR_LE, OPERATOR_IN, OPERATOR_NOT_IN, OPERATOR_PREFIX, OPERATOR_SUFFIX, OPERATOR_OVERLAP, OPERATOR_UNDEFINED, OPERATOR_PRESENT, OPERATOR_AND, OPERATOR_OR, OPERATOR_NOR, OPERATOR_XOR, OPERATOR_NOT, };
27
+ /**
28
+ * Condition engine
29
+ */
30
+ declare class Engine {
31
+ private readonly parser;
32
+ /**
33
+ * @constructor
34
+ * @param {Options?} options Parser options.
35
+ */
36
+ constructor(options?: Partial<Options>);
37
+ /**
38
+ * Evaluate the expression.
39
+ * @param {ExpressionInput} exp Raw expression.
40
+ * @param {Context} ctx Evaluation data context.
41
+ * @return {boolean}
42
+ */
43
+ evaluate(exp: ExpressionInput, ctx: Context): boolean;
44
+ /**
45
+ * Get expression statement
46
+ * @param {ExpressionInput} exp Raw expression.
47
+ * @return {string}
48
+ */
49
+ statement(exp: ExpressionInput): string;
50
+ /**
51
+ * Parse expression.
52
+ * @param {ExpressionInput} exp Raw expression.
53
+ * @return {Evaluable}
54
+ */
55
+ parse(exp: ExpressionInput): Evaluable;
56
+ /**
57
+ * Simplifies an expression with values in context.
58
+ *
59
+ * This method tries to evaluate all the expressions and reduce them to its corresponding boolean value.
60
+ * If a value required for the expression is not present in the context, the minimal corresponding expression
61
+ * will be returned.
62
+ *
63
+ * @param {ExpressionInput} exp Raw expression.
64
+ * @param {Context} context Evaluation data context.
65
+ * @param {string[]} strictKeys keys to be considered present even if they are not present in the context
66
+ * @param {string[]} optionalKeys keys to be considered not present unless they are in the context or in
67
+ * `strictKeys`; when `strictKeys` is `undefined` and `optionalKeys` is an array, every key that is not in
68
+ * `optionalKeys` is considered to be present and thus will be evaluated
69
+ * @returns {Inpunt | boolean}
70
+ */
71
+ simplify(exp: ExpressionInput, context: Context, strictKeys?: string[], optionalKeys?: string[]): Input | boolean;
72
+ }
73
+ export default Engine;
@@ -1,40 +1,36 @@
1
- /**
2
- * Operand module.
3
- * @module illogical/operand
4
- */
5
- import { Context, Evaluable, Result } from '../common/evaluable';
6
- import { Input } from '../parser';
7
- import { Options } from '../parser/options';
8
- import { Operand } from '.';
9
- import { Reference } from './reference';
10
- import { Value } from './value';
11
- /**
12
- * Collection operand resolved containing mixture of value and references.
13
- */
14
- export declare class Collection extends Operand {
15
- private readonly items;
16
- /**
17
- * @constructor
18
- * @param {Operand[]} items Collection of operands.
19
- */
20
- constructor(items: Array<Value | Reference>);
21
- /**
22
- * Evaluate in the given context.
23
- * @param {Context} ctx
24
- * @return {boolean}
25
- */
26
- evaluate(ctx: Context): Result;
27
- /**
28
- * {@link Evaluable.simplify}
29
- */
30
- simplify(...args: [Context, string[]]): Result | Evaluable;
31
- /**
32
- * {@link Evaluable.serialize}
33
- */
34
- serialize(options: Options): Input;
35
- /**
36
- * Get the strict representation of the operand.
37
- * @return {string}
38
- */
39
- toString(): string;
40
- }
1
+ import { Context, Evaluable, Result, SimplifyArgs } from '../common/evaluable';
2
+ import { Input } from '../parser';
3
+ import { Options } from '../parser/options';
4
+ import { Operand } from '.';
5
+ import { Reference } from './reference';
6
+ import { Value } from './value';
7
+ /**
8
+ * Collection operand resolved containing mixture of value and references.
9
+ */
10
+ export declare class Collection extends Operand {
11
+ private readonly items;
12
+ /**
13
+ * @constructor
14
+ * @param {Operand[]} items Collection of operands.
15
+ */
16
+ constructor(items: Array<Value | Reference>);
17
+ /**
18
+ * Evaluate in the given context.
19
+ * @param {Context} ctx
20
+ * @return {boolean}
21
+ */
22
+ evaluate(ctx: Context): Result;
23
+ /**
24
+ * {@link Evaluable.simplify}
25
+ */
26
+ simplify(...args: SimplifyArgs): Result | Evaluable;
27
+ /**
28
+ * {@link Evaluable.serialize}
29
+ */
30
+ serialize(options: Options): Input;
31
+ /**
32
+ * Get the strict representation of the operand.
33
+ * @return {string}
34
+ */
35
+ toString(): string;
36
+ }
@@ -1,29 +1,25 @@
1
- /**
2
- * Operand module.
3
- * @module illogical/operand
4
- */
5
- import { Context, Evaluable, EvaluableType, Result } from '../common/evaluable';
6
- import { Input } from '../parser';
7
- import { Options } from '../parser/options';
8
- /**
9
- * Abstract operand
10
- */
11
- export declare abstract class Operand implements Evaluable {
12
- type: EvaluableType;
13
- /**
14
- * {@link Evaluable.evaluate}
15
- */
16
- abstract evaluate(ctx: Context): Result;
17
- /**
18
- * {@link Evaluable.simplify}
19
- */
20
- abstract simplify(ctx: Context, ignoreKeys: string[]): Result | Evaluable;
21
- /**
22
- * {@link Evaluable.serialize}
23
- */
24
- abstract serialize(options: Options): Input;
25
- /**
26
- * Get the strict representation.
27
- */
28
- toString(): string;
29
- }
1
+ import { Context, Evaluable, EvaluableType, Result } from '../common/evaluable';
2
+ import { Input } from '../parser';
3
+ import { Options } from '../parser/options';
4
+ /**
5
+ * Abstract operand
6
+ */
7
+ export declare abstract class Operand implements Evaluable {
8
+ type: EvaluableType;
9
+ /**
10
+ * {@link Evaluable.evaluate}
11
+ */
12
+ abstract evaluate(ctx: Context): Result;
13
+ /**
14
+ * {@link Evaluable.simplify}
15
+ */
16
+ abstract simplify(ctx: Context, strictKeys?: string[], optionalKeys?: string[]): Result | Evaluable;
17
+ /**
18
+ * {@link Evaluable.serialize}
19
+ */
20
+ abstract serialize(options: Options): Input;
21
+ /**
22
+ * Get the strict representation.
23
+ */
24
+ toString(): string;
25
+ }
@@ -1,48 +1,44 @@
1
- /**
2
- * Operand module.
3
- * @module illogical/operand
4
- */
5
- import { Context, Evaluable, Result } from '../common/evaluable';
6
- import { Options } from '../parser/options';
7
- import { Operand } from '.';
8
- export declare enum DataType {
9
- Number = "Number",
10
- String = "String"
11
- }
12
- /**
13
- * Reference operand resolved within the context
14
- */
15
- export declare class Reference extends Operand {
16
- private readonly key;
17
- private readonly dataType;
18
- /**
19
- * @constructor
20
- * @param {string} key Context key.
21
- */
22
- constructor(key: string);
23
- /**
24
- * Evaluate in the given context.
25
- * @param {Context} ctx
26
- * @return {boolean}
27
- */
28
- evaluate(ctx: Context): Result;
29
- /**
30
- * {@link Evaluable.simplify}
31
- */
32
- simplify(ctx: Context, ignoreKeys: string[]): Result | Evaluable;
33
- /**
34
- * {@link Evaluable.serialize}
35
- */
36
- serialize({ referenceSerialization }: Options): string;
37
- /**
38
- * Get the strict representation of the operand.
39
- * @return {string}
40
- */
41
- toString(): string;
42
- /**
43
- * Converts a value to a specified data type
44
- * Silently returns original value if data type conversion has not been implemented.
45
- * @param value value to cast as data type
46
- */
47
- private toDataType;
48
- }
1
+ import { Context, Evaluable, Result } from '../common/evaluable';
2
+ import { Options } from '../parser/options';
3
+ import { Operand } from '.';
4
+ export declare enum DataType {
5
+ Number = "Number",
6
+ String = "String"
7
+ }
8
+ /**
9
+ * Reference operand resolved within the context
10
+ */
11
+ export declare class Reference extends Operand {
12
+ private readonly key;
13
+ private readonly dataType;
14
+ /**
15
+ * @constructor
16
+ * @param {string} key Context key.
17
+ */
18
+ constructor(key: string);
19
+ /**
20
+ * Evaluate in the given context.
21
+ * @param {Context} ctx
22
+ * @return {boolean}
23
+ */
24
+ evaluate(ctx: Context): Result;
25
+ /**
26
+ * {@link Evaluable.simplify}
27
+ */
28
+ simplify(ctx: Context, strictKeys?: string[], optionalKeys?: string[]): Result | Evaluable;
29
+ /**
30
+ * {@link Evaluable.serialize}
31
+ */
32
+ serialize({ referenceSerialization }: Options): string;
33
+ /**
34
+ * Get the strict representation of the operand.
35
+ * @return {string}
36
+ */
37
+ toString(): string;
38
+ /**
39
+ * Converts a value to a specified data type
40
+ * Silently returns original value if data type conversion has not been implemented.
41
+ * @param value value to cast as data type
42
+ */
43
+ private toDataType;
44
+ }
@@ -1,35 +1,31 @@
1
- /**
2
- * Operand module.
3
- * @module illogical/operand
4
- */
5
- import { Result } from '../common/evaluable';
6
- import { Input } from '../parser';
7
- import { Operand } from '.';
8
- /**
9
- * Static value operand
10
- */
11
- export declare class Value extends Operand {
12
- private readonly value;
13
- /**
14
- * @constructor
15
- * @param {Result} value Constant value.
16
- */
17
- constructor(value: Result);
18
- /**
19
- * {@link Evaluable.evaluate}
20
- */
21
- evaluate(): Result;
22
- /**
23
- * {@link Evaluable.simplify}
24
- */
25
- simplify(): Result;
26
- /**
27
- * {@link Evaluable.serialize}
28
- */
29
- serialize(): Input;
30
- /**
31
- * Get the strict representation of the operand.
32
- * @return {string}
33
- */
34
- toString(): string;
35
- }
1
+ import { Result } from '../common/evaluable';
2
+ import { Input } from '../parser';
3
+ import { Operand } from '.';
4
+ /**
5
+ * Static value operand
6
+ */
7
+ export declare class Value extends Operand {
8
+ private readonly value;
9
+ /**
10
+ * @constructor
11
+ * @param {Result} value Constant value.
12
+ */
13
+ constructor(value: Result);
14
+ /**
15
+ * {@link Evaluable.evaluate}
16
+ */
17
+ evaluate(): Result;
18
+ /**
19
+ * {@link Evaluable.simplify}
20
+ */
21
+ simplify(): Result;
22
+ /**
23
+ * {@link Evaluable.serialize}
24
+ */
25
+ serialize(): Input;
26
+ /**
27
+ * Get the strict representation of the operand.
28
+ * @return {string}
29
+ */
30
+ toString(): string;
31
+ }
@@ -1,43 +1,39 @@
1
- /**
2
- * Parser module.
3
- * @module illogical/parser
4
- */
5
- import { Evaluable } from '../common/evaluable';
6
- import { Options } from './options';
7
- export declare type Input = string | number | boolean | null | Input[] | [string, ...Input[]];
8
- export declare type ArrayInput = Input[];
9
- export declare type ExpressionInput = [string, ...Input[]];
10
- /**
11
- * Parser of raw expressions into Evaluable expression
12
- */
13
- export declare class Parser {
14
- private readonly opts;
15
- private readonly expectedOperators;
16
- /**
17
- * @constructor
18
- * @param {Options?} options Parser options.
19
- */
20
- constructor(options?: Partial<Options>);
21
- /**
22
- * Parser options
23
- * @type {Options}
24
- */
25
- get options(): Options;
26
- /**
27
- * Parse raw expression into evaluable expression.
28
- * @param {ExpressionInput} raw Raw expression.
29
- * @return {Evaluable}
30
- */
31
- parse(raw: ExpressionInput): Evaluable;
32
- /**
33
- * Parse raw expression based on the expression type.
34
- * @param {Input} raw Raw expression.
35
- * @return {Evaluable}
36
- */
37
- private parseRawExp;
38
- /**
39
- * Get resolved operand
40
- * @param raw Raw data
41
- */
42
- private getOperand;
43
- }
1
+ import { Evaluable } from '../common/evaluable';
2
+ import { Options } from './options';
3
+ export declare type Input = string | number | boolean | null | Input[] | [string, ...Input[]];
4
+ export declare type ArrayInput = Input[];
5
+ export declare type ExpressionInput = [string, ...Input[]];
6
+ /**
7
+ * Parser of raw expressions into Evaluable expression
8
+ */
9
+ export declare class Parser {
10
+ private readonly opts;
11
+ private readonly expectedOperators;
12
+ /**
13
+ * @constructor
14
+ * @param {Options?} options Parser options.
15
+ */
16
+ constructor(options?: Partial<Options>);
17
+ /**
18
+ * Parser options
19
+ * @type {Options}
20
+ */
21
+ get options(): Options;
22
+ /**
23
+ * Parse raw expression into evaluable expression.
24
+ * @param {ExpressionInput} raw Raw expression.
25
+ * @return {Evaluable}
26
+ */
27
+ parse(raw: ExpressionInput): Evaluable;
28
+ /**
29
+ * Parse raw expression based on the expression type.
30
+ * @param {Input} raw Raw expression.
31
+ * @return {Evaluable}
32
+ */
33
+ private parseRawExp;
34
+ /**
35
+ * Get resolved operand
36
+ * @param raw Raw data
37
+ */
38
+ private getOperand;
39
+ }