{"bugs":{"url":"https://github.com/un-ts/toml-tools/issues"},"dist":{"shasum":"6dde715584cd8ea46f91eeec8a32a2ba0352f5ca","tarball":"https://registry.npmjs.org/@toml-tools/parser/-/parser-1.0.1.tgz","fileCount":18,"integrity":"sha512-W+YdnB8KDgKjIqhoArEXjiTTPnKSXVvI/B+raHfou9+sip3rxhzVsELn46GG7dZyNHyu9pS+gYgYrdF9c5AQDg==","signatures":[{"sig":"MEYCIQDfsMAEqEUq666v+LUDLd1WwN2Q37bDfacEp3zgc+XZJQIhAJ2nK3FALg975beko+k6MM0CvuWPrQk3QyTKrWeabTu3","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":223069},"main":"lib/api.js","name":"@toml-tools/parser","type":"module","types":"api.d.ts","readme":"[![npm](https://img.shields.io/npm/v/@toml-tools/parser.svg)](https://www.npmjs.com/package/@toml-tools/parser)\n\n# TOML-Tools/parser\n\nA Toml **Parser** implemented in JavaScript using the [Chevrotain](https://github.com/SAP/chevrotain) Parsing Toolkit.\nThis parser outputs a Chevrotain [**C**oncrete **S**yntax **T**ree](https://sap.github.io/chevrotain/docs/guide/concrete_syntax_tree.html)\nWhich is a low level data structure that represents the **whole** syntax tree.\n\n- including comments and newline information.\n- Including full position information on every Token.\n\nThis means that this parser could be **re**-used to construct many different kinds of Toml related tooling:\n\n- Toml to JSON compilers.\n- Toml to Yaml compilers.\n  - comments information is needed.\n- Toml source code beautifiers.\n  - Once again comments information is needed.\n- Toml Schema Validator\n  - Full position information is required for useful error messages.\n- and more...\n\n## Installation\n\n```bash\nyarn add @toml-tools/parser\n# or if you prefer npm\nnpm install @toml-tools/parser\n```\n\n## APIs\n\nThis package's [APIs](./api.d.ts) are exported as a TypeScript definition file.\n\n## Usage\n\n```javascript\nconst {\n  parse,\n  BaseTomCstVisitor,\n  BaseTomlCstVisitorWithDefaults,\n} = require(\"@toml-tools/parser\");\n\nconst input = `\n# This is a TOML document.\n[database]\nserver = \"192.168.1.1\"\nports = [ 8001, 8001, 8002 ]\n`;\nconst tomlCst = parse(input);\n\n// Read the manual for using the Chevrotain CST visitor:\n// - https://sap.github.io/chevrotain/docs/guide/concrete_syntax_tree.html#cst-visitor\n// - The full APIs for the CST visitor are defined in api.d.ts linked above\nclass KeyNamesCollector extends BaseTomlCstVisitorWithDefaults {\n  constructor() {\n    super();\n    this.tableKeyNames = [];\n  }\n\n  stdTable(ctx) {\n    this.tableKeyNames.push(this.visit(ctx.key));\n  }\n\n  key(ctx) {\n    const keyImages = ctx.IKey.map((keyTok) => keyTok.image);\n    const newKey = keyImages.join(\".\");\n    return newKey;\n  }\n}\n\nconst myVisitor = new KeyNamesCollector();\nmyVisitor.visit(cst);\n\nconsole.log(myVisitor.tableKeyNames.length); // 1\nconsole.log(myVisitor.tableKeyNames[0]); // \"database\"\n```\n","exports":{".":{"types":"./api.d.ts","default":"./lib/api.js"},"./package.json":"./package.json"},"gitHead":"d7dfe8f919e0fde556e35d70f216a40cb41f8497","license":"MIT","scripts":{"test":"mocha ./test/*spec.js","benchmark":"node ./benchmark/benchmark.js"},"_npmUser":{"name":"jounqin","email":"admin@1stg.me"},"homepage":"https://github.com/un-ts/toml-tools/tree/master#readme","keywords":["toml","parser"],"repository":{"url":"git+https://github.com/un-ts/toml-tools.git#master","type":"git"},"_npmVersion":"8.19.4","description":"TOML Parser Implemented in JavaScript","directories":{},"maintainers":[{"name":"jounqin","email":"admin@1stg.me"},{"name":"bd82","email":"shahars@protonmail.com"}],"_nodeVersion":"16.20.2","dependencies":{"chevrotain":"^11.0.1","@toml-tools/lexer":"^1.0.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"toml":"^3.0.0","toml-j0.4":"^1.1.1","@iarna/toml":"^2.2.5","@sgarciac/bombadil":"^2.3.0"},"_npmOperationalInternal":{"tmp":"tmp/parser_1.0.1_1707757498635_0.3861170447044018","host":"s3://npm-registry-packages"},"_id":"@toml-tools/parser@1.0.1","version":"1.0.1"}