https://github.com/plurid/loque
Object Data Locator, Extractor, Updater [Work in Thinking]
https://github.com/plurid/loque
Last synced: 7 days ago
JSON representation
Object Data Locator, Extractor, Updater [Work in Thinking]
- Host: GitHub
- URL: https://github.com/plurid/loque
- Owner: plurid
- License: other
- Created: 2020-11-18T21:13:30.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-26T13:42:08.000Z (over 2 years ago)
- Last Synced: 2025-01-28T18:16:15.491Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.71 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
loque
Object Data Locator, Extractor, Updater
`loque` provides utility for locating, extracting, and updating data from object-like structures (arbitrarily nested maps and lists) based on a querying syntax.
### Contents
+ [About](#about)
+ [Data](#data)
+ [Packages](#packages)
+ [Codeophon](#codeophon)
## About
Given a collection of data, `loque` selects, retrieves, and modifies values.
Example:
``` typescript
import loque from '@plurid/loque';
const data = {
records: [
{
ownedBy: 'A',
id: '1',
value: 'one',
},
{
ownedBy: 'B',
id: '2',
value: 'two',
},
{
ownedBy: 'A',
id: '3',
value: 'three',
},
{
ownedBy: 'A',
id: '4',
value: 'four',
},
],
};
const main = () => {
// LocatorStatements
const locatorRecordOne = loque.locate(
'records.id:1',
);
// Extracted data obtained with locator statements.
// {
// ownedBy: 'A',
// id: '1',
// value: 'one',
// };
const recordOne = loque.extract(
locatorRecordOne,
data,
).data;
// Extracted data obtained with locator string.
// [
// {
// ownedBy: 'A',
// id: '1',
// value: 'one',
// },
// {
// ownedBy: 'B',
// id: '2',
// value: 'two',
// },
// ];
const recordsOneTwo = loque.extract(
'records . id:1 & id:2',
data,
).data;
// Updated data with locator string.
// {
// records: [
// ...
// {
// ownedBy: 'A',
// id: '3',
// value: 'three-modified',
// },
// ...
// ],
// };
const newData = loque.update(
'records.id:3',
data,
{
value: 'three-modified',
},
);
// Extraction with cursor.
const lastTwo = loque.extract(
'records.ownedBy:A |last 2|',
newData,
).data;
const firstTwo = loque.extract(
'records.ownedBy:A |first 2|',
newData,
);
// Cursor index value of the last document.
const firstTwoCursor = firstTwo.cursor;
const nextTwo = loque.extract(
`records.ownedBy:A |first 2 above ${firstTwoCursor}|`,
newData,
).data;
}
main();
```
## Data
A collection of data is an arbitrary structure composed of `collections` of `documents` and `values`.
``` typescript
const data = {
// collections
aCollection: [
],
// or values
aValue: 'value',
};
```
A `collection` is a specialized `list`.
``` typescript
const data = {
// a normal list
list: [
'one',
'two,
],
collection: [
// the first item is always a marker for the collection type
{
type: 'collection',
},
// the other elements are any type the collection holds
// and is available to the public interface
{
one: 'two',
},
],
}
```
A `value` can be a `number`, a `string`, a `boolean`, a `map`.
A `document` can contain arbitrary `values` and `collections`.
## Packages
[@plurid/loque-javascript][loque-javascript] • the `JavaScript`/`TypeScript` implementation
[loque-javascript]: https://github.com/plurid/loque/tree/master/packages/loque-javascript
## [Codeophon](https://github.com/ly3xqhl8g9/codeophon)
+ licensing: [delicense](https://github.com/ly3xqhl8g9/delicense)
+ versioning: [αver](https://github.com/ly3xqhl8g9/alpha-versioning)