# @ucast/core

> git@github.com:stalniy/ucast.git

Latest version **2.0.0** (published 2026-04-24) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @ucast/core
pnpm add @ucast/core
yarn add @ucast/core
bun add @ucast/core
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-04-24 |
| First published | 2020-07-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 69.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 270 |
| Author | Sergii Stotskyi |
| Maintainers | stalniy |
| Keywords | where, sql, mongo, conditions, query, builder, ast |

## Links

- npm: https://www.npmjs.com/package/@ucast/core
- Repository: https://github.com/stalniy/ucast
- Homepage: https://github.com/stalniy/ucast#readme
- Issues: https://github.com/stalniy/ucast/issues
- npm.io page: https://npm.io/package/@ucast/core

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-04-24
- 1.8.1-alpha.1 (alpha) — 2021-01-10
- 1.10.2 — 2023-02-15
- 1.10.1 — 2021-07-15
- 1.10.0 — 2021-03-26
- 1.9.0 — 2021-03-25
- 1.8.2 — 2021-01-10
- 1.8.1 — 2021-01-10
- 1.8.0 — 2020-12-02
- 1.7.0 — 2020-11-23
- 1.6.1 — 2020-11-02
- 1.6.0 — 2020-11-02
- 1.5.0 — 2020-08-20
- 1.4.1 — 2020-08-13
- 1.4.0 — 2020-08-13
- … 7 more at https://npm.io/package/@ucast/core/versions

## README

# Universal Conditions AST

[![@ucast/core NPM version](https://badge.fury.io/js/%40ucast%2Fcore.svg)](https://badge.fury.io/js/%40ucast%2Fcore)
[![](https://img.shields.io/npm/dm/%40ucast%2Fcore.svg)](https://www.npmjs.com/package/%40ucast%2Fcore)
[![UCAST join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-ucast/community)

This package contains classes and functions that helps to create parsers, conditions AST, interpreters and translators.

## Installation

```sh
npm i @ucast/core
# or
yarn add @ucast/core
# or
pnpm add @ucast/core
```

## Getting Started

### Parser

Parser is a function that translates conditions from any language into conditions AST. For example, `MongoQueryParser` parses MongoQuery into AST which then can be interpreted by `JavaScriptInterpreter` that returns a boolean value based on passed in object.

### Conditions AST

Abstract Syntax Tree of any condition. **What is condition?**
`x > 4` is a condition, `x === 4` is a condition as well, `{ x: { $eq: 4 } }` is a [MongoQuery](http://docs.mongodb.org/manual/reference/operator/query/) condition.

There are few types of AST nodes that allow us to represent any condition:

* **FieldCondition**. \
  Depends on a field, operator and its value. For example, in condition `x > 4`, `x` is a field, `4` is a value and `>` is operator
* **DocumentCondition**. \
  Any condition that test a document (or a row) as whole (e.g., in MongoDB Query, it's `$where` operator and in SQL it's `EXISTS`).
* **CompoundCondition**. \
  Combines other conditions using logical operations like "and", "or", "not".

### Interpreter

An interpreter is a function that interprets conditions AST in a specific way. For example, it can:

* interpret conditions in JavaScript runtime to return a boolean result
* or it can convert conditions into SQL `WHERE` statement
* or MongoDB query,
* or HTTP/REST query
* or GraphQL input
* or anything else you can imagine

### Translator

Combines Parser and Interpreter and returns a factory function:

```js
const parse = (query) => /* to conditions AST */
const interpreter = createInterpreter({ /* condition interpreters */ });
const translate = (query, ...args) => interpreter.bind(null, parse(query));
```

## Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for [contributing].

## License

[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)

[contributing]: https://github.com/stalniy/ucast/blob/master/CONTRIBUTING.md

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