{"id":17038322,"url":"https://github.com/mcasimir/valid-config","last_synced_at":"2026-05-05T02:33:20.249Z","repository":{"id":146239083,"uuid":"98632929","full_name":"mcasimir/valid-config","owner":"mcasimir","description":"Define and validate configuration with an extended json schema","archived":false,"fork":false,"pushed_at":"2018-05-23T12:33:18.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-28T03:17:37.066Z","etag":null,"topics":["configuration","json-schema"],"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/mcasimir.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2017-07-28T09:22:42.000Z","updated_at":"2023-12-28T17:51:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"2823a9f3-3b80-480a-9f6c-8ef7cd2f4ce0","html_url":"https://github.com/mcasimir/valid-config","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/mcasimir%2Fvalid-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcasimir%2Fvalid-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcasimir%2Fvalid-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcasimir%2Fvalid-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcasimir","download_url":"https://codeload.github.com/mcasimir/valid-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245034348,"owners_count":20550445,"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":["configuration","json-schema"],"created_at":"2024-10-14T08:56:30.395Z","updated_at":"2026-05-05T02:33:15.217Z","avatar_url":"https://github.com/mcasimir.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# valid-config\n\nDefine and validate configuration with an extended json schema.\n\n## Install\n\n```\nnpm install --save valid-config\n```\n\n## Usage\n\n### Inject env\n\n``` js\nconst validConfig = require('valid-config');\nprocess.env.FOO = 'bar';\n\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'string',\n      env: 'FOO'\n    }\n  }\n});\n\ndeepEqual(config, {\n  foo: 'bar'\n});\n```\n\n### Load and merge\n\n``` js\nconst validConfig = require('valid-config');\nprocess.env.FOO = 'bar';\n\nconst configFile1 = {\n  baz: 'xyz'\n};\n\nconst configFile2 = {\n  baz: 'jkw'\n};\n\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'string',\n      env: 'FOO'\n    }\n  }\n}, configFile1, configFile2);\n\ndeepEqual(config, {\n  foo: 'bar',\n  baz: 'jkw'\n});\n```\n\n### Defaults\n\n``` js\nconst validConfig = require('valid-config');\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    port: {\n      type: 'number',\n      env: 'PORT',\n      default: 3000\n    }\n  }\n});\n\ndeepEqual(config, {\n  port: 3000\n});\n```\n\n### Env always takes precedence over the rest\n\n``` js\nprocess.env.PORT = '3001';\n\nconst configFile1 = {\n  port: 8000\n};\n\nconst validConfig = require('valid-config');\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    port: {\n      type: 'number',\n      env: 'PORT',\n      default: 3000\n    }\n  }\n});\n\ndeepEqual(config, {\n  port: 3001\n});\n```\n\n### Normalize types\n\n``` js\nconst validConfig = require('valid-config');\nprocess.env.PORT = '3000';\n\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    port: {\n      type: 'number',\n      env: 'PORT'\n    }\n  }\n});\n\ndeepEqual(config, {\n  port: 3000\n});\n```\n\n### Load arrays from env\n\n``` js\nprocess.env.FOO = 'bar,baz';\n\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'array',\n      items: {\n        type: 'string'\n      },\n      env: 'FOO'\n    }\n  }\n});\n\ndeepEqual(config, {\n  foo: ['bar', 'baz']\n});\n```\n\n### Load arrays from env (specify the separator)\n\n``` js\nprocess.env.FOO = 'bar::baz';\n\nconst config = validConfig({\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'array',\n      items: {\n        type: 'string'\n      },\n      env: 'FOO'\n      envSeparator: '::'\n    }\n  }\n});\n\ndeepEqual(config, {\n  foo: ['bar', 'baz']\n});\n```\n\n### Validating required properties\n\n``` js\nthrows(function() {\n  validConfig({\n    type: 'object',\n    properties: {\n      foo: {\n        type: 'string',\n        env: 'FOO'\n      }\n    },\n    required: [\n      'foo'\n    ]\n  });\n});\n```\n\n### Validating arrays\n\n``` js\nthrows(function() {\n  const configFile = {};\n\n  validConfig({\n    type: 'object',\n    properties: {\n      foo: {\n        type: 'array',\n        items: {\n          type: 'string'\n        },\n        minItems: 1\n      }\n    }\n  }, configFile);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcasimir%2Fvalid-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcasimir%2Fvalid-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcasimir%2Fvalid-config/lists"}