obj-has
Determine if an Object has required properties
Last updated 5 years ago by stevelacy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install obj-has 
SYNC missed versions from official npm registry.

obj-has

Build Status NPM version

Determine if an Object has required properties

Information

Package obj-has
Description Determine if an Object has required properties defined in an Array or Object
Node Version >= 0.9

Usage

Install

$ npm install --save-dev obj-has

Examples

var has = require('obj-has');

// Array of required keys
var required = [
  'test',
  'second',
  'missing'
];

var object = {
  test: 'item',
  second: false
};

has({obj: object, required: required}, function(err, data) {
  // => ['missing']
});


// Object of required keys and error messages
var required = {
  test: 'test is required',
  second: 'second as well',
  missing: 'required key'
};

var object = {
  test: 'item',
  second: false
};

has({obj: object, required: required}, function(err, data) {
  // => { missing: 'required key' }
});

returns

Object or Array

var has = require('obj-has');

// Array of required keys
var required = [
  'test',
  'second',
  'missing'
];

var object = {
  test: 'item',
  second: false
};

check = has({obj: object, required: required});
// => Error ['missing required argument: missing']


LICENSE MIT

Current Tags

  • 0.5.0                                ...           latest (5 years ago)

5 Versions

  • 0.5.0                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |