Skip to content
/ iwt Public

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.

Notifications You must be signed in to change notification settings

jxchenvip/iwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

iwt.formatNumber(0.1+0.2) // 0.3
iwt.foramtNumber(0.1+0.2, 2) // '0.30'

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

API

methods return 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"
formatNumber number

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published