1.3.2 • Published 3 years ago

@credenceanalytics/parsifier v1.3.2

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
3 years ago

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

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago