Giter VIP home page Giter VIP logo

is-in-correct-format's Introduction

is-in-correct-format Build Status

Allows you to check whether a given object is in the correct specified format.

Install

$ npm install --save is-in-correct-format

Usage

const isInCorrectFormat = require('is-in-correct-format');
const is = isInCorrectFormat.is;

isInCorrectFormat( {
	a:2
 },
 {
 	a: is.number
 });
//=> true

isInCorrectFormat( {
	a:{
    	b: 3,
        c: 24
    }
 },
 {
 	a: {
    	b: is.number
    }
 },is.number);
//=> true

isInCorrectFormat( {
	a:{
    	b: 3,
        c: [1,2,3]
    }
 },
 {
 	a: {
    	b: is.number
    }
 },is.number);
//=> true because the arrays values all satisfy 'is.number'

API

isInCorrectFormat(input, check, [allValues])

input

Type: Object
Description: The object being checked whether is in the correct type

Cyclical objects are not allowed.

check

Type: Object
Description: Follows the same format as the input object to check whether the given keys are passing the tests specified.

{
	a: is.function,
	b: function( val ) { 
		return val > 10
    },
    c: val => is.function(val) || is.object(val)
}

These are all examples of possibilities in the check object, you can use the helper object is to assist in checking type or define your own checker functions and arrow functions.

allValues

Type: Function Description: Will be calculated on all values of input object regardless of whether they show in the checked object or not.

isInCorrectFormat.is

number

Returns true if argument is a Number

string

Returns true if argument is a String

function

Returns true if argument is a function

boolean

Returns true if argument is true or false

true

Returns true if argument is true

false

Returns true if argument is a false

array

Returns true if argument is an Array

object

Returns true if argument is an Object

undefined

Returns true if argument is undefined

null

Returns true if argument is null

promise

Returns true if argument is a Promise

buffer

Returns true if argument is a Buffer

regex

Returns true if argument is a Regex

symbol

Returns true if argument is a Symbol

License

MIT © Nick The Sick

is-in-correct-format's People

Contributors

nperez0111 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.