CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-js

Micro check library providing comprehensive type checking and validation operations across different JavaScript environments

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

is.js

is.js is a comprehensive micro check library for JavaScript that provides type checking and validation operations across different JavaScript environments. It offers a wide range of utility functions for checking data types, values, and conditions with support for AMD, Node.js, and browser environments through a universal module definition pattern.

Package Information

  • Package Name: is_js
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install is_js

Core Imports

const is = require('is_js');

For AMD:

define(['is_js'], function(is) {
  // Use is object
});

For browsers (global):

<script src="is.js"></script>
<script>
  // is is available globally
</script>

Basic Usage

const is = require('is_js');

// Basic type checking
console.log(is.string('hello'));     // true
console.log(is.number(42));          // true
console.log(is.array([1, 2, 3]));    // true

// Using modifiers
console.log(is.not.string(123));     // true
console.log(is.all.number(1, 2, 3)); // true
console.log(is.any.string('a', 123)); // true

// Complex validation
console.log(is.email('test@example.com')); // true
console.log(is.url('https://example.com')); // true
console.log(is.even(4));             // true

Architecture

is.js is built around several key components:

  • Core Interface: Main is object containing all checking functions
  • Modifier System: not, all, and any interfaces providing function variants
  • Universal Module: UMD pattern supporting AMD, CommonJS, and browser globals
  • Fluent API: Consistent boolean return values across all checking functions
  • Environment Detection: Browser and device-specific checks available in browser contexts

Capabilities

Type Checking

Core type validation functions for JavaScript primitives and objects. Essential for runtime type safety and input validation.

// Basic type checks
function arguments(value: any): boolean;
function array(value: any): boolean;
function boolean(value: any): boolean;
function date(value: any): boolean;
function error(value: any): boolean;
function function(value: any): boolean;
function number(value: any): boolean;
function object(value: any): boolean;
function regexp(value: any): boolean;
function string(value: any): boolean;

// Special type checks
function char(value: any): boolean;
function domNode(value: any): boolean;
function json(value: any): boolean;
function nan(value: any): boolean;
function null(value: any): boolean;
function sameType(value: any, other: any): boolean;
function undefined(value: any): boolean;
function windowObject(value: any): boolean;

Type Checking

Value Presence and State

Functions for checking value existence, truthiness, and basic state validation.

function empty(value: any): boolean;
function existy(value: any): boolean;
function falsy(value: any): boolean;
function truthy(value: any): boolean;
function space(value: any): boolean;

Presence Checking

String Validation

String-specific validation including case checking, content analysis, and format validation.

function capitalized(value: string): boolean;
function endWith(string: string, target: string): boolean;
function include(string: string, target: string): boolean;
function lowerCase(value: string): boolean;
function palindrome(value: string): boolean;
function startWith(string: string, target: string): boolean;
function upperCase(value: string): boolean;

String Checking

Pattern Matching

Regular expression-based validation for common data formats including emails, URLs, phone numbers, and postal codes.

function affirmative(value: any): boolean;
function alphaNumeric(value: any): boolean;
function caPostalCode(value: any): boolean;
function creditCard(value: any): boolean;
function dateString(value: any): boolean;
function email(value: any): boolean;
function hexadecimal(value: any): boolean;
function hexColor(value: any): boolean;
function ip(value: any): boolean;
function ipv4(value: any): boolean;
function ipv6(value: any): boolean;
function nanpPhone(value: any): boolean;
function socialSecurityNumber(value: any): boolean;
function timeString(value: any): boolean;
function ukPostCode(value: any): boolean;
function url(value: any): boolean;
function usZipCode(value: any): boolean;

Pattern Matching

Numeric Operations

Mathematical validation functions for number properties, comparisons, and arithmetic checks.

function above(n: number, min: number): boolean;
function decimal(n: number): boolean;
function equal(value: any, other: any): boolean;
function even(n: number): boolean;
function finite(n: number): boolean;
function infinite(n: number): boolean;
function integer(n: number): boolean;
function negative(n: number): boolean;
function odd(n: number): boolean;
function positive(n: number): boolean;
function under(n: number, max: number): boolean;
function within(n: number, min: number, max: number): boolean;

Numeric Operations

Collection Validation

Functions for validating arrays, objects, and their properties.

function inArray(value: any, array: any[]): boolean;
function sorted(array: any[], sign?: string): boolean;
function propertyCount(object: any, count: number): boolean;
function propertyDefined(object: any, property: string): boolean;

Collection Validation

Date and Time

Comprehensive date validation including relative time checks, specific date matching, and time range validation.

function day(date: Date, day: string): boolean;
function dayLightSavingTime(date: Date): boolean;
function future(date: Date): boolean;
function inDateRange(date: Date, start: Date, end: Date): boolean;
function leapYear(year: number): boolean;
function month(date: Date, month: string): boolean;
function past(date: Date): boolean;
function quarterOfYear(date: Date, quarter: number): boolean;
function today(date: Date): boolean;
function tomorrow(date: Date): boolean;
function weekend(date: Date): boolean;
function weekday(date: Date): boolean;
function year(date: Date, year: number): boolean;
function yesterday(date: Date): boolean;

Date and Time

Environment Detection

Browser and device detection functions for responsive behavior and feature detection.

// Browser detection
function chrome(range?: string | number): boolean;
function edge(range?: string | number): boolean;
function firefox(range?: string | number): boolean;
function ie(range?: string | number): boolean;
function opera(range?: string | number): boolean;
function safari(range?: string | number): boolean;

// Device detection
function android(): boolean;
function ios(): boolean;
function mobile(): boolean;
function tablet(): boolean;
function desktop(): boolean;

// Operating system detection
function linux(): boolean;
function mac(): boolean;
function windows(): boolean;

Environment Detection

Configuration and Utilities

Library configuration and utility functions for customization and namespace management.

function setNamespace(): typeof is;
function setRegexp(regexp: RegExp, name: string): void;

Configuration

Interface Modifiers

not Interface

All functions are available with negated logic through the not interface:

interface NotInterface {
  [K in keyof IsInterface]: IsInterface[K];
}

const not: NotInterface;

all Interface

Functions supporting the all interface check that all provided arguments pass the test:

interface AllInterface {
  [K in SupportedFunction]: (...args: any[]) => boolean;
}

const all: AllInterface;

any Interface

Functions supporting the any interface check that at least one provided argument passes the test:

interface AnyInterface {
  [K in SupportedFunction]: (...args: any[]) => boolean;
}

const any: AnyInterface;

Types

interface IsInterface {
  VERSION: string; // '0.8.0' as defined in source code
  not: NotInterface;
  all: AllInterface;
  any: AnyInterface;
  
  // All checking functions return boolean
  [functionName: string]: (...args: any[]) => boolean;
}

// Main export
const is: IsInterface;

docs

collection-validation.md

configuration.md

date-time.md

environment-detection.md

index.md

numeric-operations.md

pattern-matching.md

presence-checking.md

string-checking.md

type-checking.md

tile.json