JSPM

typeco

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 661
  • Score
    100M100P100Q95882F
  • License MIT

A javascript library which allows to check javascript value types at runtime

Package Exports

  • typeco

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typeco) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

TypeCo

dependencies Status Build Status

A javascript micro library which allows you to check javascript data types.

Installation

  npm install typeco

Usage

typeco supports following functions and returns boolean value by checking the corresponding data type.

isArray()

  var typeco = require('typeco');
  var arr = [1, 2];
  var noArr = '';

  typeco.isArray(arr);        // true
  typeco.isArray(noArr);      // false

isObject()

  var typeco = require('typeco');
  var obj = { name: 'typeco' };
  var noObj = '';

  typeco.isObject(obj);        // true
  typeco.isObject(notObj);     // false

isString()

  var typeco = require('typeco');
  var str = 'typeco-string';
  var noStr = [];

  typeco.isString(str);        // true
  typeco.isString(noStr);     // false

isDate()

  var typeco = require('typeco');
  var date = new Date();
  var noDate = '';

  typeco.isDate(date);        // true
  typeco.isDate(noDate);     // false

isRegExp()

  var typeco = require('typeco');
  var reg = new RegExp('ab+c');
  var noReg = '';

  typeco.isRegExp(reg);        // true
  typeco.isRegExp(noReg);     // false

isFunction()

  var typeco = require('typeco');
  var func = function() {
    // this is a function
  };
  var noFunc = '';

  typeco.isFunction(func);        // true
  typeco.isFunction(noFunc);     // false

isBoolean()

  var typeco = require('typeco');
  var bool = true;
  var boolString = 'true';
  var noBool = '';

  typeco.isBoolean(bool);         // true
  typeco.isBoolean(boolString);   // true
  typeco.isBoolean(noBool);       // false

isNumber()

  var typeco = require('typeco');
  var num = 1;
  var noNum = '';

  typeco.isNumber(num);         // true
  typeco.isNumber(noNum);       // false

isEmpty()

This function return true if an object has no keys or an array has no items or a string is empty or the data is either null or undefined.

  var typeco = require('typeco');
  var str = '';
  var arr = [];
  var obj = {};
  var empty1 = null;
  var empty2 = undefined;

  typeco.isEmpty(str);         // true
  typeco.isEmpty(arr);         // true
  typeco.isEmpty(obj);         // true
  typeco.isEmpty(empty1);      // true
  typeco.isEmpty(empty2);      // true

isEmptyOrZero()

This functions works exactly same as isEmpty() but also returns true if the data is number and value is 0.

  var typeco = require('typeco');
  var num = 0;

  typeco.isEmptyOrZero(num);    // true

License

MIT Licensed. Copyright (c) Farhad Yasir 2018.