# @datasco/formula

> Simple language for describing data formats, compilable to Regex

Latest version **1.3.4** (published 2023-12-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @datasco/formula
pnpm add @datasco/formula
yarn add @datasco/formula
bun add @datasco/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.4 |
| Published | 2023-12-24 |
| First published | 2022-09-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 42 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | datasco |
| Maintainers | proxymal |
| Keywords | regex, language, dsl, compilable, formula |

## Links

- npm: https://www.npmjs.com/package/@datasco/formula
- 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/@datasco/formula

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [typescript](https://npm.io/package/typescript.md) ^4.8.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.3.4 (latest) — 2023-12-24
- 1.3.3 — 2023-12-24
- 1.3.2 — 2023-12-24
- 1.3.1 — 2023-12-24
- 1.0.1 — 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/@datasco/formula · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
