UNPKG

json-parser-yaml-converter

Version:
243 lines (137 loc) 4.33 kB
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> ### Table of Contents * [buildAst][1] * [buildObject][2] * [Parameters][3] * [buildPair][4] * [Parameters][5] * [buildValue][6] * [Parameters][7] * [buildArray][8] * [Parameters][9] * [colors][10] * [index][11] * [lexer][12] * [loggers][13] * [jsonLogger][14] * [Parameters][15] * [json2Yaml][16] * [Parameters][17] * [parser][18] * [jsonParse][19] * [Parameters][20] * [astToObject][21] * [Parameters][22] * [yamlConverter][23] * [jsonToYaml][24] * [Parameters][25] * [astToYamlString][26] * [Parameters][27] ## buildAst This module exports the functions to build the AST. ## buildObject Builds an object. ### Parameters * `pairs` **[Array][28]** A list of pairs to build the object. Returns **[Object][29]** The AST of the object. ## buildPair Builds a pair. ### Parameters * `key` **[Object][29]** Key of the pair. * `value` **[Object][29]** Value of the pair. Returns **[Object][29]** The AST of the pair. ## buildValue Builds the value of a JSON file. ### Parameters * `value` **[Object][29]** Value to build. * `value.0` &#x20; Returns **[Object][29]** The AST of the value. ## buildArray Builds an array. ### Parameters * `array` **[Array][28]** Array to build. * `array.0` &#x20; Returns **[Object][29]** The AST of the array. ## colors This module contains the colors used in the CLI. ## index This module exports the parser and yamlConverter functions. ## lexer This module exports the main lexer. ## loggers This module contains the functions jsonLogger and json2Yaml that log messages to the console. ## jsonLogger Checks if a JSON file is valid. ### Parameters * `jsonFile` **[string][30]** JSON file to check. Returns **void**&#x20; ## json2Yaml Converts a JSON file to YAML format. ### Parameters * `jsonFile` **[string][30]** JSON file to convert. * `options` **[Object][29]** Command line options. Returns **void**&#x20; ## parser This module contains the function jsonParse that parses a JSON file. ## jsonParse Parses a JSON file. ### Parameters * `jsonFile` **[string][30]** JSON file to parse. * `ast` **[boolean][31]** If true, returns the AST instead of the object. (optional, default `false`) <!----> * Throws **[Error][32]** If the JSON file could not be parsed. Returns **[Object][29]** The parsed JSON file. ## astToObject Converts an AST to an object. ### Parameters * `ast` **[Object][29]** AST to convert. Returns **[Object][29]** The object. ## yamlConverter This module contains the function jsonToYaml that converts a JSON file to a YAML file. ## jsonToYaml Converts a JSON file to a YAML file. ### Parameters * `jsonFile` **[string][30]** JSON file to convert. * `yamlFile` **[string][30]** YAML file to output. <!----> * Throws **[Error][32]** If the JSON file could not be converted to YAML. Returns **void**&#x20; ## astToYamlString Converts a JSON AST to a YAML string. ### Parameters * `ast` **[Object][29]** AST to convert. * `indent` **[number][33]** Current indentation level. (optional, default `0`) Returns **[string][30]** The YAML string. [1]: #buildast [2]: #buildobject [3]: #parameters [4]: #buildpair [5]: #parameters-1 [6]: #buildvalue [7]: #parameters-2 [8]: #buildarray [9]: #parameters-3 [10]: #colors [11]: #index [12]: #lexer [13]: #loggers [14]: #jsonlogger [15]: #parameters-4 [16]: #json2yaml [17]: #parameters-5 [18]: #parser [19]: #jsonparse [20]: #parameters-6 [21]: #asttoobject [22]: #parameters-7 [23]: #yamlconverter [24]: #jsontoyaml [25]: #parameters-8 [26]: #asttoyamlstring [27]: #parameters-9 [28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array [29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [32]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [33]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number