Registry / web-framework / iselement

iselement

JSON →
library1.1.4jsnpmunverified

The `iselement` package provides a focused utility function to accurately determine if a given JavaScript object is a DOM `Element`. Unlike simpler checks that rely solely on `instanceof HTMLElement`, this library is designed to correctly identify a broader range of elements, including 'exotic' elements such as SVG polygons. This ensures more robust and cross-browser compatible DOM manipulation logic, particularly crucial when dealing with complex web applications or third-party content. The current stable version is 1.1.4. Given its specific utility, the release cadence is typically stable and infrequent, with updates primarily for bug fixes or minor enhancements rather than new feature introductions. Its key differentiator is its comprehensive approach to element identification beyond standard HTML elements, providing reliable checks across the entire DOM specification.

npm install iselement
INSTALL
IMPORT
SIG · ISELEMENT
I
iselement
web-frameworkjavascriptv1.1.4
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.

isElement
import isElement from 'iselement';
import { isElement } from 'iselement';
The `iselement` package exports `isElement` as a default export for ESM. Ensure you import it without curly braces.
isElement
const isElement = require('iselement');
const { isElement } = require('iselement');
For CommonJS environments, the function is exported directly as the module. Do not attempt to destructure it as a named export.

Demonstrates how to use `isElement` to check various JavaScript values, including HTML and SVG elements, and non-element types, correctly distinguishing them from actual DOM elements.

import isElement from 'iselement'; // Example 1: Regular HTML element const div = document.createElement('div'); console.log('Is div an element?', isElement(div)); // true // Example 2: SVG element (a common edge case for instanceof HTMLElement) const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); console.log('Is SVG element an element?', isElement(svg)); // true console.log('Is SVG circle an element?', isElement(circle)); // true // Example 3: Non-element objects const obj = {}; const str = 'hello'; const num = 123; console.log('Is plain object an element?', isElement(obj)); // false console.log('Is string an element?', isElement(str)); // false console.log('Is number an element?', isElement(num)); // false // Example 4: Text node (not an Element, but a Node) const textNode = document.createTextNode('Hello'); console.log('Is text node an element?', isElement(textNode)); // false
Debug
Known issues
gotchaThis utility specifically checks for `Element` nodes, not all `Node` types. Text nodes, attribute nodes, or document fragments are `Node`s but not `Element`s, and `isElement` will return `false` for them. Ensure your logic correctly distinguishes between `Node` and `Element` if you expect to handle other node types.
fix
If you need to check for any DOM node type, consider `input instanceof Node` or a custom check. If you specifically need an Element, `isElement` is the correct function to use.
affects: >=1.0.0
gotchaThe `iselement` function is designed for browser environments and relies on the presence of the DOM API (e.g., `document`, `Element`). Running it in a pure Node.js environment without a DOM emulation library (like JSDOM) will likely result in `ReferenceError`s or incorrect behavior, as global objects like `HTMLElement` or `Element` might not be defined.
fix
Ensure `iselement` is only used in browser contexts or Node.js environments where a DOM is sufficiently emulated (e.g., for testing with JSDOM). For server-side logic, alternative methods for object type checking should be employed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: isElement is not a function
Attempting to import `isElement` as a named export (`import { isElement } from 'iselement';`) when it is a default export, or destructuing `require('iselement')`.
fix
For ESM, change to `import isElement from 'iselement';`. For CommonJS, change to `const isElement = require('iselement');`.
ReferenceError: HTMLElement is not defined
Attempting to use `iselement` in a pure Node.js environment without a DOM emulation layer like JSDOM, where browser-specific global objects are absent.
fix
Ensure `iselement` is executed in a browser context or in a Node.js environment that has JSDOM or similar global DOM objects configured. It is not intended for pure server-side logic.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
iselement — npm install iselement · libregistry