{"id":17855620,"url":"https://github.com/nebrius/ini-builder","last_synced_at":"2025-06-14T23:02:43.979Z","repository":{"id":29169608,"uuid":"32700185","full_name":"nebrius/ini-builder","owner":"nebrius","description":"Node.js module for reading and writing INI and *NIX config files","archived":false,"fork":false,"pushed_at":"2017-09-14T19:15:52.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-13T19:14:40.700Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"stat6250/course-questions-wiki","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nebrius.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-22T23:01:36.000Z","updated_at":"2016-12-11T11:25:18.000Z","dependencies_parsed_at":"2022-08-17T18:35:08.732Z","dependency_job_id":null,"html_url":"https://github.com/nebrius/ini-builder","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/nebrius/ini-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fini-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fini-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fini-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fini-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nebrius","download_url":"https://codeload.github.com/nebrius/ini-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fini-builder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259896115,"owners_count":22928327,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T02:23:49.779Z","updated_at":"2025-06-14T23:02:43.935Z","avatar_url":"https://github.com/nebrius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"INI Builder\n===========\n\nINI builder is a tool for reading and writing INI and certain *NIX configuration files.\n\n## Installation\n\n```\nnpm install ini-builder\n```\n\n## Usage\n\nINI builder takes in a string and parses it into an AST-like structure. This structure can then be edited, modifying sections, adding sections, removing sections, etc, and then serialized back to a string.\n\n## Data Format\n\nThe `parse` method returns an array, with each entry corresponding to a line, or group of lines, in the document. Each entry will be in one of two forms. The `serialize` method accepts this data format.\n\nThe first form is a configuration entry, i.e. a key-value pair. This will always represent exactly one line in the document, and has the form:\n\n```JavaScript\n{\n  value: [value],\n  path: [path],\n  comment: [comment]\n}\n```\n\nThe value is the value of the entry, and is always a string. The comment is any comment that appears _after_ the entry on the same line and is also a string. The path is one _or more_ keys for the entry. Some INI files support namespaced keys. As an example, let's say we're given the entry:\n\n```ini\nfoo=bar=baz ; Setting foo bar to baz\n```\n\nThe data entry would then be\n\n```JavaScript\n{\n  value: 'baz',\n  path: ['foo', 'bar']\n  comment: '; Setting foo bar to baz'\n}\n```\n\nThe second form of entry is a non-configuration entry, i.e. comments and whitespace. This may represent one or more lines in the document, and has the form:\n\n```JavaScript\n{\n  comment: [comment]\n}\n```\n\nThese entries will always consume all content between configuration entires or the start/end of the document. For example, let's say we have the following document:\n\n```ini\n; This is a document\n\n; Let's set a value\nfoo=bar\n\n; Now let's set another\nfoo2=foo3=bar2 ; Let's get fancy\n\n; And let's end the document\n```\n\nThis will produce the following data:\n\n```JavaScript\n[{\n  comment: '; This is a document\\n\\n; Let\\'s set a value'\n}, {\n  value: 'bar',\n  path: [ 'foo' ]\n}, {\n  comment: '\\n; Now let\\'s set another'\n}, {\n  comment: '; Let\\'s get fancy',\n  value: 'bar2',\n  path: [ 'foo2', 'foo3' ]\n}, {\n  comment: '\\n; And let\\'s end the document\\n'\n}]\n```\n\n## Editing or creating data\n\nEditing parsed data, or creating your own, is straight forward. The data returned from `parse` is just a regular JavaScript array, so you can modify it like you can any other JavaScript array.\n\n### Finding entries\n\nINI builder provides three helper methods for searching for data: `hasPath`, `find`, and `findAll`. All of these methods take parsed data as their first argument, and the path in question for the second. The path can be a string representing a single segment path, or an array of strings.\n\n```JavaScript\nvar hasEntry = iniBuilder.hasPath(data, 'foo');\nvar entry = iniBuilder.find(data, 'foo');\nvar entries = iniBuilder.findAll(data, 'foo');\n```\n\n### Adding new entries\n\nTo add a new entry, just push it onto the array:\n\n```JavaScript\ndata.push({\n  path: ['myNewEntry']\n  value: 'The value of my new entry'\n});\n```\n\n### Editing existing entries\n\nTo edit existing entries, you must first get a reference to that entry. You can iterate over the array yourself, or you can use the `find` method, e.g.:\n\n```JavaScript\nvar entry = iniBuilder.find(data, 'foo');\nentry.value = 'bar2';\n```\n\n### Deleting entries\n\nYou can use any of the array prototype methods to remove one or more elements. Splice is usually the one you want to use:\n\n```JavaScript\nvar entry = iniBuilder.find(data, 'foo');\ndata.splice(data.indexOf(entry), 1);\n```\n\n## Complete Example\n\nHere is a complete example that reads in some data from `data.ini` and writes it out to `modified-data.ini`.\n\n```JavaScript\n\nvar fs = require('fs');\nvar iniBuilder = require('ini-builder');\n\n// Read in the file and parse the raw information\nvar data = iniBuilder.parse(fs.readFileSync('data.ini'));\n\n// Update the value we want to change\niniBuilder.find(data, 'foo').value = 'bar2';\n\n// Save the results\nfs.writeFileSync('modified-data.ini', iniBuilder.serialize(data));\n```\n\n## API\n\n### parse(rawData, options)\n\nParses the raw data into the data format described above.\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003erawData\u003c/td\u003e\n    \u003ctd\u003eString | Buffer\u003c/td\u003e\n    \u003ctd\u003eThe data to parse\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eoptions (optional)\u003c/td\u003e\n    \u003ctd\u003eObject\u003c/td\u003e\n    \u003ctd\u003eThe options to parse with\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003e\n      \u003ctable\u003e\n        \u003cthead\u003e\n          \u003ctr\u003e\n            \u003cth\u003eProperty\u003c/th\u003e\n            \u003cth\u003eType\u003c/th\u003e\n            \u003cth\u003eDescription\u003c/th\u003e\n          \u003c/tr\u003e\n        \u003c/thead\u003e\n        \u003ctr\u003e\n          \u003ctd\u003ecommentDelimiter\u003c/td\u003e\n          \u003ctd\u003eString\u003c/td\u003e\n          \u003ctd\u003eThe character used to delimit comments. Defaults to \";\"\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: The parsed data.\n\n_Note: INI builder does not currently support sections._\n\n### hasPath(data, path)\n\nChecks if the given path is found in the data\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003edata\u003c/td\u003e\n    \u003ctd\u003eArray\u003c/td\u003e\n    \u003ctd\u003eData conforming to the parsed data spec\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003epath\u003c/td\u003e\n    \u003ctd\u003eString | Array\u003c/td\u003e\n    \u003ctd\u003eThe path to search for\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: A boolean indicating whether or not the given path was found in the data.\n\n### find(data, path)\n\nFinds the most recent entry (i.e. occurs last in the file) at the given path and returns it, if it exists.\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003edata\u003c/td\u003e\n    \u003ctd\u003eArray\u003c/td\u003e\n    \u003ctd\u003eData conforming to the parsed data spec\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003epath\u003c/td\u003e\n    \u003ctd\u003eString | Array\u003c/td\u003e\n    \u003ctd\u003eThe path to search for\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: The entry if one was found, otherwise undefined. If more than one entry matches the given path, only the last entry is returned.\n\n### findAll(data, path)\n\nFinds all entries at the given path and returns them.\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003edata\u003c/td\u003e\n    \u003ctd\u003eArray\u003c/td\u003e\n    \u003ctd\u003eData conforming to the parsed data spec\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003epath\u003c/td\u003e\n    \u003ctd\u003eString | Array\u003c/td\u003e\n    \u003ctd\u003eThe path to search for\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: An array containing 0 or more entries.\n\n## serialize(data, options)\n\nSerializes the data back to a string.\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003edata\u003c/td\u003e\n    \u003ctd\u003eArray\u003c/td\u003e\n    \u003ctd\u003eThe data to serialize\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eoptions (optional)\u003c/td\u003e\n    \u003ctd\u003eObject\u003c/td\u003e\n    \u003ctd\u003eThe options to serialize with\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003e\n      \u003ctable\u003e\n        \u003cthead\u003e\n          \u003ctr\u003e\n            \u003cth\u003eProperty\u003c/th\u003e\n            \u003cth\u003eType\u003c/th\u003e\n            \u003cth\u003eDescription\u003c/th\u003e\n          \u003c/tr\u003e\n        \u003c/thead\u003e\n        \u003ctr\u003e\n          \u003ctd\u003ecommentDelimiter\u003c/td\u003e\n          \u003ctd\u003eString\u003c/td\u003e\n          \u003ctd\u003eThe character used to delimit comments. Defaults to \";\"\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nLicense\n=======\n\nThe MIT License (MIT)\n\nCopyright (c) 2015-2017 Bryan Hughes \u003cbryan@nebri.us\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fini-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnebrius%2Fini-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fini-builder/lists"}