Nearly Perpendicular Macaroons

    object-has-property

    1.1.2 • Public • Published

    Object-has-property

    npm version

    Determine if an Object has required property or properties

    Information

    NPM Package: Object-has-property
    Description: Determine if an Object passed in first argument has required property passed in second argument. There is possibility to pass an Array of properties in second argument to check for multiple properties.
    Returns False if first argument is not an Object
    Returns False if second argument is not an Array nor String
    Returns False if type of any properties is Undefined
    Returns True if property is found in Object.prototype

    Usage

    Install

    $ npm install --save object-has-property

    Examples

    var has = require('object-has-property');
     
    var a = {
      foo: 'bar'
    };
     
    console.log(has(a, 'foo'));

    Outputs true

    var has = require('object-has-property');
     
    var a = {
      foo: 'bar'
    };
     
    var required = [
      'foo',
      'missing'
    ];
     
    console.log(has(a, required));

    Outputs false because property missing is not found

    var has = require('object-has-property');
     
    var a = {
      foo: 'bar',
      notmissing: 'wohoo'
    };
     
    var required = [
      'foo',
      'notmissing'
    ];
     
    console.log(has(a, required));

    Outputs true

    var has = require('object-has-property');
     
    var a = {
      foo: 'bar',
      notmissing: undefined
    };
     
    var required = [
      'foo',
      'notmissing'
    ];
     
    console.log(has(a, required));

    Outputs false because notmissing is undefined

    var has = require('object-has-property');
     
    console.log(has(Object.prototype, 'hasOwnProperty'));

    Outputs true

    LICENSE MIT

    Install

    npm i object-has-property

    DownloadsWeekly Downloads

    2

    Version

    1.1.2

    License

    MIT

    Last publish

    Collaborators

    • vaverix