closure-dom
raw JSON → 1.0.0 verified Fri May 01 auth: no javascript
Closure DOM provides lightweight, Closure Compiler-compatible DOM manipulation utilities for JavaScript. The package (v1.0.0) includes methods like addClass, getDocumentHeight, insert, setOpacity, and others, designed for simple reuse across projects. It has a stable release cadence with infrequent updates. Its key differentiators are compatibility with Google Closure Compiler's advanced optimizations and minimal overhead, making it suitable for compiled applications. Unlike larger libraries, it offers focused, composable functions without dependencies.
Common errors
error SyntaxError: Cannot use import statement outside a module ↓
cause Package is ESM-only; using import in CommonJS context
fix
Add "type": "module" to package.json or use .mjs extension
error TypeError: closure_dom_1.addClass is not a function ↓
cause Default import used instead of named import
fix
Change to: import { addClass } from 'closure-dom';
Warnings
gotcha ESM-only package: does not support CommonJS require(). Use ES module imports. ↓
fix Use import syntax instead of require().
breaking All methods are not available as default export. Must use named imports. ↓
fix Import each function by name: import { functionName } from 'closure-dom';
Install
npm install closure-dom yarn add closure-dom pnpm add closure-dom Imports
- addClass wrong
import addClass from 'closure-dom';correctimport { addClass } from 'closure-dom'; - getDocumentHeight wrong
const { getDocumentHeight } = require('closure-dom');correctimport { getDocumentHeight } from 'closure-dom'; - insert wrong
import { insertElement } from 'closure-dom';correctimport { insert } from 'closure-dom';
Quickstart
import { addClass, getDocumentHeight, insert, setOpacity } from 'closure-dom';
const element = document.createElement('div');
addClass(element, 'highlight');
setOpacity(element, 0.5);
document.body.appendChild(element);
const height = getDocumentHeight();
console.log('Document height:', height);