{"id":15834467,"url":"https://github.com/kaelzhang/rc-parser","last_synced_at":"2026-04-16T14:06:42.889Z","repository":{"id":57348794,"uuid":"143230416","full_name":"kaelzhang/rc-parser","owner":"kaelzhang","description":"Find and parse rc, rc.js, rc.yaml or etc if any one of them exists","archived":false,"fork":false,"pushed_at":"2018-08-03T04:33:18.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T13:16:19.156Z","etag":null,"topics":["nodejs","rc","read-rc","runtime-config","yaml"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.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":"2018-08-02T02:14:32.000Z","updated_at":"2021-07-24T21:20:41.000Z","dependencies_parsed_at":"2022-09-16T05:11:59.037Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/rc-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frc-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frc-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frc-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frc-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/rc-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246397404,"owners_count":20770549,"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":["nodejs","rc","read-rc","runtime-config","yaml"],"created_at":"2024-10-05T14:01:31.597Z","updated_at":"2026-04-16T14:06:37.861Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/rc-parser.svg?branch=master)](https://travis-ci.org/kaelzhang/rc-parser)\n[![Coverage](https://codecov.io/gh/kaelzhang/rc-parser/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/rc-parser)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/rc-parser?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/rc-parser)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/rc-parser.svg)](http://badge.fury.io/js/rc-parser)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/rc-parser.svg)](https://www.npmjs.org/package/rc-parser)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/rc-parser.svg)](https://david-dm.org/kaelzhang/rc-parser)\n--\u003e\n\n# rc-parser\n\nFind and parse rc, rc.js, rc.yaml or etc if any one of them exists. `rc-parser` searches the giving path(s), and parses out that if the runtime configuration file with the certain extension listed in `options.extensions` exists. If found, it parses and returns the config object.\n\n`rc-parser` featured in:\n\n- Supports to define custom parser for a certain file type.\n- Better error messages and syntax hint.\n- Fully customizable.\n\n## Install\n\n```sh\n$ npm i rc-parser\n```\n\n## Usage\n\n```js\nconst parse = require('rc-parser')\nconst sync = require('rc-parser/sync')  // The synchronous version\n\nconst options = {\n  path: __dirname,  // current directory\n  name: '.travis'\n}\n\nconst rc = await parse(options)\n\nconsole.log(rc.extension)         // 'yml'\nconsole.log(rc.value.language)    // 'node_js'\n\nconsole.log(sync(options))  // the same as rc\n```\n\n### Define your own parsers to support more file types\n\n```js\nconst ini = require('ini')\n\nparse({\n  path: '/path/to',\n  name: 'somerc',\n  extensions: ['ini', 'js'],\n  parsers: {\n    ini (content) {\n      return ini.parse(content)\n    }\n  }\n})\n.then(({extension, value}) =\u003e {\n  console.log(extension)   // 'ini'\n  console.log(value)       // the parsed object from ini\n})\n```\n\n## APIs\n\n### parse(options): Promise\u0026lt;RCResult\u0026gt;\n\n- **options**\n  - **path** `string | Array\u003cstring\u003e` the search path(s) for the rc file.\n  - **name** `string` the prefix name of the rc file to search.\n  - **extensions** `Extensions | undefined`\n  - **parsers** `Object{[Extension]: ParserFunction}`\n  - **not_found_error** `NotFoundErrorFunction` will be executed if no rc files are found.\n  - **code_frame** `CodeFrameFunction | false`\n\nReturns `Promise\u003cRCResult\u003e`\n\n```ts\ntype Extension = string | parse.NO_EXT\ntype Extensions = Array\u003cExtension\u003e\n```\n\n`options.extensions` specifies the extension priority for searching rc files. Defaults to `['yaml', 'yml', 'js', parse.NO_EXT]`\n\n`parse.NO_EXT` is a special extension which indicates there is no extension after `name`\n\n```sh\n# Suppose: options.name === '.eslintrc'\n#             filepath      |  extension\n# ------------------------- | -----------------\n/path/to/project\n          |-- .eslintrc        # rc-parser.NO_EXT\n          |-- .eslintrc.js     # 'js'\n          |-- .eslintrc.yaml   # 'yaml'\n```\n\nIf `options.extensions` as `['yaml', 'js', NO_EXT]`, then we will get `.eslintrc.yaml`.\n\nSimilarly, `['js', 'yaml', NO_EXT]` =\u003e `.eslintrc.js`\n\n```ts\ninterface RCResult {\n  extension: string;\n  abspath: string;\n  value: object;\n}\n```\n\n- **extension** the extension string of the found rc file, excluding `.`\n- **value** the parsed value\n- **abspath** the absolute path of the rc file.\n\n```ts\nfunction ParserFunction (object: {\n  content: string,\n  filepath: string,\n  abspath: string,\n  extension: string\n}): object throws ParserError\n```\n\n- **content** the content of the rc file\n- **filepath** the filepath relative to the current search path\n\nParses the content of rc files, returns the parsed object, or throws error if there is a parse error.\n\n```ts\ninterface ParserError extends Error {\n  line?: number;\n  column?: number;\n}\n```\n\nIf the error (`ParserError`) thrown by `ParserFunction` contains both the `line` property and the `column` property, the `error.message` will be argumented by `CodeFrameFunction`\n\n```ts\ninterface Location {\n  line: number;\n  column: number;\n}\n\nfunction CodeFrameFunction (\n  rawLines: string,\n  loc: Location\n): string\n```\n\n```ts\nfunction NotFoundErrorFunction (\n  paths: Array\u003cstring\u003e,\n  extensions: Extensions\n): Error\n```\n\n### sync(options): RCResult\n\n- **options** the same as `options` of `parse(options)`\n\n## Built-in parsers\n\n```js\nparse.PARSERS.\u003ctype\u003e\n```\n\n### yaml, yml\n\nBased on [`js-yaml`](https://npmjs.org/package/js-yaml)\n\n### json\n\nBased on [`json5`](https://npmjs.org/package/json5)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Frc-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Frc-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Frc-parser/lists"}