All Projects → coreybutler → Musthave

coreybutler / Musthave

A Node.js helper module for checking object elements against a list of required elements.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Musthave

Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+37000%)
Mutual labels:  environment-variables, validation
Form Backend Validation
An easy way to validate forms using back end logic
Stars: ✭ 784 (+15580%)
Mutual labels:  validation
Malli
Data-Driven Schemas for Clojure/Script.
Stars: ✭ 667 (+13240%)
Mutual labels:  validation
Go Proto Validators
Generate message validators from .proto annotations.
Stars: ✭ 713 (+14160%)
Mutual labels:  validation
Vuelidate
Simple, lightweight model-based validation for Vue.js
Stars: ✭ 6,186 (+123620%)
Mutual labels:  validation
Spected
Validation library
Stars: ✭ 717 (+14240%)
Mutual labels:  validation
Vue Composable
Vue composition-api composable components. i18n, validation, pagination, fetch, etc. +50 different composables
Stars: ✭ 638 (+12660%)
Mutual labels:  validation
Flow Runtime
A runtime type system for JavaScript with full Flow compatibility.
Stars: ✭ 813 (+16160%)
Mutual labels:  validation
Commonregex
🍫 A collection of common regular expressions for Go
Stars: ✭ 733 (+14560%)
Mutual labels:  validation
Swagger Parser
Swagger 2.0 and OpenAPI 3.0 parser/validator
Stars: ✭ 710 (+14100%)
Mutual labels:  validation
Formsy React
A form input builder and validator for React JS
Stars: ✭ 708 (+14060%)
Mutual labels:  validation
Envalid
Environment variable validation for Node.js
Stars: ✭ 684 (+13580%)
Mutual labels:  validation
Skinny Framework
🚝 "Scala on Rails" - A full-stack web app framework for rapid development in Scala
Stars: ✭ 719 (+14280%)
Mutual labels:  validation
Pydantic
Data parsing and validation using Python type hints
Stars: ✭ 8,362 (+167140%)
Mutual labels:  validation
Winterfell
Generate complex, validated and extendable JSON-based forms in React.
Stars: ✭ 787 (+15640%)
Mutual labels:  validation
Class Validator
Decorator-based property validation for classes.
Stars: ✭ 6,941 (+138720%)
Mutual labels:  validation
Encoding
Go package containing implementations of efficient encoding, decoding, and validation APIs.
Stars: ✭ 705 (+14000%)
Mutual labels:  validation
Angular Validation
[INACTIVE] Client Side Validation for AngularJS 1. (You should use version > 2 💥)
Stars: ✭ 714 (+14180%)
Mutual labels:  validation
Simple Java Mail
Simple API, Complex Emails (JavaMail smtp wrapper)
Stars: ✭ 821 (+16320%)
Mutual labels:  validation
React Final Form
🏁 High performance subscription-based form state management for React
Stars: ✭ 6,781 (+135520%)
Mutual labels:  validation

Build Status Greenkeeper badge

musthave

This module provides a simple and standard way of checking for object attributes. The inspiration for this project was checking for the existence of environment variables.

Installation: npm install musthave

This module contains minimal dependencies and helps keep npm fit.

Use: HasAll

If 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.

var MustHave = require('musthave');
var mh = new MustHave();

mh.hasAll(process.env, 'IMPORTANT_VAR_1', 'IMPORTANT_VAR_2'); // returns boolean

If the hasAll method fails, the missing attributes are available in mh.missing (returned as an array of strings).

Use: HasAny

If you need to make sure an object has at least one attribute of a specific name, use the hasAny() method.

var MustHave = require('musthave');
var mh = new MustHave();

mh.hasAny(process.env, 'IMPORTANT_VAR_1', 'IMPORTANT_VAR_2'); // returns boolean

The code above will throw an error only if process.env does NOT have IMPORTANT_VAR_1 or IMPORTANT_VAR_2.

Use: HasExactly

If you need to make sure an object has only a specific set of named attributes, use the hasExactly() method.

var MustHave = require('musthave');
var mh = new MustHave();

mh.hasExactly(process.env, 'IMPORTANT_VAR_1', 'IMPORTANT_VAR_2'); // returns boolean

The 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.

Handling Errors & Suppressing Warnings

If 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:

var MustHave = require('musthave');
var mh = new MustHave({
  throwOnError: true,      // Set this to false if you want to handle errors on our own
  suppressWarnings: false  // Set this to true if you don't want console output for warnings.
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].