should.js Utility Functions

1.0.1 · maintenance · verified Sun Apr 19

should-util is a foundational utility library within the should.js assertion ecosystem. It provides a collection of core helper functions, primarily type-checking utilities (e.g., `isString`, `isArray`, `isFunction`) and a `deepEqual` comparison function. The package itself is highly stable, having been at version 1.0.1 since its initial releases over a decade ago, with the last code commit occurring 7 years prior. As such, it follows a 'maintenance' release cadence, receiving no active development or new features. Its primary differentiator is its integral role in the should.js assertion library, offering common, reusable functionalities that are robust and well-tested, though not independently maintained for general-purpose use. It is predominantly a CommonJS module, reflecting its age.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and using `isString`, `isArray`, and `deepEqual` for type checking and object comparison, key utilities from the package.

import { isString, isArray, deepEqual } from 'should-util';

// Example 1: Type checking a string
const myString = 'Hello, world!';
console.log(`'${myString}' is a string: ${isString(myString)}`);
// Expected: 'Hello, world!' is a string: true

// Example 2: Type checking an array
const myArray = [1, 2, 3];
console.log(`${JSON.stringify(myArray)} is an array: ${isArray(myArray)}`);
// Expected: [1,2,3] is an array: true

// Example 3: Deep equality comparison
const objA = { a: 1, b: { c: 2 } };
const objB = { a: 1, b: { c: 2 } };
const objC = { a: 1, b: { c: 3 } };

console.log(`objA deepEqual objB: ${deepEqual(objA, objB)}`);
// Expected: objA deepEqual objB: true
console.log(`objA deepEqual objC: ${deepEqual(objA, objC)}`);
// Expected: objA deepEqual objC: false

// Example 4: Demonstrating other exports
import util from 'should-util'; // For older bundlers or direct CommonJS require
console.log(`Is null undefined? ${util.isUndefined(null)}`);
console.log(`Is undefined undefined? ${util.isUndefined(undefined)}`);

view raw JSON →