{"id":20853036,"url":"https://github.com/gakimball/load-whatever","last_synced_at":"2026-04-13T03:36:24.079Z","repository":{"id":143809544,"uuid":"77720826","full_name":"gakimball/load-whatever","owner":"gakimball","description":"Load and parse a file that might be JS, JSON, YAML, or CSON","archived":false,"fork":false,"pushed_at":"2017-06-05T23:46:14.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-19T06:27:48.438Z","etag":null,"topics":["javascript","json","nodejs","yaml"],"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/gakimball.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-31T02:14:04.000Z","updated_at":"2023-04-17T00:41:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"f24711ce-5938-4eec-a672-2ce16e176dcc","html_url":"https://github.com/gakimball/load-whatever","commit_stats":null,"previous_names":["spacedoc/load-whatever"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakimball%2Fload-whatever","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakimball%2Fload-whatever/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakimball%2Fload-whatever/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gakimball%2Fload-whatever/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gakimball","download_url":"https://codeload.github.com/gakimball/load-whatever/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243222185,"owners_count":20256229,"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":["javascript","json","nodejs","yaml"],"created_at":"2024-11-18T03:19:38.853Z","updated_at":"2026-04-13T03:36:18.747Z","avatar_url":"https://github.com/gakimball.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# load-whatever\n\n\u003e Load and parse a file that might be a module, JSON, YAML, or CSON\n\n[![Travis](https://img.shields.io/travis/spacedoc/load-whatever.svg?maxAge=2592000)](https://travis-ci.org/spacedoc/load-whatever) [![npm](https://img.shields.io/npm/v/load-whatever.svg?maxAge=2592000)](https://www.npmjs.com/package/load-whatever)\n\nSometimes you want to load and parse a file but don't care how the file is written. Who likes writing `switch` statements, anyway?\n\nLoads JavaScript modules, JSON, YAML, and CSON.\n\n## Installation\n\n```bash\nnpm install load-whatever\n```\n\n## Usage\n\n```js\nconst load = require('load-whatever');\n\nload('config.js').then(res =\u003e {\n  // res =\u003e {}\n});\n\nconst config = load.sync('config.json'); // =\u003e {}\n```\n\n## API\n\n### load(file[, options])\n\nLoad and parse the value of a file. It can be:\n\n- A JavaScript file with `module.exports`.\n  - If the value is a function, the function is executed, and the return value is used.\n  - If the value is a Promise-returning function, the value inside the Promise is used.\n- A JSON file.\n- A YAML file.\n- A CSON file.\n\nThe contents of the file will be parsed based on its extension. If the file has no extension, it will be parsed as JSON first, and if that doesn't work, as YAML next.\n\n- **file** (String): Path of file to load.\n- **options** (Object or String): *Optional.* Options for `fs.readFile`.\n\nReturns a promise containing the value. Rejects on any of these conditions:\n\n- There's an error reading the file.\n- There's an error parsing the file based on its extension.\n- A file with no extension can't be parsed as JSON or YAML.\n- A JavaScript function encounters an error when it's run.\n\n### load.sync(file[, options])\n\nSynchronous version of `load()`. Returns the parsed value of the file. Supports all the same features as the asynchronous method **except for loading asynchronous functions**. Throws an error for any of the reasons outlined by the asynchronous `load()`, plus one more:\n\n- A JavaScript function returns a Promise.\n\n### load.supports\n\nArray of strings containing the file extensions this library supports. Useful if you utilize glob matching to load files with this library.\n\n## Local Development\n\n```bash\ngit clone https://github.com/spacedoc/load-whatever\ncd load-whatever\nnpm install\nnpm test\n```\n\n## License\n\nMIT \u0026copy; [Geoff Kimball](http://geoffkimball.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgakimball%2Fload-whatever","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgakimball%2Fload-whatever","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgakimball%2Fload-whatever/lists"}