nullcake
v1.0.2
Published
null is not scary
Downloads
1
Readme
nullCake
- check if the data is null or undefined
example
import nullCake from "nullCake";
const myDataCheck = nullCake();
//getType
const myDataType = myDataCheck.getType(data);
//check data
const isNull = myDataCheck.check(data);
// translate data to targetType
const myDataNew = myDataCheck.setData(datatypeObj, dataObj);
methods
| Method | Description | | ------- | ---------------------------------------------- | | getType | get data type ,return data's type in lowerCase | | check | check if the data is null or undefined | | setData | translate data to targetType |
use methods
getType
- get data type ,return data's type in lowerCase
const data = "get my data type";
const type = nullCake.getType(data);
console.log({ type }); // type: 'string'
check
- check if the data is null or undefined
const data = null
const isNull = nullCake.check(data)
console.log({isNull}) // isNull: true
--------------------------------------------------------
const dataString = 'null' | 'Null' |'NULL'
const isNull = nullCake.check(dataString)
console.log({isNull}) // isNull: 'null string'
--------------------------------------------------------
const dataUndefined = undefined
const isNull = nullCake.check(dataUndefined)
console.log({isNull}) // isNull: 'undefined'
--------------------------------------------------------
const undefinedStr = 'undefined' | 'Undefined' |'UNDEFINED'
const isNull = nullCake.check(undefinedStr)
console.log({isNull}) // isNull: 'undefined string'
--------------------------------------------------------
const data = 'string' | [] | ...
const isNull = nullCake.check(data)
console.log({isNull}) // isNull: false
- setData
- translate data to targetType
const targetData = { a: "", b: [], c: 0, d: () => {} };
const orginData = { a: "had a value", b: null, d: undefined };
const tData = nullCake.setData(targetData, orginData);
console.log({ tData }); // tData: {a: 'had a value', b:[], c:0, d:()=>{}}