New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

basetype

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basetype

basic javascript type

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

basetype

Provide basic type validation functions and simple type composition.

Build Status Coverage Status

install

npm i basetype --save

type function

Type function is a boolean function, accept one argument and return boolean value.

eg:

let {likeArray} = require('basetype');

likeArray(123); // => false
likeArray([1, 2, 3]); // => true

basic types

isUndefined, isNull, isFalsy, likeArray, isString, isObject, isFunction, isNumber, isBool, isNode, isPromise, isReadableStream, isWritableStream

compose types

  • and
let newType = and(isObject, isArray);
newType([1, 2, 3]); // true
newType({}); // false
  • or
let newType = or(isNumber, isBool);
newType(4); // true
newType(true); // true
newType("123"); // false
  • not
let newType = not(isNumber);
newType(1); // false
newType("123"); // true
  • mapType
let type = mapType({
    a: isNumber,
    b: isBool
});

type({
    a: 3,
    b: false
}); //true

type({
    a: 3,
    b: {}
}); //false
  • listType
let type = listType(isNumber);
type([1, 2, 3]); //true
type([1, {}, 3]); //false
  • any
any([1, 2, 3], isNumber); //true
any([1, {}, 3], isNumber); //false
  • exist
exist([1, 2, 3], isString); //false
exist([1, {}, 3], isNumber); // true

function arguments type

let fun = funType((a, b) => a + b, [
    isNumber,
    isNumber
]);

fun(1, 2); // 3
fun('1', 2); // TypeError

Keywords

type

FAQs

Package last updated on 10 Jan 2017

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