Socket
Book a DemoInstallSign in
Socket

adhere-core

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adhere-core

Make objects adhere to a specification

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Adhere

var post = {
    title: 'My Summer Adventures',
    tags: [ 'summer', 'warm', 'luxury' ]
};

// Create a contract.
var validator = adhere({
    // The title will be coerced into a string.
    title: coerceString,
    // The tags property is expected to be an array. Each item is coerced into a string and expected to be a tag. 
    tags: adhere.compose.each([coerceString, expectTag])
});

// A function that tests if a given string is considered a tag. 
function expectTag(string) {
    if (!/[a-z]+/.test(string)) throw Exception('Invalid tag.')
    return string
}

// A function that will always output a string. 
function coerceString(value) {
    return '' + value
}

Can be used in browser. Useful for when you are creating an API.

Keywords

adhere

FAQs

Package last updated on 01 Sep 2015

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