
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
npm install tinyboo
Import what you need :
import { isEmptyArray, isIP, isGreaterThan } from 'tinyboo';
And have fun !
Usage
Type checkers
isArray([]);
isBlob(new Blob());
isBoolean(false);
isDate(new Date());
isError(new Error());
isFile(new File());
isFunction(() => {});
isMap(new Map());
isNull(null);
isNumber(1);
isObject({});
isRegExp(/^foo(bar)?$/);
isSet(new Set());
isString('foo');
isSymbol(Symbol());
isUndefined(undefined);
isWeakMap(new WeakMap());
isWeakSet(new WeakSet());
isPrimitive('foo');
Arrays
isArrayOfBooleans([true, false]);
isArrayOfDates([new Date(), new Date()]);
isArrayOfNumbers([1, 2, 3]);
isArrayOfObjects([{}, {}]);
isArrayOfPrimitives(['foo', 1]);
isArrayOfStrings(['bar', '1']);
Objects
hasKey({ foo: 'bar' }, 'foo');
hasValue({ foo: 'bar' }, 'bar');
Numbers
isFiniteNumber(2);
isGreaterThan(700, 500);
isInteger(21);
isLessThan(300, 500);
isBetween(2, 1, 3);
Others
isEmptyArray([]);
isEmptyObject({});
isEmptyString(' ');
isEqual('foo', 'foo');
isHexadecimal('F1F1F1');
isIP('210.23.51.230');
isJSON('{ "foo": "bar" }');
More examples
isEqual
- works with array, boolean, null, number and string
isEqual([1, 'foo', 'bar'], [1, 'foo', 'bar']);
isEqual([1, 'foo', 'bar'], ['foo', 1, 'bar']);
isEqual(false, false);
isEqual(true, false);
isEqual(null, null);
isEqual(null, 'foo');
isEqual(1, 1);
isEqual(1, '1');
isEqual('foo', 'foo');
isEqual('foo', 'bar');
isIP
- only works with string
isIP('127.0.0.0');
isIP('0.0.0.0');
isIP('255.255.255.255');
isIP('192.168');
isIP(19216801);
isIP('127.000.000.000');
isJSON
- only works with string or null
isJSON('{}');
isJSON('null');
isJSON('{ "foo": "bar" }');
isJSON(null);
isJSON({});
isJSON({ foo: 'bar' });
isJSON('');
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!