Skip to content

Small module that checks if the given object has given properties and are not null or undefined

License

Notifications You must be signed in to change notification settings

Corgi-IT/accepted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Accepted

Small module that checks if the given object has given properties and are not null or undefined

Requirements

To use this module, one the following is required:

  • Node.js v6.0.0 or higher
  • An env that accepts ES6' const and let

Installation

You can install this module with NPM:

npm install --save accepted

Usage

Require the library

    const accepted = require('accepted');

Define an Object (or get one)

    const obj = {
        foo: 'bar',
        baz: 'qux',
        nope: null,
        sub_obj: {exists: 'Yes!'},
        sub_arr: ['element']
    }

Start checking!

Success!

    if(!accepted(obj, ['foo', 'baz'])) {
        return 'Not all required props are given';
    }

    // Go on with life

Oops!

    if(!accepted(obj, ['nope', 'non-existend'])) {
        return 'Not all required props are given';
    }

    // Life stopped, accepted returned false
``

About

Small module that checks if the given object has given properties and are not null or undefined

Resources

License

Stars

Watchers

Forks

Packages

No packages published