{"id":14155662,"url":"https://github.com/vara855/yaml-env-defaults","last_synced_at":"2025-04-11T22:11:30.552Z","repository":{"id":38386701,"uuid":"312990997","full_name":"vara855/yaml-env-defaults","owner":"vara855","description":"Read yaml file with environment variables substitution","archived":false,"fork":false,"pushed_at":"2023-07-14T17:22:03.000Z","size":668,"stargazers_count":10,"open_issues_count":6,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T18:11:11.972Z","etag":null,"topics":["configuration","environment-variables","nodejs","yaml"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/vara855.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}},"created_at":"2020-11-15T08:45:57.000Z","updated_at":"2024-11-14T02:07:53.000Z","dependencies_parsed_at":"2023-11-14T03:44:48.580Z","dependency_job_id":null,"html_url":"https://github.com/vara855/yaml-env-defaults","commit_stats":{"total_commits":56,"total_committers":4,"mean_commits":14.0,"dds":0.4464285714285714,"last_synced_commit":"6d47ad9d063c128bfac4f5ccfa2d841662ab44ad"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vara855%2Fyaml-env-defaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vara855%2Fyaml-env-defaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vara855%2Fyaml-env-defaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vara855%2Fyaml-env-defaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vara855","download_url":"https://codeload.github.com/vara855/yaml-env-defaults/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487694,"owners_count":21112190,"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","environment-variables","nodejs","yaml"],"created_at":"2024-08-17T08:04:47.897Z","updated_at":"2025-04-11T22:11:30.522Z","avatar_url":"https://github.com/vara855.png","language":"TypeScript","funding_links":[],"categories":["yaml"],"sub_categories":[],"readme":"\u003ch1\u003eWelcome to yaml-env-defaults 👋\u003c/h1\u003e\n\u003cp\u003e\n  \u003cimg alt=\"Version\" src=\"https://img.shields.io/badge/version-2.0.1-blue.svg?cacheSeconds=2592000\" /\u003e\n  \u003ca href=\"#\" target=\"_blank\"\u003e\n    \u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e Read yaml file with environment variables substitution\n\nThis is an wrapper under [js-yaml](https://www.npmjs.com/package/js-yaml) library which can render environment variables values with defaults support in yml file. (like Java Spring application.yaml). \n\n## Install module for Node.js\n\n```sh\nnpm install yaml-env-defaults\n\n# or\n\nyarn add yaml-env-defaults\n```\n\n## Usage\n\n### Import\n\n```js\n// ES\nimport { readYamlEnvSync, readYamlEnv } from 'yaml-env-defaults';\n\n// require\nconst { readYamlEnvSync, readYamlEnv } = require('yaml-env-defaults');\n```\n\n### Reading yaml\n\n```js\nimport { readYamlEnvSync, readYamlEnv } from 'yaml-env-defaults';\n\n// Read one yaml file synchronysly\nconst config = readYamlEnvSync('../path/to/yaml-file.yml');\n\n// Read many yaml files synchronysly\nconst joinedYamls = readYamlEnvSync(['first.yml', 'second.yml', 'third.yaml']);\n\n// Read yaml files with custom properties provider fn\nconst propertiesMap = {\n  ENV_VAR_NAME: 'My value',\n  USERS_COUNT: 4\n};\n\nconst getProperty = (key) =\u003e {\n  // without default value will be throwed error in case of missing \n  return propertiesMap[key] || 'Default value';\n}\n\nconst config = readYamlEnvSync('../path/to/yaml-file.yml', getProperty);\n\n// Custom properties for js-yaml\nconst config = readYamlEnvSync('../path/to/yaml-file.yml', undefined, {\n  jsYaml: {\n    onWarning: (yaml, e) =\u003e {\n    }\n    //...\n  }\n})\n\n  // the same for readYamlEnv as async \n  (async () =\u003e {\n    // Read one yaml file asynchronysly\n    const config = await readYamlEnv('../path/to/yaml-file.yml');\n  });\n//or\nreadYamlEnv('../path/to/yaml-file.yml').then(config =\u003e config);\n\n```\n\n## Example\n\nconfig-env.yml\n```yaml\nfoo: 1\nbar: 'text-${ENV_VAR_MY}-text-${ENV_VAR_YOUR}-text'\n\nsomeFoo:\n  someBar: ['${ENV_VAR_MY}', '${ENV_VAR_YOUR}']\n  yaml-array:\n    - ${ENV_VAR_MY}\n    - second\n\nsomeStrange: Thats/${ENV_VAR_MY}/${NAMESPACE:cloud-or-not}/${ENV_VAR_YOUR}\n\nescapedValue:\n  value: \\$\\{ENV_VAR_MY\\}\n```\n\nJS output\n```js\nprocess.env.ENV_VAR_MY = 'Some value 2';\nprocess.env.ENV_VAR_YOUR = 'Another Value';\n\nconst config = readYamlEnvSync(path.resolve(__dirname, 'config-env.yml'));\n// Object {\n//   \"bar\": \"text-Some value 2-text-Another Value-text\",\n//   \"escapedValue\": Object {\n//     \"value\": \"\\\\\\\\$\\\\\\\\{ENV_VAR_MY\\\\\\\\}\",\n//   },\n//   \"foo\": 1,\n//   \"someFoo\": Object {\n//     \"someBar\": Array [\n//       \"Some value 2\",\n//       \"Another Value\",\n//     ],\n//     \"yaml-array\": Array [\n//       \"Some value 2\",\n//       \"second\",\n//     ],\n//   },\n//   \"someStrange\": \"Thats/Some value 2/cloud-or-not/Another Value\",\n// }\n```\n\nMore examples you can find in `./src/__fixtures__/` and `./src/__snapshots/` from tests snapshot results.\n\n## Tests coverage report\n```\n---------------------|---------|----------|---------|---------|-------------------\nFile                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n---------------------|---------|----------|---------|---------|-------------------\nAll files            |   98.46 |    83.02 |     100 |   98.11 |                   \n read-yaml-config.ts |   98.46 |    83.02 |     100 |   98.11 | 40                \n---------------------|---------|----------|---------|---------|-------------------\n```\n\n## Used Dependencies: \n\n- js-yaml@4.1.0\n- lodash@4.17.21\n\n## Author\n\n👤 **Valerii Nosikov**\n\n* Github: [@vara855](https://github.com/vara855)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n***\n_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvara855%2Fyaml-env-defaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvara855%2Fyaml-env-defaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvara855%2Fyaml-env-defaults/lists"}