{"id":15980961,"url":"https://github.com/vitalets/flat-options","last_synced_at":"2025-10-13T06:38:35.912Z","repository":{"id":57253460,"uuid":"106402908","full_name":"vitalets/flat-options","owner":"vitalets","description":"One-level options with default values and validation","archived":false,"fork":false,"pushed_at":"2017-10-11T08:12:31.000Z","size":114,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T05:29:03.290Z","etag":null,"topics":["assign","defaults","extend","javascript","merge","nodejs","options"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vitalets.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-10T10:31:34.000Z","updated_at":"2019-08-30T01:08:16.000Z","dependencies_parsed_at":"2022-08-31T22:11:58.567Z","dependency_job_id":null,"html_url":"https://github.com/vitalets/flat-options","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fflat-options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fflat-options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fflat-options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fflat-options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalets","download_url":"https://codeload.github.com/vitalets/flat-options/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243886918,"owners_count":20363800,"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":["assign","defaults","extend","javascript","merge","nodejs","options"],"created_at":"2024-10-08T00:23:41.486Z","updated_at":"2025-10-13T06:38:30.865Z","avatar_url":"https://github.com/vitalets.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# flat-options\n\n[![Build Status](https://travis-ci.org/vitalets/flat-options.svg?branch=master)](https://travis-ci.org/vitalets/flat-options)\n[![npm](https://img.shields.io/npm/v/flat-options.svg)](https://www.npmjs.com/package/flat-options)\n[![license](https://img.shields.io/npm/l/flat-options.svg)](https://www.npmjs.com/package/flat-options)\n\n\u003e One-level options with default values and validation\n\nUtility function to merge simple one-level options with default values and perform validation.\n\n## Comparison to `Object.assign`\nBenefits over `Object.assign` are:\n\n* exclude of `undefined` values (useful for conditional options):\n  ```js\n  const defaults = {foo: 'bar'};\n  const options = {foo: undefined};\n\n  Object.assign({}, defaults, options); // -\u003e {foo: undefined}\n  // vs\n  flatOptions(options, defaults); // -\u003e {foo: 'bar'}\n  ```\n  \n* validation of options keys:\n  ```js\n  const defaults = {foo: 'bar'};\n  const options = {unknown: 'baz'};\n\n  Object.assign({}, defaults, options); // -\u003e {foo: 'bar', unknown: 'baz'}\n  // vs\n  flatOptions(options, defaults); // -\u003e throws error \"Unknown option\"!\n  ```\n  \n## Comparison to other packages\nBenefits over existing [defaults](https://www.npmjs.com/package/defaults),\n[lodash.defaults](https://www.npmjs.com/package/lodash.defaults) and \n[object.defaults](https://www.npmjs.com/package/object.defaults) are:\n\n* auto-validation of options keys\n* zero dependencies\n\n\u003e Note that this package is only for **one-level** options, for nested ones please use alternative packages\n\n## Installation\n```bash\nnpm install --save flat-options\n```\n\n## Usage\n```js\nimport flatOptions from 'flat-options';\n\nconst defaults = {\n  a: 1,\n  b: false\n};\n\nclass Foo {\n  constructor(options) {\n    this._options = flatOptions(options, defaults);\n  }\n}\n\nconst foo = new Foo({a: 2}); // foo._options will be {a: 2, b: false} \n```\n\n## License\nMIT @ [Vitaliy Potapov](https://github.com/vitalets)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fflat-options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalets%2Fflat-options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fflat-options/lists"}