Skip to content

Utilities library for type checking and other useful things. Already more than 40 functions (TypeScript supported). πŸ‘»

License

Notifications You must be signed in to change notification settings

stevenpersia/tinyboo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

tinyboo

Overview

Utilities library for type checking and other useful things. Already more than 40 functions. Each function returns false or true, that's it. Perfect for front and back ends. πŸ‘»

  • 0 dependencies 🌱
  • Super lightweight (~25 kB) ⚑
  • Easy to use 🀘
  • Tested πŸ› 
  • TypeScript supported 🌞

Roadmap : isUrl, isAbsoluteUrl, isRelativeUrl, isGif, isJpg, isPng, isPdf, isSvg, isWebp, isHtml, isZip, isRar, isMatch, ...

Installation

Install package :

yarn add tinyboo
# or
npm install tinyboo

Import what you need :

import { isEmptyArray, isIP, isGreaterThan } from 'tinyboo';

And have fun !

Usage

Type checkers

isArray([]); // β†’ true
isBlob(new Blob()); // β†’ true
isBoolean(false); // β†’ true
isDate(new Date()); // β†’ true
isError(new Error()); // β†’ true
isFile(new File()); // β†’ true
isFunction(() => {}); // β†’ true
isMap(new Map()); // β†’ true
isNull(null); // β†’ true
isNumber(1); // β†’ true
isObject({}); // β†’ true
isRegExp(/^foo(bar)?$/); // β†’ true
isSet(new Set()); // β†’ true
isString('foo'); // β†’ true
isSymbol(Symbol()); // β†’ true
isUndefined(undefined); // β†’ true
isWeakMap(new WeakMap()); // β†’ true
isWeakSet(new WeakSet()); // β†’ true
isPrimitive('foo'); // β†’ true

Arrays

isArrayOfBooleans([true, false]); // β†’ true
isArrayOfDates([new Date(), new Date()]); // β†’ true
isArrayOfNumbers([1, 2, 3]); // β†’ true
isArrayOfObjects([{}, {}]); // β†’ true
isArrayOfPrimitives(['foo', 1]); // β†’ true
isArrayOfStrings(['bar', '1']); // β†’ true

Objects

hasKey({ foo: 'bar' }, 'foo'); // β†’ true
hasValue({ foo: 'bar' }, 'bar'); // β†’ true

Numbers

isFiniteNumber(2); // β†’ true
isGreaterThan(700, 500); // β†’ true
isInteger(21); // β†’ true
isLessThan(300, 500); // β†’ true
isBetween(2, 1, 3); // β†’ true

Others

isEmptyArray([]); // β†’ true
isEmptyObject({}); // β†’ true
isEmptyString(' '); // β†’ true
isEqual('foo', 'foo'); // β†’ true
isHexadecimal('F1F1F1'); // β†’ true
isIP('210.23.51.230'); // β†’ true
isJSON('{ "foo": "bar" }'); // β†’ true

More examples

isEqual - works with array, boolean, null, number and string

// Array
isEqual([1, 'foo', 'bar'], [1, 'foo', 'bar']); // β†’ true
isEqual([1, 'foo', 'bar'], ['foo', 1, 'bar']); // β†’ false

// Boolean
isEqual(false, false); // β†’ true
isEqual(true, false); // β†’ false

// Null
isEqual(null, null); // β†’ true
isEqual(null, 'foo'); // β†’ false

// Number
isEqual(1, 1); // β†’ true
isEqual(1, '1'); // β†’ false

// String
isEqual('foo', 'foo'); // β†’ true
isEqual('foo', 'bar'); // β†’ false

isIP - only works with string

isIP('127.0.0.0'); // β†’ true
isIP('0.0.0.0'); // β†’ true
isIP('255.255.255.255'); // β†’ true

isIP('192.168'); // β†’ false
isIP(19216801); // β†’ false
isIP('127.000.000.000'); // β†’ false

isJSON - only works with string or null

isJSON('{}'); // β†’ true
isJSON('null'); // β†’ true
isJSON('{ "foo": "bar" }'); // β†’ true
isJSON(null); // β†’ true

isJSON({}); // β†’ false
isJSON({ foo: 'bar' }); // β†’ false
isJSON(''); // β†’ false

Star, Fork, Clone & Contribute

Feel free to contribute on this repository. If my work helps you, please give me back with a star. This means a lot to me and keeps me going!

About

Utilities library for type checking and other useful things. Already more than 40 functions (TypeScript supported). πŸ‘»

Topics

Resources

License

Stars

Watchers

Forks