@speedy/json-extends
Version:
Extend a JSON file with one or many existing files.
67 lines (51 loc) • 2.07 kB
Markdown
[](https://circleci.com/gh/alan-agius4/speedy-json-extends)
[](https://www.npmjs.com/package/@speedy/json-extends)
[](https://david-dm.org/alan-agius4/speedy-json-extends)
[](https://david-dm.org/alan-agius4/speedy-json-extends?type=dev)
Extend a JSON file with one or many existing files.
```core
npm install @speedy/json-extends --save
```
Retrieve a JSON file. Supports `extends` with one or many existing JSON files.
Extends supports also Named Extends paths, as shown in the example.
| Param | Type | Required | Description |
|--------------|---------------------------|----------|------------------------------------------|
| filePath | `string` | true | path to a JSON file. |
| namedExtends | `{[id: string]: string }` | false | A key value pair of named extends paths |
TypeScript
```ts
import { json } from "@speedy/json-extends";
const named = {
"@speedy/commit-msg-hook:latest": "./node_modules/config/config.json"
};
json.read("local-config.json", named)
.then(content => {
// json content
});
```
JSON file
```json
{
"extends": [
"@speedy/commit-msg-hook:latest",
"./local/config.json"
],
"rules": {
"no-dash": true
}
}
```
Synchronous version of `json.read()`.
TypeScript
```ts
import { json } from "@speedy/json-extends";
const named = {
"@speedy/commit-msg-hook:latest": "./node_modules/config/config.json"
};
const content = json.readSync("local-config.json", named);
```