Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daiyam/node-jsonc-preprocessor
https://github.com/daiyam/node-jsonc-preprocessor
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/daiyam/node-jsonc-preprocessor
- Owner: daiyam
- License: mit
- Created: 2021-08-12T16:44:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-17T12:02:22.000Z (almost 2 years ago)
- Last Synced: 2025-01-02T22:04:35.101Z (8 days ago)
- Language: TypeScript
- Size: 159 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[@daiyam/jsonc-preprocessor](https://github.com/daiyam/node-jsonc-preprocessor)
===============================================================================[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![NPM Version](https://img.shields.io/npm/v/@daiyam/jsonc-preprocessor.svg?colorB=green)](https://www.npmjs.com/package/@daiyam/jsonc-preprocessor)
[![License](https://img.shields.io/badge/donate-ko--fi-green)](https://ko-fi.com/daiyam)
[![License](https://img.shields.io/badge/donate-liberapay-green)](https://liberapay.com/daiyam/donate)
[![License](https://img.shields.io/badge/donate-paypal-green)](https://paypal.me/daiyam99)Disable/enable/ignore blocks based on rules found in the JSONC text
Getting Started
---------------With [node](http://nodejs.org) previously installed:
npm install @daiyam/jsonc-preprocessor
```typescript
import {transform} from '@daiyam/jsonc-preprocessor';const TYPES = {
version: 'version',
};function preprocessJSON(text: string, {host: string, os: string, editor: string, version: string}): string {
const args = {
host,
os,
editor,
version,
};return transform(text, TYPES, args);
}
```Directives
----------### `enable`
```
{
// #enable(os="linux")
// "key": "foobar"
}
```If `os` is equal to `linux`, the block `"key": "foobar"` will be uncommented. If not, the block will be commented.
### `if/else`
```
{
// #if(os="mac")
// "key": "foo"
// #elif(os="windows", host="host1"|"host2")
// "key": "bar"
// #elif(version>="2.18.1")
// "key": "qux"
// #else
// "key": "baz"
// #endif
}
````#elif(os="windows", host="host1"|"host2")` is `true` when `os` equals `windows` ***and*** `host` equals `host1` or `host2`.
`#elif(os="windows", version>="2.18.1")` is `true` when `version` is greater than or equal to `2.18.1`.### `ignore`
```
{
// #ignore
"key": "foobar"
}
```The block `"key": "foobar"` will always be removed.
### `rewrite-enable`/`rewrite-disable`
```
{
// #rewrite-enable
// #if(os="mac"|"windows")
// "key": "#{os}"
// #else
// "key": "linux"
// #endif
// #rewrite-disable// #if(os="mac"|"windows")
// "key2": "#{os}"
// #else
// "key2": "linux"
// #endif
}
````key` will have the following values: `max`, `windows` or `linux`.
`key2` will have the following values: `#{os}` or `linux`.### `rewrite-next-line`
```
{
// #rewrite-next-line
// "key": "#{os}"
}
```Condition
---------```
condition = expression ("," expression)*
expression = (unary-operator identifier) | (identifier operator values)
identifier = \w+
operator = "=" | "!=" | "<" | "<=" | ">" | ">="
unary-operator = "?" | "!?"
values = value ("|" value)*
````value` is a double quote string.
The operators `<`, `<=`, `>`, `>=` are only working for the identifier `version`.Donations
---------Support this project by becoming a financial contributor.
ko-fi.com/daiyam
liberapay.com/daiyam/donate
paypal.me/daiyam99
License
-------Copyright © 2021-present Baptiste Augrain
Licensed under the [MIT license](https://opensource.org/licenses/MIT).