@credenceanalytics/parsifier
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

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 represents Jds/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 of Parsifier.<process>Jds() in above example, you can use Parsifier.<process>Js() or Parsifier.<process>Env() based on your file type, where process is either update or append or delete.

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);

Package Sidebar

Install

npm i @credenceanalytics/parsifier

Weekly Downloads

3

Version

1.3.2

License

ISC

Unpacked Size

28.4 kB

Total Files

8

Last publish

Collaborators

  • jiteshsuthar
  • atulknowsme
  • shruti_shende
  • sonalnadkar
  • cred-shubham
  • sagarf
  • prajaktacred
  • mandakadam
  • prabhuvikas
  • jimmyjammerx
  • suraj_chavan
  • mohinim18