https://github.com/alan-agius4/speedy-json-extends
Extend a JSON file with one or many existing files
https://github.com/alan-agius4/speedy-json-extends
extend extendable extends json json-files node nodejs utility
Last synced: about 1 year ago
JSON representation
Extend a JSON file with one or many existing files
- Host: GitHub
- URL: https://github.com/alan-agius4/speedy-json-extends
- Owner: alan-agius4
- Created: 2017-04-01T14:50:04.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-28T13:31:41.000Z (almost 2 years ago)
- Last Synced: 2025-04-09T19:51:03.823Z (about 1 year ago)
- Topics: extend, extendable, extends, json, json-files, node, nodejs, utility
- Language: TypeScript
- Size: 30.3 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @speedy/json-extends
[](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.
### Installation
```core
npm install @speedy/json-extends --save
```
### Usage
#### json.read(filePath, [namedExtends]) ⇒ `Promise`
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
}
}
```
#### json.readSync(filePath, [namedExtends]) ⇒ `T`
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);
```