Registry / serialization / js-types

js-types

JSON →
library4.0.0jsnpmunverified

The `js-types` package provides a comprehensive, programmatically accessible list of built-in JavaScript data types, primarily sourced from MDN Web Docs. It is currently at stable version 4.0.0, which requires Node.js 18.20 and is a pure ESM package. The package maintains a moderate release cadence, with major versions often coinciding with significant Node.js LTS updates and new ECMAScript feature adoptions. Its key differentiator lies in its straightforward design: the core data is simply a `js-types.json` file that can be directly imported, making it highly portable and easy to integrate across various JavaScript environments—from Node.js backend services to browser-side applications—without introducing complex dependencies. This makes it an ideal utility for tasks like runtime type checking, generating documentation, or any scenario requiring a definitive, up-to-date enumeration of JavaScript's fundamental types.

npm install js-types
INSTALL
IMPORT
SIG · JS-TYPES
J
js-types
serializationjavascriptv4.0.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.

jsTypes
import jsTypes from 'js-types';
const jsTypes = require('js-types');
Since v4.0.0, this package is pure ESM and must be imported using ES modules syntax. CommonJS `require()` is not supported.
typesJson
import typesJson from 'js-types/js-types.json';
const typesJson = require('js-types/js-types.json');
The raw JSON file can be imported directly for scenarios where the array of strings is sufficient. This is also ESM-only since v4.0.0.
Type (TypeScript)
type JSTypeName = typeof import('js-types')[number];
While `js-types` ships with TypeScript definitions, the default export is an array of strings. This example shows how to derive a union type of all possible JavaScript type names.

Demonstrates how to import the list of JavaScript types and perform basic operations, such as listing all types and checking for the presence of a specific type. This highlights the primary use case of accessing the array of type names.

import jsTypes from 'js-types'; console.log('--- All JavaScript Built-in Types ---'); console.log(`Total types found: ${jsTypes.length}`); console.log(jsTypes.join(', ')); // Example: Check if a specific type is in the list const typeToCheck = 'Map'; if (jsTypes.includes(typeToCheck)) { console.log(`\n'${typeToCheck}' is a recognized JavaScript built-in type.`); } else { console.log(`\n'${typeToCheck}' is NOT in the list of JavaScript built-in types.`); }
Debug
Known issues
breakingVersion 4.0.0 of `js-types` is now a pure ECMAScript Module (ESM) and no longer supports CommonJS `require()`. You must update your project to use `import` statements.
fix
Migrate your import statements from `const jsTypes = require('js-types');` to `import jsTypes from 'js-types';`. Ensure your project's `package.json` has `"type": "module"` or uses `.mjs` file extensions for ESM compatibility.
affects: >=4.0.0
breakingVersion 4.0.0 explicitly requires Node.js 18.20 or newer. Running on older Node.js versions will result in errors.
fix
Upgrade your Node.js environment to version 18.20 or later. Use `nvm` or your preferred Node.js version manager to switch versions.
affects: >=4.0.0
breakingVersion 3.0.0 required Node.js 18 or newer. If you are upgrading from an older version directly to v3.x or v4.x, ensure your Node.js version meets these minimums.
fix
Upgrade your Node.js environment to version 18 or later. For v4.0.0, ensure it's at least 18.20.
affects: >=3.0.0 <4.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import `js-types` in a CommonJS context when the package is pure ESM.
fix
Update your import statement from `const jsTypes = require('js-types');` to `import jsTypes from 'js-types';`. Ensure your project configuration supports ES modules (e.g., `"type": "module"` in `package.json`).
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'js-types' is not supported resolving ES modules
This error can occur if you're trying to import the package using a path like `import 'js-types';` without specifying the default export or if there's a misconfiguration in how your bundler/Node.js resolves ESM.
fix
Always use the full import path for the default export: `import jsTypes from 'js-types';` or specific files like `import typesJson from 'js-types/js-types.json';`.
TypeError: __dirname is not defined in ES module scope
When migrating to pure ESM, CommonJS globals like `__dirname`, `__filename`, and `require` are no longer available in the module scope.
fix
Refactor your code to use ES module equivalents. For `__dirname`, use `import.meta.url` and `path.dirname(fileURLToPath(import.meta.url))`.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
js-types — npm install js-types · libregistry