{"id":16431831,"url":"https://github.com/coreybutler/musthave","last_synced_at":"2025-03-23T08:31:40.804Z","repository":{"id":28065815,"uuid":"31562746","full_name":"coreybutler/musthave","owner":"coreybutler","description":"A Node.js helper module for checking object elements against a list of required elements.","archived":false,"fork":false,"pushed_at":"2019-12-27T02:30:29.000Z","size":13,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T18:57:51.475Z","etag":null,"topics":["environment-variables","javascript","musthave","nodejs","require","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coreybutler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["coreybutler"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2015-03-02T20:56:52.000Z","updated_at":"2024-03-14T14:06:20.000Z","dependencies_parsed_at":"2022-08-29T10:50:57.507Z","dependency_job_id":null,"html_url":"https://github.com/coreybutler/musthave","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreybutler%2Fmusthave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreybutler%2Fmusthave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreybutler%2Fmusthave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreybutler%2Fmusthave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coreybutler","download_url":"https://codeload.github.com/coreybutler/musthave/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078067,"owners_count":20557274,"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":["environment-variables","javascript","musthave","nodejs","require","validation"],"created_at":"2024-10-11T08:32:54.182Z","updated_at":"2025-03-23T08:31:40.184Z","avatar_url":"https://github.com/coreybutler.png","language":"JavaScript","funding_links":["https://github.com/sponsors/coreybutler"],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/coreybutler/musthave.svg)](https://travis-ci.org/coreybutler/musthave)\n\n# musthave\n\nThis module provides a simple and standard way of checking for object attributes.\nThe inspiration for this project was checking for the existence of environment variables.\n\n**Installation:** `npm install musthave`\n\nThis module contains minimal dependencies and [helps keep npm fit](https://medium.com/@goldglovecb/npm-needs-a-personal-trainer-537e0f8859c6).\n\n### Use: HasAll\n\nIf your application requires the presence of a couple of envrionment variables, it's a good idea to make sure they exist as a simple sanity check when your application launches. The following code will log a warning to the console and throw an error if `IMPORTANT_VAR_1` _and_ `IMPORTANT_VAR_2` aren't in the environment variables.\n\n```js\nvar MustHave = require('musthave');\nvar mh = new MustHave();\n\nmh.hasAll(process.env, 'IMPORTANT_VAR_1', 'IMPORTANT_VAR_2'); // returns boolean\n```\n\nIf the `hasAll` method fails, the missing attributes are available in `mh.missing` (returned as an array of strings).\n\n### Use: HasAny\n\nIf you need to make sure an object has _at least_ one attribute of a specific name, use the `hasAny()` method.\n\n```js\nvar MustHave = require('musthave');\nvar mh = new MustHave();\n\nmh.hasAny(process.env, 'IMPORTANT_VAR_1', 'IMPORTANT_VAR_2'); // returns boolean\n```\n\nThe code above will throw an error only if `process.env` does NOT have `IMPORTANT_VAR_1` _or_ `IMPORTANT_VAR_2`.\n\n### Use: HasExactly\n\nIf you need to make sure an object has only a specific set of named attributes, use the `hasExactly()` method.\n\n```js\nvar MustHave = require('musthave');\nvar mh = new MustHave();\n\nmh.hasExactly(process.env, 'IMPORTANT_VAR_1', 'IMPORTANT_VAR_2'); // returns boolean\n```\n\nThe code above will **not** throw an error _only if `process.env` has_ `IMPORTANT_VAR_1` _and_ `IMPORTANT_VAR_2`. If `process.env` has both of these _and_ another attribute like `NODE_ENV`, this method will throw an error because the object is not exactly as defined. You probably don't want to use this on `process.env` because it can change from system to system, but it can be useful on other kinds of objects like data models.\n\n### Handling Errors \u0026 Suppressing Warnings\n\nIf you want to suppress warning messages, the `MustHave` module can be configured to do so. It can also be configured to not throw errors so your app can handle them as it sees fit. To accomodate these use cases, there are two configuration options that can be passed to the `MustHave()` object. Not providing a configuration is the same as:\n\n```js\nvar MustHave = require('musthave');\nvar mh = new MustHave({\n  throwOnError: true,      // Set this to false if you want to handle errors on our own\n  suppressWarnings: false  // Set this to true if you don't want console output for warnings.\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreybutler%2Fmusthave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoreybutler%2Fmusthave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreybutler%2Fmusthave/lists"}