Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This document lists breaking changes in the library to help users migrate between versions.

## Version 6.0.0

`null` is no longer silently casted to `0`. This means that from version 6 onwards, `null == 0` will no longer be true and `null == someVariable` with `someVariable` having a null value will become true. (This was not the case before.)

## Version 5.0.0

### Security: Functions Must Be Registered Explicitly
Expand Down
2 changes: 1 addition & 1 deletion docs/language-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ A complete working example of Monaco Editor integration is included in the repos

```bash
# Build the UMD bundle and start the sample server
npm run monaco-sample:serve
npm run playground
```

Then open http://localhost:8080 in your browser. The sample demonstrates:
Expand Down
14 changes: 7 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export {
} from './src/types/errors.js';

export type {
LanguageServiceApi,
HoverV2,
GetCompletionsParams,
GetHoverParams,
HighlightToken,
LanguageServiceOptions
} from "./src/language-service/index.js";
LanguageServiceApi,
HoverV2,
GetCompletionsParams,
GetHoverParams,
HighlightToken,
LanguageServiceOptions
} from './src/language-service/index.js';

export { createLanguageService, Expression, Parser };
2,499 changes: 1,312 additions & 1,187 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pro-fa/expr-eval",
"version": "5.0.0",
"version": "6.0.0",
"description": "Mathematical expression evaluator",
"keywords": [
"expression",
Expand Down Expand Up @@ -43,7 +43,6 @@
],
"scripts": {
"test": "npm run build && vitest run",
"test:ts": "vitest run test/expression/expression-core-partial.ts test/expression/expression-advanced-partial.ts test/expression/expression-fork-partial.ts test/expression/expression-methods-partial.ts test/functions/functions-binary-ops-partial.ts test/functions/functions-unary-ops-partial.ts test/functions/functions-advanced-partial.ts test/functions/functions-array-string-partial.ts test/functions/functions-logical-partial.ts test/functions/functions-higher-order-partial.ts test/parser/parser-core-partial.ts test/parser/parser-numbers-partial.ts test/parser/parser-options-partial.ts test/operators/operators-comparison-partial.ts test/operators/operators-logical-partial.ts test/operators/operators-math-trig-partial.ts test/operators/operators-math-basic-partial.ts test/operators/operators-misc-partial.ts",
"test:ts:watch": "vitest --testNamePattern=partial",
"test:watch": "vitest",
"test:ui": "vitest --ui",
Expand All @@ -57,7 +56,6 @@
"bench:ci": "npm run build && tsx benchmarks/index.bench.ts",
"lint": "eslint **/*.ts --ignore-pattern parser.d.ts",
"tsgo": "tsgo",
"check-types": "tsgo --noEmit",
"type-check": "tsgo --noEmit",
"build:types": "tsgo -p tsconfig.build.json --emitDeclarationOnly",
"build:esm": "cross-env BUILD_TARGET=esm vite build",
Expand All @@ -68,7 +66,7 @@
"watch": "cross-env BUILD_TARGET=esm vite build --watch",
"clean": "rimraf dist",
"prepublish": "npm run build",
"monaco-sample:serve": "npm run build:umd && node samples/language-service-sample/serve-sample.cjs"
"playground": "npm run build:umd && node samples/language-service-sample/serve-sample.cjs"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
Expand All @@ -83,6 +81,7 @@
"eslint-plugin-n": "^17.0.0",
"eslint-plugin-promise": "^7.0.0",
"rimraf": "^6.0.1",
"terser": "^5.44.1",
"tinybench": "^5.0.1",
"ts-node": "^10.9.2",
"tslib": "^2.8.1",
Expand Down
2 changes: 1 addition & 1 deletion src/core/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { ISCALAR, IOP1, IOP2, IOP3, IVAR, IVARNAME, IFUNCALL, IFUNDEF, IEXPR, IEXPREVAL, IMEMBER, IENDSTATEMENT, IARRAY, IUNDEFINED, ICASEMATCH, IWHENMATCH, ICASEELSE, ICASECOND, IWHENCOND, IOBJECT, IPROPERTY, IOBJECTEND } from '../parsing/instruction.js';
import type { Instruction } from '../parsing/instruction.js';
import type { Expression } from './expression.js';
import type { Value, Values, VariableResolveResult, VariableAlias, VariableValue } from '../types/values.js';
import type { Value, Values, VariableResolveResult } from '../types/values.js';
import { VariableError } from '../types/errors.js';
import { ExpressionValidator } from '../validation/expression-validator.js';

Expand Down
12 changes: 6 additions & 6 deletions src/functions/string/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function searchCount(text: string | undefined, substring: string | undefi
if (substring.length === 0) {
return 0;
}

let count = 0;
let position = 0;
while ((position = text.indexOf(substring, position)) !== -1) {
Expand Down Expand Up @@ -310,12 +310,12 @@ export function naturalSort(arr: string[] | undefined): string[] | undefined {
if (!Array.isArray(arr)) {
throw new Error('Argument to naturalSort must be an array');
}

const collator = new Intl.Collator(undefined, {
numeric: true,
sensitivity: 'base'
});

return [...arr].sort(collator.compare);
}

Expand Down Expand Up @@ -348,16 +348,16 @@ export function toBoolean(str: string | undefined): boolean | undefined {
if (typeof str !== 'string') {
throw new Error('Argument to toBoolean must be a string');
}

const lower = str.toLowerCase().trim();

if (lower === 'true' || lower === '1' || lower === 'yes' || lower === 'on') {
return true;
}
if (lower === 'false' || lower === '0' || lower === 'no' || lower === 'off' || lower === '') {
return false;
}

throw new Error(`Cannot convert "${str}" to a boolean`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/language-service/language-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function createLanguageService(options: LanguageServiceOptions | undefine
const range: Range = {
start: textDocument.positionAt(span.start),
end: textDocument.positionAt(span.end)
}
};
return {
contents: {
kind: MarkupKind.PlainText,
Expand Down
6 changes: 3 additions & 3 deletions src/parsing/parser-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// cSpell:words IOBJECT IOBJECTEND

import {
TOP, TNUMBER, TSTRING, TPAREN, TBRACKET, TCOMMA, TNAME, TSEMICOLON, TEOF, TKEYWORD, TBRACE, Token, TokenType,
TCONST
TOP, TNUMBER, TSTRING, TPAREN, TBRACKET, TCOMMA, TNAME, TSEMICOLON, TEOF, TKEYWORD, TBRACE, Token, TokenType,
TCONST
} from './token.js';
import { Instruction, ISCALAR, IVAR, IFUNCALL, IMEMBER, IARRAY, IUNDEFINED, binaryInstruction, unaryInstruction, IWHENMATCH, ICASEMATCH, ICASEELSE, ICASECOND, IWHENCOND, IPROPERTY, IOBJECT, IOBJECTEND, InstructionType } from './instruction.js';
import contains from '../core/contains.js';
Expand Down Expand Up @@ -121,7 +121,7 @@ export class ParserState {
} else {
instr.push(new Instruction(IVAR, this.current!.value));
}
} else if (this.accept(TNUMBER) ||this.accept(TSTRING) || this.accept(TCONST)) {
} else if (this.accept(TNUMBER) || this.accept(TSTRING) || this.accept(TCONST)) {
instr.push(new Instruction(ISCALAR, this.current!.value));
} else if (this.accept(TPAREN, '(')) {
this.parseExpression(instr);
Expand Down
6 changes: 3 additions & 3 deletions src/parsing/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Expression } from '../core/expression.js';
import type { Value, VariableResolveResult, Values } from '../types/values.js';
import type { Instruction } from './instruction.js';
import type { OperatorFunction } from '../types/parser.js';
import { atan2, condition, fac, filter, fold, gamma, hypot, indexOf, join, map, max, min, random, roundTo, sum, json, stringLength, isEmpty, stringContains, startsWith, endsWith, searchCount, trim, toUpper, toLower, toTitle, stringJoin, split, repeat, reverse, left, right, replace, replaceFirst, naturalSort, toNumber, toBoolean, padLeft, padRight } from '../functions/index.js';
import { atan2, condition, fac, filter, fold, gamma, hypot, indexOf, join, map, max, min, random, roundTo, sum, json, stringLength, isEmpty, stringContains, startsWith, endsWith, searchCount, trim, toUpper, toLower, toTitle, split, repeat, reverse, left, right, replace, replaceFirst, naturalSort, toNumber, toBoolean, padLeft, padRight } from '../functions/index.js';
import {
add,
sub,
Expand Down Expand Up @@ -223,13 +223,13 @@ export class Parser {

this.numericConstants = {
E: Math.E,
PI: Math.PI,
PI: Math.PI
};

this.buildInLiterals = {
true: true,
false: false,
null: null,
null: null
};

// A callback that evaluate will call if it doesn't recognize a variable. The default
Expand Down
2 changes: 1 addition & 1 deletion src/validation/expression-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ExpressionValidator {
static validateMemberAccess(propertyName: string, expressionString: string): void {
if (DANGEROUS_PROPERTIES.has(propertyName)) {
throw new AccessError(
`Prototype access detected in member expression`,
'Prototype access detected in member expression',
{
propertyName,
expression: expressionString
Expand Down
Loading