Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muze-nl/jaqt
GraphQL-style Array.select() and Array.where() for javascript
https://github.com/muze-nl/jaqt
Last synced: 2 days ago
JSON representation
GraphQL-style Array.select() and Array.where() for javascript
- Host: GitHub
- URL: https://github.com/muze-nl/jaqt
- Owner: muze-nl
- License: mit
- Created: 2023-07-07T12:55:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-18T09:35:05.000Z (6 days ago)
- Last Synced: 2024-09-19T11:25:40.214Z (5 days ago)
- Language: JavaScript
- Size: 106 KB
- Stars: 196
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GitHub License](https://img.shields.io/github/license/muze-nl/jaqt)](https://github.com/muze-nl/jaqt/blob/main/LICENSE)
[![GitHub package.json version](https://img.shields.io/github/package-json/v/muze-nl/jaqt)]()
[![NPM Version](https://img.shields.io/npm/v/jaqt)](https://www.npmjs.com/package/jaqt)
[![npm bundle size](https://img.shields.io/bundlephobia/min/jaqt)](https://www.npmjs.com/package/jaqt)# jaqt: javascript queries and transformations
jaqt (pronounced 'jacket') is a query engine for arrays and objects, inspired by graphql and sql. e.g:
Javascript Query
Result
```javascript
from(data.people)
.select({
metrics: {
hair_color: _
},
lastName: _
})
```
```
[
{
"metrics": {
"hair_color": "blond"
},
"lastName": "Skywalker"
},
{
"metrics": {
"hair_color": "none"
},
"lastName": "Vader"
}
]
```## Table of Contents
1. [Background](#background)
2. [Quickstart](docs/quickstart.md)
3. [Usage](#usage)
4. [User Manual](docs/manual.md)
5. [Reference](docs/reference.md)
6. [Contributions](#contributions)
7. [License](#license)There are many libraries that add a kind of query language to javascript arrays. GraphQL is one of those. But all the libraries I have found add a custom query language. Either by adding specific functions that mimic SQL, or by explicitly defining a query language like GraphQL. In all cases this means that you give up the power of javascript itself and must switch to a different, less capable language.
So this library is explicitly not a query language itself, but it uses some javascript trickery to add some syntactic sugar to the native Array.map and Array.filter functions so that you can get most of the ease of use of something like GraphQL, while staying squarely in javascript country.
There are no speed improvements or indexes over normal Array.filter and Array.map.
The examples below all use the data below:
```javascript
let data = JSON.parse(`[
{
"name": "John",
"lastName": "Doe",
"friends": [
"Jane"
]
},
{
"name": "Jane",
"lastName": "Doe",
"friends": [
"John"
]
}
]`)
```And this is how you can use this library:
```javascript
import {from, _} from 'jaqt'from(data)
.where({
friends: 'John'
})
.select({
name: o => o.name+' '+o.lastName
})
```Which results in:
```
[
{ name: 'Jane Doe'}
]
```## Documentation
- The [Developers Manual](docs/manual.md) will guide you on how to get started and how to use JAQT.
- The [Reference](docs/reference.md) explains all the parts in detail.Contributions are welcome. Please fork the github repository and make your changes there, then open a pull request.
If you find any bugs or other issues, please use the github repository Issues. Check if your issue has already been posted before you add a new issue.The github repository is at https://github.com/muze-nl/jaqt
This software is licensed under MIT open source license. See the [License](./LICENSE) file.