npm.io
1.0.2 • Published 4 years ago

nullcake

Licence
ISC
Version
1.0.2
Deps
1
Size
4 kB
Vulns
0
Weekly
0

nullCake

  1. 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
  1. 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'
  1. 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
  1. 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:()=>{}}

Keywords