Registry / serialization / typpy
library0.4.0jsnpmunverified

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 typpy
INSTALL
IMPORT
SIG · TYPPY
T
typpy
serializationjavascriptv0.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Typpy
import Typpy from 'typpy';
const Typpy = require('typpy');
For ESM, use default import. The package's primary export is a callable function that also carries `is` and `get` methods as properties. CommonJS `require` is still widely used in older Node.js projects, but `import` is preferred for modern JavaScript.
Typpy.is
import Typpy from 'typpy'; Typpy.is(value, type);
import { is } from 'typpy';
The `is` method is a property of the default `Typpy` export, not a standalone named export. It's accessed directly via the imported `Typpy` object/function.
Typpy.get
import Typpy from 'typpy'; Typpy.get(value);
import { get } from 'typpy';
Similar to `Typpy.is`, the `get` method is a property of the default `Typpy` export, not a named export. Access it via `Typpy.get` after importing the default.

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.

import Typpy from 'typpy'; console.log(Typpy(0)); // => "number" console.log(Typpy('', String)); // => true console.log(Typpy.is(null, 'null')); // => true console.log(Typpy.get([])); // => Array console.log(Typpy({}, true)); // => false console.log(Typpy({}, Object)); // => true console.log(Typpy.get({})); // => Object console.log(Typpy.get(42, true)); // => "number"
Debug
Known issues
gotchaThe documentation primarily showcases CommonJS `require` syntax. While modern Node.js and bundlers support `import Typpy from 'typpy';` for ESM, direct named exports like `import { is } from 'typpy';` are not provided. Always import the default `Typpy` object and access `is` and `get` as properties.
fix
Use `import Typpy from 'typpy';` and then `Typpy.is(...)` or `Typpy.get(...)` for ESM. For CommonJS, `const Typpy = require('typpy');` remains valid.
affects: >=1.0.0
gotchaTyppy's primary function `Typpy(input, target)` returns a boolean if `target` is provided, but a string if `target` is omitted. Ensure you handle both return types correctly in your logic.
fix
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)`.
affects: >=1.0.0
gotchaUnlike the native `typeof` operator which returns 'object' for `null`, `Typpy.is(null, 'null')` correctly evaluates to `true`. Be aware of this difference when migrating code or expecting native `typeof` behavior.
fix
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`.
affects: >=2.4.0
Errors
Common errors & fixes
TypeError: Typpy.is is not a function
Attempting to import `is` as a named export (`import { is } from 'typpy';`) instead of accessing it as a property of the default export.
fix
Change your import statement to `import Typpy from 'typpy';` and then call `Typpy.is(value, type);`.
ReferenceError: require is not defined
Using `const Typpy = require('typpy');` in an environment configured for ECMAScript Modules (ESM) without a CommonJS shim.
fix
Update your import statement to use ESM syntax: `import Typpy from 'typpy';`.
Typpy is not defined
The Typpy package was not correctly installed or imported. This could be due to a typo in the import path or a missing `npm install typpy` step.
fix
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.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
1
Resources
typpy — npm install typpy · libregistry