formulang-ts 0.0.0-stage → 1.0.0
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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +93 -2
- package/dist/abstractions/index.cjs +44 -0
- package/dist/abstractions/index.cjs.map +1 -0
- package/dist/abstractions/index.d.cts +48 -0
- package/dist/abstractions/index.d.ts +48 -0
- package/dist/abstractions/index.js +3 -0
- package/dist/abstractions/index.js.map +1 -0
- package/dist/chunk-5H5INCIE.cjs +4129 -0
- package/dist/chunk-5H5INCIE.cjs.map +1 -0
- package/dist/chunk-BAFJXDWP.cjs +99 -0
- package/dist/chunk-BAFJXDWP.cjs.map +1 -0
- package/dist/chunk-LBF7G2HJ.js +89 -0
- package/dist/chunk-LBF7G2HJ.js.map +1 -0
- package/dist/chunk-P57TIHNW.js +4052 -0
- package/dist/chunk-P57TIHNW.js.map +1 -0
- package/dist/environment-BJYwrQVN.d.cts +472 -0
- package/dist/environment-DxDoox8U.d.ts +472 -0
- package/dist/index.cjs +528 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +696 -0
- package/dist/index.d.ts +696 -0
- package/dist/index.js +182 -0
- package/dist/index.js.map +1 -0
- package/dist/processing-CnZQCacu.d.cts +398 -0
- package/dist/processing-CnZQCacu.d.ts +398 -0
- package/dist/stock/index.cjs +657 -0
- package/dist/stock/index.cjs.map +1 -0
- package/dist/stock/index.d.cts +309 -0
- package/dist/stock/index.d.ts +309 -0
- package/dist/stock/index.js +631 -0
- package/dist/stock/index.js.map +1 -0
- package/package.json +111 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="./raw/images/icons/monogram.svg" height="50" alt="FormuLang-TS monogram">
|
|
4
|
+
|
|
5
|
+
# Changelog
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
All notable changes of **FormuLang-TS**. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); the library uses [Semantic Versioning](https://semver.org).
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## [1.0.0] - 2026-11-23
|
|
13
|
+
|
|
14
|
+
First release of the library.
|
|
15
|
+
|
|
16
|
+
**Supported standards:** `core-1.0`, `stock-1.0` ([`Adisoreq/FormuLang@c40e08a`](https://github.com/Adisoreq/FormuLang/tree/c40e08a)); same results as FormuLang.NET 1.0.0.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Execution pipeline of the standard: pre-execution, validation, clean-up, tokenization, parsing (Pratt parser), evaluation and finalization, with replaceable stages (`Executor.with*`).
|
|
20
|
+
- Core standard `core-1.0`: all functions and procedures (including `FORMAT` and the time functions), operators, lambdas, objects, scoped comments `<# ... #>`, Unicode texts (characters are code points), serialization variables, `NOW` and `time_offset`, the Default, Iteration and Time Contexts (`Executor.createFrameRunner`, `executeFrames`).
|
|
21
|
+
- Stock standard `stock-1.0` (`formulang-ts/stock`): `Stock.Candle`, `CANDLE`, `IS_BULLISH`, `IS_BEARISH`, `LOAD_INDICATOR` and `LOAD_PATTERN` with the formula registry (`FormulaRegistry`), the Stock, Indicator, Pattern and Strategy contexts and `StockExecutor`.
|
|
22
|
+
- JavaScript facade: `evaluate`, `createEngine` / `Engine`, conversion between FormuLang and JavaScript values, host functions.
|
|
23
|
+
- Interfaces of every module in `formulang-ts/abstractions`.
|
|
24
|
+
- Conformance tests ported from FormuLang.NET and the JSON conformance tests of the standard (`scripts/sync-conformance.mjs`), samples (calculator CLI, web preview), documentation, CI and the npm release workflow.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adrian Piznal
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="./raw/images/icons/logotype.svg" alt="FormuLang logo" width="500" />
|
|
4
|
+
|
|
5
|
+
**FormuLang-TS** is a multi-platform, modular TypeScript library implementing the [**FormuLang**](https://github.com/Adisoreq/FormuLang) standard.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
[](https://www.npmjs.com/package/formulang-ts)
|
|
9
|
+
[](docs/conformance.md)
|
|
10
|
+
|
|
11
|
+
[**Documentation**](docs/README.md) · [**Getting started**](docs/getting-started.md) · [**Changelog**](CHANGELOG.md)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
**Web preview** available here:
|
|
16
|
+
|
|
17
|
+
<a href="https://adisoreq.github.io/formulang-ts/">
|
|
18
|
+
<img src="https://img.shields.io/badge/%E2%96%B6-Run%20Web%20Preview-3178c6?style=for-the-badge&labelColor=1e4f8a" alt="Run Web Preview button" />
|
|
19
|
+
</a>
|
|
20
|
+
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
[**FormuLang**](https://github.com/Adisoreq/FormuLang) is a formula-based scripting language standard: a host application embeds an interpreter and lets its users write text formulas such as below:
|
|
26
|
+
|
|
27
|
+
```php
|
|
28
|
+
$principal := 1000
|
|
29
|
+
$rate := 0.05
|
|
30
|
+
$principal * (1 + $rate) ^ 10
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**FormuLang-TS** is the implementation of that standard for TypeScript and JavaScript, in Node.js and in the browser. It turns a formula into a single result value by running the execution pipeline defined by the standard:
|
|
34
|
+
|
|
35
|
+
**Validation** → **Clean-up** → **Tokenization** → **Parsing** → **Evaluation**
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { evaluate } from "formulang-ts";
|
|
39
|
+
|
|
40
|
+
const result = evaluate("$principal * (1 + $rate) ^ 10", { variables: { principal: 1000, rate: 0.05 } });
|
|
41
|
+
|
|
42
|
+
if (result.ok) console.log(result.value); // 1628.894626777442
|
|
43
|
+
else console.log(result.error.toString()); // e.g. [UNKNOWN_SYMBOL_ERROR (5)] Variable "rate" is not defined.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- **Core 1.0** and **Stock 1.0** standards: all Core functions and procedures, lambdas, objects, scoped comments, Unicode texts, `FORMAT`, the time functions and `NOW`, the Iteration and Time Contexts; the Stock context types, the formula registry of indicators and patterns, `CANDLE`, `IS_BULLISH`, `IS_BEARISH`, `LOAD_INDICATOR` and `LOAD_PATTERN`.
|
|
49
|
+
- **Modular**: one package with separate entry points – `formulang-ts`, `formulang-ts/abstractions` and `formulang-ts/stock` – each as an ES module and as CommonJS, with type declarations and no runtime dependencies.
|
|
50
|
+
- **Two levels of API**: a facade working with plain JavaScript values (`evaluate`, `createEngine`), and the pipeline API following the architecture of [FormuLang.NET](https://github.com/Adisoreq/formulang-dotnet) (environments, contexts, replaceable stages, typed function overloads).
|
|
51
|
+
- **Errors are values**: a formula never throws; every problem is a FormuLang Error with a code from the standard, and validation reports every problem at once.
|
|
52
|
+
- **Same results as the reference implementation**: the test cases of FormuLang.NET and the language-independent conformance tests of the standard are the tests of this library, and both implementations give identical outputs (see [Conformance](docs/conformance.md)).
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install formulang-ts
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The package needs Node.js 20 or newer, or any modern browser (through a bundler). See [Getting started](docs/getting-started.md#installation).
|
|
61
|
+
|
|
62
|
+
| Import | Content |
|
|
63
|
+
| :----- | :------ |
|
|
64
|
+
| `formulang-ts` | Core standard, execution pipeline, JavaScript facade |
|
|
65
|
+
| `formulang-ts/abstractions` | Interfaces shared by every module |
|
|
66
|
+
| `formulang-ts/stock` | Stock extension standard |
|
|
67
|
+
|
|
68
|
+
## Project status
|
|
69
|
+
|
|
70
|
+
The library implements the first stable versions of the standards, **Core 1.0** and **Stock 1.0**. From version `1.0.0` on it follows [Semantic Versioning](https://semver.org): changes within the `1.x` versions are backward compatible. See [Conformance](docs/conformance.md) for the details, the implementation choices and the proposals for the standard, and [Development](docs/development.md#releasing) for the releases.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Related projects
|
|
74
|
+
|
|
75
|
+
- [**FormuLang**](https://github.com/Adisoreq/FormuLang)
|
|
76
|
+
<br> Language standard, reference point for syntax and semantics rules.
|
|
77
|
+
|
|
78
|
+
- [**FormuLang.NET**](https://github.com/Adisoreq/formulang-dotnet)
|
|
79
|
+
<br> Implementation for C# (.NET 8.0), reference implementation of this library.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## Authors
|
|
83
|
+
|
|
84
|
+
Adrian Piznal
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
The library is licensed under the [MIT License](LICENSE).
|
|
90
|
+
The FormuLang standard documentation is licensed separately, under [CC BY 4.0](https://github.com/Adisoreq/FormuLang/blob/main/LICENSE.txt).
|
|
91
|
+
|
|
92
|
+
<div align="center">
|
|
93
|
+
<img src="raw/images/icons/monogram.svg" width="50" alt="Monogram" />
|
|
94
|
+
</div>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBAFJXDWP_cjs = require('../chunk-BAFJXDWP.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "Associativity", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkBAFJXDWP_cjs.Associativity; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "ContainerType", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkBAFJXDWP_cjs.ContainerType; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "ContextType", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkBAFJXDWP_cjs.ContextType; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "ExpressionKind", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkBAFJXDWP_cjs.ExpressionKind; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "FunctionType", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunkBAFJXDWP_cjs.FunctionType; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "OperatorType", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkBAFJXDWP_cjs.OperatorType; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "PrimitiveType", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkBAFJXDWP_cjs.PrimitiveType; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "TokenType", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkBAFJXDWP_cjs.TokenType; }
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "VariableScope", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return chunkBAFJXDWP_cjs.VariableScope; }
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=index.cjs.map
|
|
44
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export { j as ContainerType, C as ContextType, N as ExpressionKind, F as FunctionType, g as IAbstractTree, D as IAbstractTreeNode, n as IArgumentTemplate, E as ICallExpression, o as ICleanUpResult, y as ICleaner, G as IConstantExpression, i as IContainer, b as IContext, c as IEnvironment, d as IError, q as IEvaluationResult, B as IEvaluator, p as IExecutionResult, t as IExpressionNode, h as IFunction, l as IFunctionOverload, O as IInvokable, M as ILambda, H as ILambdaExpression, J as ILiteralExpression, I as IObject, P as IOperationResult, K as IParameterExpression, A as IParser, r as IParsingResult, Q as IPrimitive, m as IProcedure, s as ISequence, e as IStandard, f as IStandardVersion, v as IToken, u as ITokenizationResult, z as ITokenizer, k as IType, w as IValidationResult, x as IValidator, a as IValue, L as IVariableExpression, R as PrimitiveType, T as TokenType, V as VariableScope } from '../processing-CnZQCacu.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Contracts of operators.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/Adisoreq/FormuLang/blob/main/docs/semantics/operator-parsing.md
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Grouping of operators with equal binding power. */
|
|
10
|
+
declare const Associativity: {
|
|
11
|
+
/** `a - b - c` = `(a - b) - c` */
|
|
12
|
+
readonly Left: "Left";
|
|
13
|
+
/** `a ^ b ^ c` = `a ^ (b ^ c)` */
|
|
14
|
+
readonly Right: "Right";
|
|
15
|
+
/** Operators cannot be chained: `a < b < c` is a syntax error. */
|
|
16
|
+
readonly None: "None";
|
|
17
|
+
};
|
|
18
|
+
type Associativity = (typeof Associativity)[keyof typeof Associativity];
|
|
19
|
+
/** Roles of an operator token. The values are bit flags and can be combined. */
|
|
20
|
+
declare const OperatorType: {
|
|
21
|
+
readonly None: 0;
|
|
22
|
+
/** Separates operands: `A [operator] B` */
|
|
23
|
+
readonly Separator: 1;
|
|
24
|
+
/** Unary operator before its operand: `[operator] A` */
|
|
25
|
+
readonly Prefix: 2;
|
|
26
|
+
/** Unary operator after its operand: `A [operator]` */
|
|
27
|
+
readonly Suffix: 4;
|
|
28
|
+
/** Opening bracket. */
|
|
29
|
+
readonly OpenBracket: 8;
|
|
30
|
+
/** Closing bracket. */
|
|
31
|
+
readonly CloseBracket: 16;
|
|
32
|
+
/** Sequence boundary (new line, semicolon). Not an expression operator. */
|
|
33
|
+
readonly Boundary: 32;
|
|
34
|
+
/** Structural separator inside a delimiter (comma, colon). */
|
|
35
|
+
readonly ItemSeparator: 64;
|
|
36
|
+
};
|
|
37
|
+
/** Combination of {@link OperatorType} flags. */
|
|
38
|
+
type OperatorType = number;
|
|
39
|
+
interface IOperator {
|
|
40
|
+
readonly symbol: string;
|
|
41
|
+
readonly type: OperatorType;
|
|
42
|
+
/** Binding power. A higher binding power binds more tightly; 0 for tokens that do not compete for it. */
|
|
43
|
+
readonly priority: number;
|
|
44
|
+
readonly associativity: Associativity;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { Associativity, OperatorType };
|
|
48
|
+
export type { IOperator };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export { j as ContainerType, C as ContextType, N as ExpressionKind, F as FunctionType, g as IAbstractTree, D as IAbstractTreeNode, n as IArgumentTemplate, E as ICallExpression, o as ICleanUpResult, y as ICleaner, G as IConstantExpression, i as IContainer, b as IContext, c as IEnvironment, d as IError, q as IEvaluationResult, B as IEvaluator, p as IExecutionResult, t as IExpressionNode, h as IFunction, l as IFunctionOverload, O as IInvokable, M as ILambda, H as ILambdaExpression, J as ILiteralExpression, I as IObject, P as IOperationResult, K as IParameterExpression, A as IParser, r as IParsingResult, Q as IPrimitive, m as IProcedure, s as ISequence, e as IStandard, f as IStandardVersion, v as IToken, u as ITokenizationResult, z as ITokenizer, k as IType, w as IValidationResult, x as IValidator, a as IValue, L as IVariableExpression, R as PrimitiveType, T as TokenType, V as VariableScope } from '../processing-CnZQCacu.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Contracts of operators.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/Adisoreq/FormuLang/blob/main/docs/semantics/operator-parsing.md
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Grouping of operators with equal binding power. */
|
|
10
|
+
declare const Associativity: {
|
|
11
|
+
/** `a - b - c` = `(a - b) - c` */
|
|
12
|
+
readonly Left: "Left";
|
|
13
|
+
/** `a ^ b ^ c` = `a ^ (b ^ c)` */
|
|
14
|
+
readonly Right: "Right";
|
|
15
|
+
/** Operators cannot be chained: `a < b < c` is a syntax error. */
|
|
16
|
+
readonly None: "None";
|
|
17
|
+
};
|
|
18
|
+
type Associativity = (typeof Associativity)[keyof typeof Associativity];
|
|
19
|
+
/** Roles of an operator token. The values are bit flags and can be combined. */
|
|
20
|
+
declare const OperatorType: {
|
|
21
|
+
readonly None: 0;
|
|
22
|
+
/** Separates operands: `A [operator] B` */
|
|
23
|
+
readonly Separator: 1;
|
|
24
|
+
/** Unary operator before its operand: `[operator] A` */
|
|
25
|
+
readonly Prefix: 2;
|
|
26
|
+
/** Unary operator after its operand: `A [operator]` */
|
|
27
|
+
readonly Suffix: 4;
|
|
28
|
+
/** Opening bracket. */
|
|
29
|
+
readonly OpenBracket: 8;
|
|
30
|
+
/** Closing bracket. */
|
|
31
|
+
readonly CloseBracket: 16;
|
|
32
|
+
/** Sequence boundary (new line, semicolon). Not an expression operator. */
|
|
33
|
+
readonly Boundary: 32;
|
|
34
|
+
/** Structural separator inside a delimiter (comma, colon). */
|
|
35
|
+
readonly ItemSeparator: 64;
|
|
36
|
+
};
|
|
37
|
+
/** Combination of {@link OperatorType} flags. */
|
|
38
|
+
type OperatorType = number;
|
|
39
|
+
interface IOperator {
|
|
40
|
+
readonly symbol: string;
|
|
41
|
+
readonly type: OperatorType;
|
|
42
|
+
/** Binding power. A higher binding power binds more tightly; 0 for tokens that do not compete for it. */
|
|
43
|
+
readonly priority: number;
|
|
44
|
+
readonly associativity: Associativity;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { Associativity, OperatorType };
|
|
48
|
+
export type { IOperator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|