{"id":11107,"library":"iselement","title":"DOM Element Checker","description":"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.","status":"active","version":"1.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/fczbkk/iselement","tags":["javascript"],"install":[{"cmd":"npm install iselement","lang":"bash","label":"npm"},{"cmd":"yarn add iselement","lang":"bash","label":"yarn"},{"cmd":"pnpm add iselement","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `iselement` package exports `isElement` as a default export for ESM. Ensure you import it without curly braces.","wrong":"import { isElement } from 'iselement';","symbol":"isElement","correct":"import isElement from 'iselement';"},{"note":"For CommonJS environments, the function is exported directly as the module. Do not attempt to destructure it as a named export.","wrong":"const { isElement } = require('iselement');","symbol":"isElement","correct":"const isElement = require('iselement');"}],"quickstart":{"code":"import isElement from 'iselement';\n\n// Example 1: Regular HTML element\nconst div = document.createElement('div');\nconsole.log('Is div an element?', isElement(div)); // true\n\n// Example 2: SVG element (a common edge case for instanceof HTMLElement)\nconst svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\nconst circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\nconsole.log('Is SVG element an element?', isElement(svg)); // true\nconsole.log('Is SVG circle an element?', isElement(circle)); // true\n\n// Example 3: Non-element objects\nconst obj = {};\nconst str = 'hello';\nconst num = 123;\nconsole.log('Is plain object an element?', isElement(obj)); // false\nconsole.log('Is string an element?', isElement(str)); // false\nconsole.log('Is number an element?', isElement(num)); // false\n\n// Example 4: Text node (not an Element, but a Node)\nconst textNode = document.createTextNode('Hello');\nconsole.log('Is text node an element?', isElement(textNode)); // false\n","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For ESM, change to `import isElement from 'iselement';`. For CommonJS, change to `const isElement = require('iselement');`.","cause":"Attempting to import `isElement` as a named export (`import { isElement } from 'iselement';`) when it is a default export, or destructuing `require('iselement')`.","error":"TypeError: isElement is not a function"},{"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.","cause":"Attempting to use `iselement` in a pure Node.js environment without a DOM emulation layer like JSDOM, where browser-specific global objects are absent.","error":"ReferenceError: HTMLElement is not defined"}],"ecosystem":"npm"}