Registry / web-framework / crel
library4.2.1jsnpmunverified

Crel is a lightweight, minimalist JavaScript utility designed to simplify and accelerate the creation of DOM elements, serving as a more ergonomic alternative to directly using `document.createElement`. It enables developers to construct complex DOM trees with a concise, declarative syntax. The current stable version is 4.2.1, with the project demonstrating an active development and maintenance cadence over its lifetime, having evolved through multiple major versions. Key differentiators include its exceptionally small footprint (under 1KB minified and 500 bytes gzipped), its performance which rivals native `document.createElement` calls, and its avoidance of interference with existing in-DOM event listeners. It also provides a modern Proxy-based API for even cleaner syntax in environments supporting ES6 Proxies, making it suitable for modern evergreen browser applications.

npm install crel
INSTALL
IMPORT
SIG · CREL
C
crel
web-frameworkjavascriptv4.2.1
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.

crel
import crel from 'crel';
import { crel } from 'crel';
Primary default export for the standard API, used for creating DOM elements. `crel` itself is a function.
crel (CommonJS)
const crel = require('crel');
import crel from 'crel';
Standard CommonJS import for Node.js or Browserify environments where `require` is used.
crel.proxy
import crelBase from 'crel'; const crelProxy = crelBase.proxy;
import { proxy } from 'crel';
Accesses the Proxy-based API variant from the default export, enabling cleaner syntax like `crelProxy.div(...)` for environments supporting ES6 Proxies.

This quickstart demonstrates both the standard `crel` function and its Proxy-based API. It shows how to create and append various DOM elements, including handling attributes and events, illustrating the different ways to attach event listeners based on the API variant used.

import crel from 'crel'; // Standard API usage const standardButton = crel('button', { type: 'button', 'data-action': 'standard-click' // Direct event attributes like 'onclick' won't work without crel.attrMap['on'] setup }, 'Click Me (Standard)!'); const infoParagraph = crel('p', 'This element was created using the standard `crel` function syntax.'); const standardDiv = crel('div', { 'class': 'standard-example', style: 'padding: 15px; border: 1px solid #ccc; background-color: #f9f9f9;' }, crel('h2', 'Standard Crel API'), infoParagraph, standardButton ); // Attach event listener for the standard button (common alternative if attrMap['on'] isn't configured) standardButton.addEventListener('click', () => alert('Standard API button clicked (via addEventListener)!')); // Accessing the Proxy API from the default export const crelProxy = crel.proxy; // Proxy API usage const proxyButton = crelProxy.button({ type: 'button', onclick: () => alert('Proxy API button clicked!') // Proxy API handles 'onclick' directly as an attribute }, 'Proxy Click Me!'); const proxyInfoParagraph = crelProxy.p('This element was created using the modern Proxy API for cleaner syntax.'); const proxyDiv = crelProxy.div( { 'class': 'proxy-example', style: 'margin-top: 20px; padding: 15px; border: 1px solid #cce; background-color: #f0f8ff;' }, crelProxy.h2('Proxy Crel API'), proxyInfoParagraph, proxyButton ); // Append elements to the document body (or a specific container) document.body.appendChild(standardDiv); document.body.appendChild(proxyDiv); console.log('DOM elements created and appended to the document body.');
Debug
Known issues
gotchaCrel is designed for efficient creation of *new* DOM elements. While it's technically possible to pass existing DOM elements to `crel` for modification or rearrangement, this usage pattern is explicitly discouraged by the library's authors and can lead to unexpected behavior or inefficient DOM operations compared to native methods or libraries optimized for manipulation.
fix
For modifying or rearranging existing DOM elements, always use standard DOM manipulation methods (e.g., `appendChild`, `removeChild`, `insertBefore`) or a library specifically focused on efficient DOM manipulation and diffing.
affects: >=1.0.0
gotchaThe standard `crel` API handles event listeners via a custom `crel.attrMap['on']` definition. Direct `onclick` or `oninput` attributes within the attribute object for the standard API will *not* automatically attach event handlers without this custom mapping being set up beforehand.
fix
To use declarative event handling with the standard `crel` API, you must first configure `crel.attrMap['on']` as demonstrated in the library's documentation. Alternatively, for direct `on<event>` attribute support, utilize the Proxy API (`crel.proxy`) which natively maps these attributes to event listeners, or attach events manually using `element.addEventListener()`.
affects: >=1.0.0
gotchaCrel extensively utilizes modern ES6 features (e.g., Proxies for its advanced API). Consequently, it is specifically intended for use in modern 'evergreen' browser environments. Applications targeting older or legacy browsers will require transpilation (e.g., via Babel) to ensure full compatibility and functionality.
fix
Ensure your project's build pipeline includes a transpilation step for JavaScript code (e.g., using Babel with appropriate presets) if supporting legacy browsers is a requirement. Otherwise, explicitly target modern browsers where ES6 features are natively supported.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: crel is not defined
The `crel` library was not correctly imported, loaded, or is out of the current scope, preventing access to its primary function.
fix
Ensure `crel` is properly imported using `import crel from 'crel';` (ESM), `const crel = require('crel');` (CommonJS), or that `crel.min.js` is loaded via a `<script>` tag in the HTML before use.
TypeError: crel.proxy is not a function / crel.proxy is undefined
This error occurs when attempting to use the `crel.proxy` API without properly accessing it from the default export, or if the runtime environment does not support ES6 Proxies.
fix
Verify that your runtime environment supports ES6 Proxies. For ESM, access the proxy API correctly via `import crelBase from 'crel'; const crelProxy = crelBase.proxy;`. For CommonJS, use `const crelProxy = require('crel').proxy;`.
Upgrade
Version history
4.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources