DOM Node Types
This package `dom-node-types` (version 1.0.1) provides a lightweight solution for accessing the numeric constants associated with standard DOM Node types, such as `ELEMENT_NODE`, `TEXT_NODE`, and `COMMENT_NODE`. Its primary purpose is to offer these well-defined constants directly, enabling developers to avoid the necessity of including a full-fledged DOM implementation as a dependency when only these specific values are required for logic, type checking, or comparison. The package is maintained with a stable, low-cadence release cycle, reflecting its simple and immutable utility. Its key differentiator lies in its focused minimalism, providing essential DOM constants without introducing any additional overhead, browser API polyfills, or complex parsing capabilities, making it ideal for environments where a full DOM is unavailable or unnecessary.
Common errors
-
TypeError: (0 , dom_node_types__WEBPACK_IMPORTED_MODULE_0__.ELEMENT_NODE) is not a function
cause Attempting to call an imported constant as if it were a function, or a bundler/runtime misinterpreting the export type, often due to mixed ESM/CJS environments.fixEnsure `ELEMENT_NODE` is treated as a numeric constant, not a callable function. Verify correct import syntax for your module environment (ESM `import { ELEMENT_NODE }` or CJS `const { ELEMENT_NODE } = require`). -
ReferenceError: ELEMENT_NODE is not defined
cause The constant `ELEMENT_NODE` was used without being correctly imported or destructured from the `dom-node-types` package.fixAdd the appropriate import statement at the top of your file. For ESM: `import { ELEMENT_NODE } from 'dom-node-types';`. For CommonJS: `const { ELEMENT_NODE } = require('dom-node-types');`.
Warnings
- gotcha This package only exports numeric constants representing DOM Node types. It does not provide any DOM manipulation utilities, polyfills, or interaction with actual DOM elements.
Install
-
npm install dom-node-types -
yarn add dom-node-types -
pnpm add dom-node-types
Imports
- ELEMENT_NODE
import ELEMENT_NODE from 'dom-node-types';
import { ELEMENT_NODE } from 'dom-node-types'; - nodeTypes (wildcard)
import nodeTypes from 'dom-node-types';
import * as nodeTypes from 'dom-node-types';
- CommonJS (all)
import { ELEMENT_NODE } from 'dom-node-types';const nodeTypes = require('dom-node-types'); - CommonJS (individual)
var ELEMENT_NODE = require('dom-node-types'); // only assigns the module object, not the constant directlyconst { ELEMENT_NODE } = require('dom-node-types');
Quickstart
import { ELEMENT_NODE, TEXT_NODE, COMMENT_NODE } from 'dom-node-types';
console.log('DOM Node Types Constants:');
console.log(`ELEMENT_NODE: ${ELEMENT_NODE}`); // Expected: 1
console.log(`TEXT_NODE: ${TEXT_NODE}`); // Expected: 3
console.log(`COMMENT_NODE: ${COMMENT_NODE}`); // Expected: 8
// You can also import all as an object
import * as nodeTypes from 'dom-node-types';
console.log(`\nAll types object:`);
console.log(`nodeTypes.DOCUMENT_NODE: ${nodeTypes.DOCUMENT_NODE}`); // Expected: 9
console.log(`nodeTypes.CDATA_SECTION_NODE: ${nodeTypes.CDATA_SECTION_NODE}`); // Expected: 4
// This package is purely for constants, it does not interact with actual DOM elements.