{"id":13671319,"url":"https://github.com/egoist/joycon","last_synced_at":"2025-04-12T23:39:39.495Z","repository":{"id":43001663,"uuid":"129592191","full_name":"egoist/joycon","owner":"egoist","description":"Find and load config files with joy.","archived":false,"fork":false,"pushed_at":"2023-01-07T04:14:19.000Z","size":1173,"stargazers_count":147,"open_issues_count":12,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T23:39:35.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/egoist.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-04-15T08:43:00.000Z","updated_at":"2025-03-02T16:07:44.000Z","dependencies_parsed_at":"2023-02-06T11:30:56.325Z","dependency_job_id":null,"html_url":"https://github.com/egoist/joycon","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fjoycon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fjoycon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fjoycon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fjoycon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/joycon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647255,"owners_count":21139081,"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-08-02T09:01:06.049Z","updated_at":"2025-04-12T23:39:39.471Z","avatar_url":"https://github.com/egoist.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"\n# joycon\n\n[![NPM version](https://img.shields.io/npm/v/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![NPM downloads](https://img.shields.io/npm/dm/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![install size](https://packagephobia.now.sh/badge?p=joycon@2.0.0)](https://packagephobia.now.sh/result?p=joycon@2.0.0) [![CircleCI](https://circleci.com/gh/egoist/joycon/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/joycon/tree/master)  [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe)\n\n## Differences with [cosmiconfig](https://github.com/davidtheclark/cosmiconfig)?\n\nJoyCon is zero-dependency but feature-complete.\n\n## Install\n\n```bash\nyarn add joycon\n```\n\n## Usage\n\n```js\nconst JoyCon = require('joycon')\n\nconst joycon = new JoyCon()\n\njoycon.load(['package-lock.json', 'yarn.lock'])\n.then(result =\u003e {\n  // result is {} when files do not exist\n  // otherwise { path, data }\n})\n```\n\nBy default non-js files are parsed as JSON, if you want something different you can add a loader:\n\n```js\nconst joycon = new JoyCon()\n\njoycon.addLoader({\n  test: /\\.toml$/,\n  load(filepath) {\n    return require('toml').parse(filepath)\n  }\n})\n\njoycon.load(['cargo.toml'])\n```\n\n## API\n\n### constructor([options])\n\n#### options\n\n##### files\n\n- Type: `string[]`\n\nThe files to search.\n\n##### cwd\n\nThe directory to search files.\n\n##### stopDir\n\nThe directory to stop searching.\n\n##### packageKey\n\nYou can load config from certain property in a `package.json` file. For example, when you set `packageKey: 'babel'`, it will load the `babel` property in `package.json` instead of the entire data.\n\n##### parseJSON\n\n- Type: `(str: string) =\u003e any`\n- Default: `JSON.parse`\n\nThe function used to parse JSON string.\n\n### resolve([files], [cwd], [stopDir])\n### resolve([options])\n\n`files` defaults to `options.files`.\n\n`cwd` defaults to `options.cwd`.\n\n`stopDir` defaults to `options.stopDir` then `path.parse(cwd).root`.\n\nIf using a single object `options`, it will be the same as constructor options.\n\nSearch files and resolve the path of the file we found.\n\nThere's also `.resolveSync` method.\n\n### load(...args)\n\nThe signature is the same as [resolve](#resolvefiles-cwd-stopdir).\n\nSearch files and resolve `{ path, data }` of the file we found.\n\nThere's also `.loadSync` method.\n\n### addLoader(Loader)\n\n```typescript\ninterface Loader {\n  name?: string\n  test: RegExp\n  load(filepath: string)?: Promise\u003cany\u003e\n  loadSync(filepath: string)?: any\n}\n```\n\nAt least one of `load` and `loadSync` is required, depending on whether you're calling the synchonous methods or not.\n\n### removeLoader(name)\n\nRemove loaders by loader name.\n\n### clearCache()\n\nEach JoyCon instance uses its own cache.\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Author\n\n**joycon** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nAuthored and maintained by egoist with help from contributors ([list](https://github.com/egoist/joycon/contributors)).\n\n\u003e [github.com/egoist](https://github.com/egoist) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fjoycon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Fjoycon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fjoycon/lists"}