🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

iwt

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iwt

iwt is a javascript utility that returns the value passed in when the passed variable is the value of the type you want, otherwise it returns the value of the default type.

latest
npmnpm
Version
1.0.8
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

iwt

iwt is a javascript utility that returns the value passed in when the passed variable is the value of the type you want, otherwise it returns the value of the default type.

Example Usage

var iwt = require("iwt");
const arr = { a: ["a"], b: 1 };
const obj = { a: { a: 1 }, b: 1 };

iwt.array(arr.a); // ['a'];
iwt.array(arr.b); // [];
iwt.array(arr.b, ["b"]); // ['b'];

iwt.object(obj.a); // {a: 1};
iwt.object(obj.b); // {};
iwt.object(obj.b, { b: 1 }); // {b: 1};

// ...
// iwt.null
// iwt.undefined
// iwt.function
// iwt.boolean
// iwt.number
// iwt.null
// iwt.null

const get = require("lodash/get");
const a = {};
iwt.object(get(a, "b.c.e.f.g.h")); // {};

API

methodsreturn value
array(any, defaultValue)[]
object(any, defaultValue){}
function(any, defaultValue)new Function()
boolean(any, defaultValue)true
string(any, defaultValue)''
number(any, defaultValue)0
undefined(any, defaultValue)undefined
null(any, defaultValue)null
date(any, defaultValue)new Date()
regExp(any, defaultValue)new RegExp()
symbol(any, defaultValue)Symbol('symbol')
getValue(type, any, defaultValue)
typeOf(any)"number","string","function", "regExp", "null", "undefined", "date", "boolean", "object", "array", "symbol"

Keywords

iwt

FAQs

Package last updated on 14 Oct 2019

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