README
@daiyam/jsonc-preprocessor
Disable/enable/ignore blocks based on rules found in the JSONC text
Getting Started
With node previously installed:
npm install @daiyam/jsonc-preprocessor
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.
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.