{"id":16441877,"url":"https://github.com/nil/options-config","last_synced_at":"2026-05-15T06:37:12.564Z","repository":{"id":57315886,"uuid":"155862965","full_name":"nil/options-config","owner":"nil","description":"Validate and replace your default configuration options with ease","archived":false,"fork":false,"pushed_at":"2018-11-25T13:44:22.000Z","size":86,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T04:05:14.133Z","etag":null,"topics":["browser","class","config","configuration","javascript","js","node","object","option","options","validate","validation"],"latest_commit_sha":null,"homepage":null,"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/nil.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-11-02T12:27:35.000Z","updated_at":"2020-05-12T15:27:41.000Z","dependencies_parsed_at":"2022-09-18T20:52:49.537Z","dependency_job_id":null,"html_url":"https://github.com/nil/options-config","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil%2Foptions-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil%2Foptions-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil%2Foptions-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil%2Foptions-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nil","download_url":"https://codeload.github.com/nil/options-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240788617,"owners_count":19857691,"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":["browser","class","config","configuration","javascript","js","node","object","option","options","validate","validation"],"created_at":"2024-10-11T09:15:40.226Z","updated_at":"2026-05-15T06:37:12.518Z","avatar_url":"https://github.com/nil.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# options-config\n\nValidate and replace your default configuration options with ease.\n\nThe validation scripts for configuration objects are harder to write than it seems. Luckily for you, options-config was released. This tiny library allows you to add a configuration object, of up to 2 levels, into your JavaScript library. This way, without you worrying about the validation mechanisms, your user will be able to replace any configuration option with any valid value.\n\n\n[![Build status](https://travis-ci.com/nil/options-config.svg?branch=master)](https://travis-ci.com/nil/options-config)\n[![Dependencies status](https://img.shields.io/david/dev/nil/options-config.svg)](https://david-dm.org/nil/options-config)\n[![Version](https://img.shields.io/npm/v/options-config.svg)](https://www.npmjs.com/package/options-config)\n[![License](https://img.shields.io/npm/l/options-config.svg)](https://github.com/nil/options-config/blob/master/LICENSE)\n\n\n## Installation\n\nOpen Terminal and install the package with this command:\n\n```sh\nnpm install options-config --save\n```\n\nThen import options-config into nay file you are planning to use it:\n\n```js\nimport OptionsConfig from 'options-config';\n```\n\nFinally, do the one time setup:\n\n```js\nconst options = new OptionsConfig([defaultsObject]);\n```\n\n## Defaults’ object\n\nThe defaults’ object is an object containing the default values and restrictions for every configuration option.\n\n| Key       | Type                  | Description                                                 |\n|:---------:|:---------------------:|-------------------------------------------------------------|\n| `default` | string, object        | The result when there isn’t any valid value given.          |\n| `type`    | string, array         | Only the values of this type will be valid.                 |\n| `valid`   | string, array, object | The only values that will be valid.                         |\n| `regex`   | regexp                | A RegExp expression that has to match with the given value. |\n| `range`   | object                | The `min`, `max` and `step` parameters for numbers.         |\n\nPractical examples:\n\n```js\nconst defaultsObject = {\n  x: {\n    default: 10,\n    type: ['number', 'boolean']\n  },\n  y: {\n    default: 'foo',\n    type: 'string',\n    valid: ['foo', 'bar', 'hello', 'world']\n  }\n};\n```\n\n```js\nconst defaultsObject = {\n  x: true,\n  y: {\n    default: {\n      y1: 'foo',\n      y2: 'bar'\n    },\n    type: 'string',\n    regex: /[A-z]{3}/\n  }\n};\n```\n\n```js\nconst defaultsObject = {\n  x: {\n    x1: {\n      default: 15,\n      type: 'number',\n      range: {\n        min: 0,\n        max: 100,\n        step: 5\n      }\n    },\n    x2: {\n      default: false,\n      type: 'boolean'\n    }\n  },\n  y: {\n    default: 200,\n    valid: {\n      number: 'all',\n      string: ['e', 'π', 'pi']\n    }\n  }\n};\n```\n\n## Validate\n\n`options.validate(object, [defaultsObject])`\n\nReturns an object with all the configuration options, whether they are the default value or the one given by the user.\n\n| Parameter        | Required | Description                                                                                            |\n|:----------------:|:--------:|--------------------------------------------------------------------------------------------------------|\n| `object`         | true     | The configuration object given by the user. It can contain none, some or all of the available options. |\n| `defaultsObject` | false    | The default values and restrictions. It’s not required if it has already been declared in the setup.   |\n\nPractical examples:\n\n```js\nconst userOptions = options.validate({\n  x: false,\n  y: 'hello'\n});\n```\n\n```js\nconst userOptions = options.validate({\n  x: 15\n}, {\n  x: {\n    default: 60,\n    type: 'number'\n  }\n});\n```\n\n## About\n\n### Contributing\n\nIf you have any trouble while installing or using options-config, or you want to suggest a change, I encourage you to [open an issue](https://github.com/nil/options-config/issues/new) or [make a pull request](https://github.com/nil/options-config/pulls). A short explanation is enough, and it will improve this project for you and other developers.\n\n### Tests\n\nTo run the tests, first install the dev dependencies and then run the test command:\n\n```sh\nnpm install -d \u0026\u0026 npm test\n```\n\n### License\n\n© 2018, [Nil Vila](https://twitter.com/nilvilam). Released under the [MIT License](https://github.com/nil/options-config/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnil%2Foptions-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnil%2Foptions-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnil%2Foptions-config/lists"}