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

speccy

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

speccy

simple specification pattern for JavaScript object validation

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-5.81%
Maintainers
1
Weekly downloads
 
Created
Source

Speccy

Simple JavaScript specification pattern for NodeJS and Browserify apps.

Basic Use

npm install speccy to install it.

// create a specification object

function HasValue(attr){
  this.attr = attr;
}

HasValue.prototype = Object.create(Specification);

HasValue.prototype.isSatisfiedBy = function(obj){
  if (!obj){ return false; }

  return obj[this.attr] !== undefined;
};

// use it

var hasFoo = new HasValue("foo");
var hasBar = new HasValue("Bar");
var hasBaz = new HasValue("Baz");

// build a compound spec using and/or/not
var mySpec = hasFoo.and(
  (
    hasBar.not(hasBaz)
  ).or(
    hasBaz.not(hasBar)
  )
);

// run the specs
console.log(mySpec.isSatisfiedBy({
  foo: "something",
  bar: "another thing"
})); //=> true

console.log(mySpec.isSatisfiedBy({
  foo: "something",
  baz: "third thing"
})); //=> true

console.log(mySpec.isSatisfiedBy({
  foo: "something",
  bar: "another thign",
  baz: "third thing"
})); //=> false

For more examples, see the tests in the tests folder.

Copyright ©2014 Muted Solutions, LLC. All Rights Reserved.

Distributed under MIT License.

Keywords

FAQs

Package last updated on 01 Jul 2014

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