Is_a_type

`breads.types`

Function: exists. Returns true if value isn't null or undefined, else returns false.

function exists(val: any): boolean;

Example:

const exists = require("103-breads").types.exists;

let something;
console.log(exists(something)); // false (not defined)

something = null;
console.log(exists(something)); // false (null)

something = "Hello!";
console.log(exists(something)); // true (has a value)

Function: isFunction. Returns true if value is a function, false otherwise. (The function does not execute)

function isFunction(val: any): boolean;

Example:

const isFunction = require("103-breads").types.isFunction;

function myFunc(test = "Hi!") {
    console.log(test);
}
console.log(isFunction(myFunc)); // true, function doesn't execute
console.log(isFunction("Hello!")); // false

Function: isNumber. Returns true if value is a number, false otherwise.

function isNumber(val: any): boolean;

Example:

const isNumber = require("103-breads").types.isNumber;

console.log(isNumber(123)); // true
console.log(isNumber("Hi")); // false

Function: isObject. Returns true if value is an object, false otherwise.

function isObject(val: any): boolean;

Example:

const isObject = require("103-breads").types.isObject;

console.log(isObject({ test: 'hi' })); // true
console.log(isObject("Hi")); // false

Function: isString. Returns true if value is an String object or it has a type of "string", false otherwise.

function isString(val: any): boolean;

Example:

const isString = require("103-breads").types.isString;

console.log(isString(String("Hello"))); // true
console.log(isString("Hi")); // true
console.log(isString(123)); // false

Last updated