Functional, dependency-free check library for Node.js and the browser (transpiled).
npm i @fiquu/is
Import by category:
import { isString, isNumber } from '@fiquu/is/type';
import { isIntlPhone } from '@fiquu/is/regexp';
isString('foo'); // true
isString(2); // false
isNumber(1); // true
isNumber('1'); // false
intlPhone('+12015556677'); // true
intlPhone('1234'); // false
Or just what you need:
import { isIntlPhone } from '@fiquu/is/regexp/intl-phone';
import { isString } from '@fiquu/is/type/string';
import { isNumber } from '@fiquu/is/type/number';
isString('foo'); // true
isSstring(2); // false
isNumber(1); // true
isNumber('1'); // false
isIntlPhone('+12015556677'); // true
isIntlPhone('1234'); // false
If you need to check multiple values, then use the some
and every
array methods:
import { isString, isNumber } from '@fiquu/is/type';
['foo', 'bar'].every(isString); // true
[1, 2, 'baz'].every(isString); // false
[1, 2, 3, 4].every(isNumber); // true
[1, 2, 'foo'].every(isNumber); // false
['foo', 'bar', true].some(isString); // true
[1, 2, 'baz'].some(isString); // false
[1, null, '3'].some(isNumber); // true
[false, null, 'foo'].some(isNumber); // false
Please see the documentation page for more details.