{"id":13495913,"url":"https://github.com/npm/ini","last_synced_at":"2025-05-12T11:17:41.266Z","repository":{"id":482643,"uuid":"2167680","full_name":"npm/ini","owner":"npm","description":"An ini parser/serializer in JavaScript","archived":false,"fork":false,"pushed_at":"2025-04-09T14:30:23.000Z","size":223,"stargazers_count":788,"open_issues_count":13,"forks_count":204,"subscribers_count":42,"default_branch":"main","last_synced_at":"2025-05-12T11:17:32.390Z","etag":null,"topics":["npm-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-08-07T05:41:15.000Z","updated_at":"2025-05-12T10:50:54.000Z","dependencies_parsed_at":"2024-04-20T22:53:32.561Z","dependency_job_id":"9e21400a-488f-4ef3-8600-c1439dffedfe","html_url":"https://github.com/npm/ini","commit_stats":{"total_commits":164,"total_committers":27,"mean_commits":6.074074074074074,"dds":0.6524390243902439,"last_synced_commit":"63c421ecbbcb6c78b61aeb870099928ee78f8452"},"previous_names":["isaacs/ini"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/ini/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253726906,"owners_count":21954096,"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":["npm-cli"],"created_at":"2024-07-31T19:01:39.618Z","updated_at":"2025-05-12T11:17:41.238Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","readme":"\nAn INI format parser \u0026 serializer.\n\n## Note\n\n-   Sections are treated as nested objects.\n\n-   Section-less items are treated as globals.\n\n## Usage\n\nConsider an INI file such as the following:\n\n```ini\n; This comment is being ignored\nscope = global\n\n[database]\nuser = dbuser\npassword = dbpassword\ndatabase = use_this_database\n\n[paths.default]\ndatadir = /var/lib/data\narray[] = first value\narray[] = second value\narray[] = third value\n```\n\nYou can **read**, **modify** and **write** it like so:\n\n```js\nimport { writeFile , readFile } from 'node:fs/promises'\nimport { stringify , parse } from 'ini'\n\n//  Read INI file as text\n\nlet text = await readFile(`./Original.ini`,{\n    encoding : 'utf-8'\n})\n\n//  Parse text data to object\n\nconst config = parse(text)\n\n//  Modify data object\n\nconfig.scope = 'local'\nconfig.database.database = 'use_another_database'\nconfig.paths.default.tmpdir = '/tmp'\ndelete config.paths.default.datadir\nconfig.paths.default.array.push('fourth value')\n\n//  Stringify data object\n\ntext = stringify(config,{ \n    section : 'section' \n})\n\n//  Write INI file as text\n\nawait writeFile(`./Modified.ini`,text)\n```\n\nThe written file will contain the following:\n\n```ini\n[section]\nscope=local\n[section.database]\nuser=dbuser\npassword=dbpassword\ndatabase=use_another_database\n[section.paths.default]\ntmpdir=/tmp\narray[]=first value\narray[]=second value\narray[]=third value\narray[]=fourth value\n```\n\n## API\n\n### Parse\n\nAttempts to turn the given INI string into a nested data object.\n\n```js\n// You can also use `decode`\nconst object = parse(`\u003cINI Text\u003e`) \n```\n\n### Stringify\n\nEncodes the given data object as an INI formatted string.\n\n```js\n// You can also use `encode`\nstringify(object,{\n\n    /**\n     *  Whether to insert spaces before \u0026 after `=`\n     * \n     *  Disabled by default to have better \n     *  compatibility with old picky parsers.\n     */\n\n    whitespace : false ,\n\n    /**\n     *  Whether to align the `=` character for each section.\n     *  -\u003e Also enables the `whitespace` option\n     */\n\n    align : false ,\n\n    /**\n     *  Identifier to use for global items \n     *  and to prepend to all other sections.\n     */\n\n    section ,\n\n    /**\n     *  Whether to sort all sections \u0026 their keys alphabetically.\n     */\n\n    sort : false ,\n\n    /**\n     *  Whether to insert a newline after each section header.\n     * \n     *  The TOSHIBA \u0026 FlashAir parser require this format. \n     */\n\n    newline : false ,\n\n    /**\n     *  Which platforms line-endings should be used.\n     * \n     *  win32 -\u003e CR+LF\n     *  other -\u003e LF\n     * \n     *  Default is the current platform\n     */\n\n    platform ,\n\n    /**\n     *  Whether to append `[]` to array keys.\n     * \n     *  Some parsers treat duplicate names by themselves as arrays\n     */\n\n    bracketedArray : true\n\n})\n```\n\n*For backwards compatibility any string passed as the*  \n*options parameter is treated as the `section` option.*\n\n```js\nstringify(object,'section')\n```\n\n### Un / Escape\n\nTurn the given string into a safe to  \nuse key or value in your INI file.\n\n```js\nsafe(`\"unsafe string\"`) // -\u003e \\\"unsafe string\\\"\n```\n\nOr reverse the process with:\n\n```js\nunsafe(`\\\\\"safe string\\\\\"`) // -\u003e \"safe string\"\n```\n","funding_links":[],"categories":["JavaScript","Repository","others"],"sub_categories":["Parsing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Fini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fini/lists"}