https://github.com/uppercod/map-object
https://github.com/uppercod/map-object
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/uppercod/map-object
- Owner: UpperCod
- Created: 2020-08-17T19:21:16.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-18T04:24:58.000Z (over 5 years ago)
- Last Synced: 2025-01-26T14:05:05.981Z (over 1 year ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# map-object
Api for creating plugins capable of modifying an object according to its index, this library is created to implement the use of `$ref`.
### \$ref implementation example
```js
import path from "path";
import { readFile } from "fs/promises";
import loadData from "../../src/index";
loadData(
{
file: path.join(__dirname, "data.json"),
value: {
$ref: "files/users.json",
},
},
{
async $ref({ value, file }, { load, addChild }) {
const { dir } = path.parse(file);
const src = path.join(dir, file);
return load({
file: src,
value: JSON.parse(await readFile(src, "utf-8")),
});
},
}
);
```
**The execution of load inside `$ref` allows associating an additional import on the tree object returned by loadData**, the tree object is managed by the pkg [@uppercod/imported](https://github.com/UpperCod/imported).