@credenceanalytics/parsifier
v1.3.2
Published
Config file parser
Downloads
9
Readme
Parsifier
Library to parse and modify config files
Supported file types
- json
- js
- xml
- env
- jds
Usage
JSON
- Update - existing config in the file
/** * @param filePath - path of the file * @param key - key to update * @param value - new value of that key */ updateJson((filePath: string), (key: string), (value: any));
- Append - new config to the file
/** * @param filePath - path of the file * @param key - key to append * @param value - value of that key */ appendJson((filePath: string), (key: string), (value: any));
- Delete - existing config in the file
/** * @param filePath - path of the file * @param key - key to delete */ deleteJson((filePath: string), (key: string));
Example
const Parsifier = require('@credenceanalytics/parsifier');
Parsifier.updateJson('C:/Users/hello.json', 'key1', 'newValue'});
Parsifier.appendJson('C:/Users/hello.json', 'key2', 'value'});
Parsifier.deleteJson('C:/Users/hello.json', 'key2'});
XML
Update - existing config in the file
/** * @param filePath - path of the file * @param key - key to update * @param value - new value of that key */ updateXml((filePath: string), (key: string), (value: any));
Append - new config to the file
/** * @param filePath - path of the file * @param key - key to append * @param value - value of that key */ appendXml((filePath: string), (key: string), (value: any));
Delete - existing config in the file
/** * @param filePath - path of the file * @param key - key to delete */ deleteXml((filePath: string), (key: string));
Example
const Parsifier = require('@credenceanalytics/parsifier');
Parsifier.updateXml('C:/Users/sample.xml', 'name', 'John');
Parsifier.appendXml('C:/Users/sample.xml', 'name', 'Bob');
Parsifier.deleteXml('C:/Users/sample.xml', 'employees.details[0].contact');
Note:
Internally it uses xml-js.
Refer compact value of xml-js to know more about xml notation.
Jds/Js/Env
Txt
below representsJds
/Js
/Env
Update - existing config in the file
/** * @param supportExtension - Extensions that are supported (passed as bind()) * @param filePath - path of the file * @param searchValue - old value to replace * @param replaceValue - new value */ updateTxt((filePath: string), (searchValue: string), (replaceValue: string));
Append - new config to the file
/** * @param supportExtension - Extensions that are supported (passed as bind()) * @param filePath - path of the file * @param newValue - value to add */ appendTxt((filePath: string), (newValue: string));
Delete - existing config in the file
/** * deletes something * * @param filePath path of the file * @param searchValue value to delete */ deleteTxt((filePath: string), (searchValue: string));
Example
const Parsifier = require('@credenceanalytics/parsifier');
Parsifier.updateJds('C:/Users/sample.jds', `var a="010"`, `var a="101"`});
Parsifier.appendJds('C:/Users/sample.jds', `var b="020"`});
Parsifier.deleteJds('C:/Users/sample.jds', `var b="020"`});
Note:
Instead ofParsifier.<process>Jds()
in above example, you can useParsifier.<process>Js()
orParsifier.<process>Env()
based on your file type, whereprocess
iseither
update
orappend
ordelete
.
Encrypted Files
To modify encrypted files, pass an object as last parameter specifying path of encrypted keys. Object should look like:
const encryptionKeys = { publicKey: 'PATH HERE', privateKey: 'PATH HERE' };
Example
const Parsifier = require('@credenceanalytics/parsifier');
Parsifier.updateJson('C:/Users/hello.json', 'key1', 'newValue'}, encryptionKeys);