{"id":19151679,"url":"https://github.com/cypress-io/env-or-json-file","last_synced_at":"2025-04-19T16:31:57.269Z","repository":{"id":57105220,"uuid":"97030098","full_name":"cypress-io/env-or-json-file","owner":"cypress-io","description":"Loads JSON object from environment string or local file","archived":false,"fork":false,"pushed_at":"2017-10-30T17:32:05.000Z","size":84,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-09T21:29:52.087Z","etag":null,"topics":["ci","environment","environment-variables","json","util"],"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/cypress-io.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-07-12T16:33:54.000Z","updated_at":"2022-11-13T05:50:29.000Z","dependencies_parsed_at":"2022-08-21T03:00:40.450Z","dependency_job_id":null,"html_url":"https://github.com/cypress-io/env-or-json-file","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/cypress-io%2Fenv-or-json-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fenv-or-json-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fenv-or-json-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fenv-or-json-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cypress-io","download_url":"https://codeload.github.com/cypress-io/env-or-json-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223800821,"owners_count":17205010,"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":["ci","environment","environment-variables","json","util"],"created_at":"2024-11-09T08:15:27.279Z","updated_at":"2024-11-09T08:15:27.884Z","avatar_url":"https://github.com/cypress-io.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @cypress/env-or-json-file\n\n\u003e Loads JSON object from environment string or local file\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![Build status](https://ci.appveyor.com/api/projects/status/lwqty4s0g0l1x9x0?svg=true)](https://ci.appveyor.com/project/cypress-io/env-or-json-file)\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 6 or above.\n\n```sh\nnpm install --save @cypress/env-or-json-file\n```\n\n## Use\n\nIf you have configuration file locally `foo.json` with all your settings,\nload it directly\n\n```js\nconst {configFromEnvOrJsonFile} = require('@cypress/env-or-json-file')\nconst config = configFromEnvOrJsonFile('foo.json')\nif (config) {\n  // ok, loaded somehow\n} else {\n  console.error('Missing config...')\n}\n```\n\nBut when you move to CI, just grab the file's contents and put it as\nenvironment variable `foo_json` (environment variables often have restrictions\non characters, so replace all `/.-` characters in the path with `_`)\n\n```sh\ncat foo.json | pbcopy\n```\n\nPaste the contents into CI variable `foo_json` and it should load the config\non CI without checking in a sensitive file.\n\n## Debug\n\nTo see verbose log message from this module, run with\n`DEBUG=env-or-json-file ...` environment variable.\n\n## Filename\n\nGiven a filename with path, function `filenameToShellVariable` converts it to\nenvironment key name, normalizing slashes and dots.\n\n```js\nconst {filenameToShellVariable} = require('@cypress/env-or-json-file')\nfilenameToShellVariable('foo/bar/.me.json')\n// foo_bar__me_json\n```\n\n## Tips\n\n* To prevent committing sensitive files use\n  [ban-sensitive-files](https://github.com/bahmutov/ban-sensitive-files)\n* Make sure CI does NOT leak environment variables to forks, like\n  [CircleCI does](https://circleci.com/docs/1.0/fork-pr-builds/)\n\n![Stop CircleCI default variable leak](images/circleci-env-vars.png)\n\n### Small print\n\nLicense: MIT - do anything with the code, but don't blame us if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/cypress-io/env-or-json-file/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 Cypress.io\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[npm-icon]: https://nodei.co/npm/@cypress/env-or-json-file.svg?downloads=true\n[npm-url]: https://npmjs.org/package/@cypress/env-or-json-file\n[ci-image]: https://travis-ci.org/cypress-io/env-or-json-file.svg?branch=master\n[ci-url]: https://travis-ci.org/cypress-io/env-or-json-file\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcypress-io%2Fenv-or-json-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcypress-io%2Fenv-or-json-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcypress-io%2Fenv-or-json-file/lists"}