Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-key-validator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-key-validator

check objects for the existence of certain keys

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by4.76%
Maintainers
1
Weekly downloads
 
Created
Source

object-key-validator

check objects for the existence of certain keys

API

validateKeys

(rule: Rule, obj: Object) => boolean

Accepts a rule definition and a test object. If the rule definition is invalid, the validation function will throw.

Rule Types

There are three rule types: $and, $or, and $not. Rules can be nested (as shown below).

$and

Checks an array of rules. If all of the rules pass, validation returns true.

Examples

// checks to make sure an object has BOTH `a` AND `b` keys
// logically: (a && b)
{ $and: ['a', 'b'] }

// checks to make sure an object has `a`, `b`, AND `c` keys
// logically: (a && (b && c))
{
  $and: [
    'a',
    { $and: ['b', 'c']}
  ]
}

$or

Checks an array of rules. If one or more of the rules pass, validation returns true.

Examples

// checks to make sure an object has EITHER `a` OR `b` keys
// logically: (a || b)
{ $or: ['a', 'b'] }

// checks to make sure an object has either an `a` key OR a `b` AND `c` key
// logically: (a || (b && c))
{
  $or: [
    'a',
    { $and: ['b', 'c']}
  ]
}

$not

Inverts the response value of a single rule. $not does not accept an array of conditions like $and and $or.

Examples

// checks to make sure an object doesn't have EITHER `a` OR `b` keys
// logically: !(a || b)
{ $not: { $or: ['a', 'b'] } }

// checks to make sure an object doesn't have either an `a` key OR a `b` AND `c` key
// logically: !(a || (b && c))
{
  $not: {
    $or: [
      'a',
      { $and: ['b', 'c']}
    ]
  }
}

FAQs

Package last updated on 02 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc