Typpy is a lightweight JavaScript utility that provides a more robust and accurate approach to determining variable types compared to the native `typeof` operator. It addresses common ambiguities of `typeof`, such as `null` evaluating to "object" and distinguishing between different object types like arrays and plain objects. The library allows for type comparison against both string representations (e.g., "array") and constructor functions (e.g., `Array`). Currently at version 2.4.0, its release cadence is moderate, primarily consisting of minor updates for documentation, sponsor links, and small bug fixes like handling null/undefined constructors. It differentiates itself by offering a consolidated API for precise type checks, simplifying conditional logic and reducing potential type-related bugs in applications.
npm install typpyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use the main `Typpy` function to get a type string or compare against a target, and how to use the `Typpy.is` and `Typpy.get` helper methods for specific type checks.
Use `import Typpy from 'typpy';` and then `Typpy.is(...)` or `Typpy.get(...)` for ESM. For CommonJS, `const Typpy = require('typpy');` remains valid.When using `Typpy(input, target)`, check for a boolean result. When using `Typpy(input)` to get the type, expect a string. If consistent boolean results are desired, prefer `Typpy.is(input, target)`.
Leverage `Typpy`'s accurate `null` checking. If you specifically need the native `typeof` behavior, use the built-in operator directly. For consistent and precise type checking across all primitive and object types, stick with `Typpy`.
Change your import statement to `import Typpy from 'typpy';` and then call `Typpy.is(value, type);`.
Update your import statement to use ESM syntax: `import Typpy from 'typpy';`.
First, ensure the package is installed: `npm install typpy`. Then, verify the import statement `import Typpy from 'typpy';` (for ESM) or `const Typpy = require('typpy');` (for CommonJS) is correct and at the top of your file.No dependency data recorded yet.