Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsnext/nester
Transforming "raw-string" keys in objects.
https://github.com/bsnext/nester
node objects transform typescript
Last synced: 3 days ago
JSON representation
Transforming "raw-string" keys in objects.
- Host: GitHub
- URL: https://github.com/bsnext/nester
- Owner: bsnext
- License: mit
- Created: 2023-12-12T17:17:00.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-13T00:34:44.000Z (7 months ago)
- Last Synced: 2024-04-14T13:12:03.240Z (7 months ago)
- Topics: node, objects, transform, typescript
- Language: TypeScript
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nester
![Build & Test](https://github.com/bsnext/nester/actions/workflows/main.yml/badge.svg)
![Node.JS Supported](https://badgen.net/static/Node.JS/%3E=16.0.0/green)
![Install Size](https://badgen.net/packagephobia/install/@bsnext/nester)
![Dependencies](https://badgen.net/bundlephobia/dependency-count/@bsnext/nester)
![License](https://badgen.net/static/license/MIT/blue)Short library for transform objects with "raw-string" keys.
```
{ "object.raw.string": "key" } -> { object: { raw: { string: "key" } } }
{ "my.array[2]": "hehe" } -> { my: { array: [undefined, undefined, "hehe"] } }
```## Installing:
```bash
npm install @bsnext/nester
```## Usage:
```ts
new Nester(isCaching: boolean = false, cacheLimit: number = 100, cachePurgeTime: number = 300000)
```* isCaching - State of cache mode for store parsed keys.
* cacheLimit - Limit of cached keys. Cache will purged when reach limit keys.
* cachePurgeTime - Interval (ms) for purge cache.```ts
import Nester from "@bsnext/nester";
const nester = new Nester(true);const result = nester.transform(
{ "object.raw.string": "key" }
);// Result: { object: { raw: { string: "key" } }
// PS. We recommended to use caching. See benchmark on this page.
```## Examples:
```ts
nester.transform(
{
"hui.asdsad.asdsd": {
"elda": 123,
"pizda[2]": "da",
"pizda[3]": {
"moshonka.po.imeni[0]": "sanya",
"moshonka.po.imeni[1]": "sasanya",
"moshonka.po.imeni[3]": "POEsher",
}
},
"buba.biba": true,
"bruh": null,
"keka.ebeka[1]": true,
"keka.ebeka[5]": {
bekabeka: 123123.123
},
}
);/*
Result:
{
"hui": {
"asdsad": {
"asdsd": {
"elda": 123,
"pizda": [undefined, undefined, "da",
{
"moshonka": {
"po": {
"imeni": ["sanya", "sasanya", undefined, "POEsher"]
}
}
}
]
}
}
},
"buba": {
"biba": true
},
"bruh": null,
"keka": {
"ebeka": [true, true, false, undefined, undefined,
{
"bekabeka": 123123.123
}
]
}
}
*/
``````ts
type exampleType = {
my: {
deep: {
variable: {
hello: string;
version: string;
}
}
}
}const myObject = nester.transform(
{
"my.deep.variable": {
"hello": "world",
"version": "1.1.0"
}
}
);
``````ts
nester.purge(); // Method for manually purge cache.
```## Benchmark:
[Used code for test and get those results.](https://github.com/bsnext/Nester/blob/main/src/benchmark/index.ts)```
[No Cache] Hard & Deep Object: x100000 / 1996.83 ms.
[No Cache] Object + Array: x100000 / 908.87 ms.
[No Cache] Deep Object: x100000 / 1385.89 ms.
[Cache] Hard & Deep Object: x100000 / 193.69 ms.
[Cache] Object + Array: x100000 / 82.66 ms.
[Cache] Deep Object: x100000 / 157.80 ms.
```Tested on Node.JS v20.11.1, Ryzen 7 3800X 3.9 GHz