What is is?
The 'is' npm package provides a set of utility functions for type checking and validation. It allows developers to easily determine the type of a variable, check for specific conditions, and validate data types.
What are is's main functionalities?
Type Checking
The 'is' package provides functions to check the type of a variable. For example, 'is.string' checks if a value is a string, 'is.number' checks if a value is a number, and 'is.array' checks if a value is an array.
const is = require('is');
console.log(is.string('hello')); // true
console.log(is.number(123)); // true
console.log(is.array([1, 2, 3])); // true
Existence Checks
The 'is' package includes functions to check for the existence and truthiness of values. 'is.empty' checks if a value is empty, 'is.existy' checks if a value exists (is not null or undefined), and 'is.truthy' checks if a value is truthy.
const is = require('is');
console.log(is.empty([])); // true
console.log(is.existy(null)); // false
console.log(is.truthy(1)); // true
Regex and String Checks
The 'is' package provides functions to validate strings against common patterns. For example, 'is.email' checks if a string is a valid email address, 'is.url' checks if a string is a valid URL, and 'is.creditCard' checks if a string is a valid credit card number.
const is = require('is');
console.log(is.email('test@example.com')); // true
console.log(is.url('https://www.example.com')); // true
console.log(is.creditCard('4111111111111111')); // true
Other packages similar to is
lodash
Lodash is a modern JavaScript utility library that provides a wide range of functions for common programming tasks, including type checking and validation. It offers similar functionality to 'is' but with a broader scope and additional utilities for working with arrays, objects, and more.
validator
Validator is a library for string validation and sanitization. It provides a comprehensive set of functions for validating and sanitizing strings, including checks for email addresses, URLs, and credit card numbers. It is more focused on string validation compared to 'is'.
type-detect
Type-detect is a library for type detection in JavaScript. It provides functions to determine the type of a variable, similar to the type checking features of 'is'. It is a lightweight alternative focused specifically on type detection.
is.js
JavaScript type testing library
API
is x ... ?
- arguments(x), args(x)
- array(x)
- arraylike(x)
- boolean(x), bool(x)
- date(x)
- decimal(x)
- defined(x), def(x)
- element(x), el(x)
- empty(x)
- error(x), err(x)
- func(x)
- integer(x), int(x)
- nan(x)
- nil(x)
- number(x), num(x)
- object(x)
- regex(x)
- string(x)
- undef(x)
License
(The MIT License)
Copyright (c) 2011 Enrico Marino <enrico.marino@email.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.