0.3.9 • Published 3 months ago

@actions/expressions v0.3.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

actions/expressions

@actions/expressions is a library to parse and evaluate GitHub Actions expressions.

Installation

The package contains TypeScript types and compiled ECMAScript modules.

npm install @actions/expressions

Usage

Simple example

import { Parser, Lexer, Evaluator, data } from '@actions/expressions';

const lexer = new Lexer("1 == 2");
const lr = lexer.lex();

const parser = new Parser(lr.tokens, [], []);
const expr = parser.parse();

const evaluator = new Evaluator(expr, new data.Dictionary());
const result = evaluator.evaluate();

console.log(result.coerceString()) // false

With context data

import { Parser, Lexer, Evaluator, data } from '@actions/expressions';

const lexer = new Lexer("'monalisa' == context.name");
const lr = lexer.lex();

const parser = new Parser(lr.tokens, ["context"], []);
const expr = parser.parse();

const evaluator = new Evaluator(expr, new data.Dictionary([{
  key: "context"
  value: new data.Dictionary([{
    key: "name"
    value: new data.StringData("monalisa")
  }])
}]));
const result = evaluator.evaluate();

console.log(result.coerceString()) // true

Contributing

See CONTRIBUTING.md at the root of the repository for general guidelines and recommendations.

This project is just one of multiple implementations of the GitHub Actions Expressions language. We therefore cannot accept contributions that add new language features or significantly change the behavior of existing language features. If you would like to propose a change to the language itself, please use our Community Forum.

If you do want to contribute, please run prettier to format your code and add unit tests as appropriate before submitting your PR. ./testdata contains test cases that all implementations should pass, please also make sure those tests are still passing.

Build

npm run build

or to watch for changes

npm run watch

Test

npm test

or to watch for changes and run tests:

npm run test-watch

Lint

npm run format-check

License

This project is licensed under the terms of the MIT open source license. Please refer to MIT for the full terms.

0.3.9

3 months ago

0.3.8

9 months ago

0.3.7

10 months ago

0.3.6

11 months ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago