1.0.2 • Published 2 years ago

nullcake v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

MethodDescription
getTypeget data type ,return data's type in lowerCase
checkcheck if the data is null or undefined
setDatatranslate 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:()=>{}}