# formula-cli

> Simple language for describing data formats, compilable to Regex

Latest version **1.3.5** (published 2024-05-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install formula-cli
pnpm add formula-cli
yarn add formula-cli
bun add formula-cli
```

Provides the command `formula`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.5 |
| Published | 2024-05-27 |
| First published | 2022-09-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 61.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | datasco |
| Maintainers | proxymal |
| Keywords | regex, language, dsl |

## Links

- npm: https://www.npmjs.com/package/formula-cli
- Repository: https://github.com/datasco/Formula
- Homepage: https://github.com/datasco/Formula#readme
- Issues: https://github.com/datasco/Formula/issues
- npm.io page: https://npm.io/package/formula-cli

## Dependencies (4)

- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [yargs](https://npm.io/package/yargs.md) ^17.5.1
- [typescript](https://npm.io/package/typescript.md) ^4.8.3
- [@datasco/formula](https://npm.io/package/@datasco/formula.md) ^1.3.4

## Recent versions

- 1.3.5 (latest) — 2024-05-27
- 1.3.4 — 2023-12-24
- 1.3.3 — 2023-12-24
- 1.2.2 — 2023-09-26
- 1.2.1 — 2023-09-22
- 1.2.0 — 2023-09-22
- 1.1.1 — 2023-05-28
- 1.1.0 — 2022-09-24
- 1.0.4 — 2022-09-22
- 1.0.3 — 2022-09-22
- 1.0.2 — 2022-09-22

## README

# Formula

Simple language for describing data formats, transpilable to RegExp.

# Syntax

Example of advanced formula:

```formula
# Variables
define VAL match '[a-f0-9]'
define VAL_3 match(3) VAL
define VAL_6 match(6) VAL

# Tests
test '#fff'
test '#ababab'
test '#000000'
test '#f0f0f0'

# Formula
match START
match '#'
group {
	match VAL_3 | VAL_6 # 3 or 6 hex values
}
match END
```

Formula is gonna be transpiled into following RegExp:

```regex
^#((?:[a-f0-9]{3})|(?:[a-f0-9]{6}))$
```

# Usage

Install a Formula CLI globally:

```bash
npm i formula-cli -g
```

After installation you can use CLI to compile formula file:

```bash
formula compile example.formula
```

And also you can compile the whole directory:

```bash
formula compile src --dir
```

For running a tests inside formula:

```bash
formula test example.formula
```

# Examples

You can see examples of formulas in [`/example`](https://github.com/datasco/Formula/tree/main/examples) directory in this repository.

# Changelog

## v1.2.2

-   Added lookahead & lookbehind syntax (`match ...'a' | 'a'...`)

## v1.2.1

-   Fixed infinite loop when `#` at the end of file

## v1.2.0

-   Added testing system that allows to test formulas matching
-   Added `formula test` CLI command
-   Added `test`

## v1.1.1

-   Added support of both string formats (`'` and `"`)
-   Added support of `+`/`(min,max)` and `?` to groups
-   Added `|` operator for matching
-   Fixed if-else compilation

## v1.1.0

-   Added `formula compile` CLI command
-   Added `match`
-   Added `group`
-   Added `if` and `else`
-   Added `define`

---
_Source: https://npm.io/package/formula-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
