{"_id":"@3rd/ini","name":"@3rd/ini","dist-tags":{"latest":"5.0.0"},"versions":{"5.0.0":{"name":"@3rd/ini","version":"5.0.0","description":"An ini encoder/decoder for node","author":{"name":"GitHub Inc."},"type":"module","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","engines":{"node":">=22"},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"},"license":"ISC","_id":"@3rd/ini@5.0.0","gitHead":"121e8d7bc7e195b6a22fb11584fda7909d6755c9","_nodeVersion":"23.10.0","_npmVersion":"11.2.0","dist":{"integrity":"sha512-dFhNvc7M8vAGsie9zBws3EHPqCxBtB0cTzMoM5DYp8HMtu8vhXASKVdFywXPaAMC6H45paPZyLFtV4HdRSSmwQ==","shasum":"193a98f8a50f3b8f271031d64b5d45370c8e1fe9","tarball":"https://registry.npmjs.org/@3rd/ini/-/ini-5.0.0.tgz","fileCount":4,"unpackedSize":7291,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHasTQViI7eUshS1s8ylyb0y8bOK9/xkouCVuu7k4RuSAiEArHZbrwRIOBzRFJd/sWJEhWyFGhCcgGzQgljktWCCWeo="}]},"_npmUser":{"name":"scriptpower","email":"scriptpower@qq.com"},"directories":{},"maintainers":[{"name":"scriptpower","email":"scriptpower@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ini_5.0.0_1742459609920_0.33208354120977535"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-20T08:33:29.769Z","5.0.0":"2025-03-20T08:33:30.099Z","modified":"2025-03-20T08:33:30.733Z"},"maintainers":[{"name":"scriptpower","email":"scriptpower@qq.com"}],"description":"An ini encoder/decoder for node","author":{"name":"GitHub Inc."},"license":"ISC","readme":"# @3rd/ini\n\n> An INI format parser & serializer.\n\n## Note\n\n- Sections are treated as nested objects.\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 '@3rd/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(`<INI Text>`) \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 & 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     *  -> 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 & their keys alphabetically.\n     */\n\n    sort : false ,\n\n    /**\n     *  Whether to insert a newline after each section header.\n     * \n     *  The TOSHIBA & FlashAir parser require this format. \n     */\n\n    newline : false ,\n\n    /**\n     *  Which platforms line-endings should be used.\n     * \n     *  win32 -> CR+LF\n     *  other -> 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\"`) // -> \\\"unsafe string\\\"\n```\n\nOr reverse the process with:\n\n```js\nunsafe(`\\\\\"safe string\\\\\"`) // -> \"safe string\"\n```\n","readmeFilename":"README.md","_rev":"1-4e0b1470d2781501f2658a167409bdfa"}