Registry / testing / css-chain-test

css-chain-test

JSON →
library1.1.9jsnpmunverified

css-chain-test (version 1.1.9) is a JavaScript/TypeScript package that serves as a demonstration and test suite for the underlying `CssChain` and `ApiChain` modules. These modules provide a lightweight, chainable API for manipulating collections of DOM elements or plain JavaScript objects. `CssChain` extends native DOM element methods and Array prototypes to allow for fluent, jQuery-like selection and manipulation, enabling operations such as adding event listeners or setting attributes on multiple elements in a single chained call. `ApiChain` offers similar chaining capabilities for arbitrary arrays of JavaScript objects. The package features recent updates focusing on improved TypeScript typings, enhanced shadow DOM support, and unified chain return types. It distinguishes itself by directly extending native browser APIs with a focus on a minimal footprint and modern module support, offering an alternative to heavier DOM manipulation libraries. The release cadence appears active, with frequent minor updates addressing features and typings.

npm install css-chain-test
INSTALL
IMPORT
SIG · CSS-CHAIN-TEST
C
css-chain-test
testingjavascriptv1.1.9
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CssChain
✓ import { CssChain } from 'css-chain-test';
✗ const CssChain = require('css-chain-test');
The `CssChain` function acts as both a selector and a chain initiator. For ESM, use named import. CommonJS `require` might result in an object containing `CssChain` rather than the function directly, or issues with default export patterns.
$ (alias for CssChain)
✓ import { CssChain as $ } from 'css-chain-test';
✗ import $ from 'css-chain-test';
The `$` alias for `CssChain` is a common pattern for brevity, but it must be imported as a named export and aliased, not as a default export.
ApiChain
✓ import { ApiChain } from 'css-chain-test';
✗ const ApiChain = require('css-chain-test').ApiChain;
ApiChain provides a similar chaining interface for plain JavaScript objects, often imported alongside CssChain for mixed DOM/data manipulation.

This quickstart demonstrates both CssChain for DOM manipulation (selecting elements, adding events, setting attributes/properties, chaining queries) and ApiChain for object array manipulation (setting properties, filtering, reducing) in a web browser environment.

import { CssChain as $, ApiChain } from 'css-chain-test'; // === CssChain: DOM Manipulation === // Create some dummy HTML for demonstration document.body.innerHTML = ` <div id="app"> <button class="my-button" title="Click me">Button 1</button> <button class="my-button" title="Don't click me">Button 2</button> <a href="#" class="my-link">Link 1</a> <input type="text" class="my-input" value="Initial Value"> <div class="container"> <span class="nested-span">Nested Span</span> </div> </div> `; // Select all buttons and add a click listener, then remove their title $('button.my-button') .on('click', (event) => { const target = event.target as HTMLElement; console.log(`Button clicked: ${target.textContent} (title was: ${target.title})`); target.style.backgroundColor = 'lightblue'; }) .attr('data-clicked', 'true') // Set a data attribute .removeAttribute('title'); // Remove the title attribute after setup // Select an input and set its value, then retrieve it const inputField = $('input.my-input'); inputField.value = 'New Value Set By CssChain'; // Set property for all selected inputs console.log(`Input value (from first element): ${inputField.value}`); // Get property from first element // Chain multiple event listeners for a link $('a.my-link') .on('mouseover', (ev) => (ev.target as HTMLElement).classList.add('hovered')) .on('mouseleave', (ev) => (ev.target as HTMLElement).classList.remove('hovered')) .text('Hover and click this link!'); // Query for children within a selected container $('div#app') .$('.nested-span') // Alias for querySelectorAll .text('Updated Nested Span Text') .css('color', 'green'); // === ApiChain: Object Manipulation === const data = [ { id: 1, name: 'Alice', active: true }, { id: 2, name: 'Bob', active: false }, { id: 3, name: 'Charlie', active: true } ]; const chainedData = ApiChain(data); // Set a property on all objects chainedData.active = false; console.log('All data objects made inactive:', chainedData.map(d => d.active)); // Get a property from the first object const firstId = chainedData.id; console.log('ID of the first object:', firstId); // You can still use array methods const activeUsers = chainedData.filter(user => user.active); // Will be empty now console.log('Active users after setting all to false:', activeUsers); // Let's create a new chain and modify it const moreData = ApiChain([ { category: 'A', value: 10 }, { category: 'B', value: 20 }, { category: 'A', value: 15 } ]); const sumValues = moreData.reduce((sum, item) => sum + item.value, 0); console.log('Sum of values in moreData:', sumValues); // Filter and then set a property moreData.filter(item => item.category === 'A').status = 'processed'; console.log('More data after processing category A:', moreData);
Debug
Known issues
gotchaReading properties from a `CssChain` collection (e.g., `$('input').value`) only returns the value from the *first* element in the collection. To retrieve values from all matching elements, use `map()` or explicit iteration.
fix
Use `$('input').map(el => el.value)` or `$('input').forEach(el => console.log(el.value))` to access properties on all elements.
affects: >=1.0.0
gotchaWhen assigning a property to a `CssChain` collection (e.g., `$('input').value = 'new'`), the property is set for *all* elements currently within that collection.
fix
Be aware that assignments affect the entire collection. If you need to update a single element, select it specifically (e.g., `$('#my-input').value = 'single'`).
affects: >=1.0.0
breakingPrior to version 1.1.9, the return types for some chained methods might have been inconsistent. Applications strictly relying on specific TypeScript return types or chaining assumptions might need minor adjustments after upgrading.
fix
Review type definitions and ensure compatibility with the unified chain return types. Re-test chaining logic, especially for custom extensions or complex sequences.
affects: <1.1.9
gotchaUsing `on()` (alias for `addEventListener`) or `remove()` (alias for `removeEventListener`) with a `CssChain` collection attaches or detaches the event listener to *each* element in the collection. Ensure proper cleanup to avoid memory leaks if elements or listeners are frequently added/removed.
fix
Always use `remove(eventName, cb)` to detach listeners when elements are removed from the DOM or no longer needed. Consider using delegated event listeners for performance in large collections.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0, _css_chain_test__WEBPACK_IMPORTED_MODULE_0__.CssChain) is not a function
Attempting to call `CssChain` as a constructor (`new CssChain()`) or an incorrect import mechanism (e.g., CommonJS `require` in an ESM context, or vice-versa) prevented the function from being correctly accessed.
fix
Ensure `CssChain` is imported as a named export for ESM (`import { CssChain } from 'css-chain-test';`) and called directly as a function: `CssChain('selector')`. For CommonJS, use `const { CssChain } = require('css-chain-test');`.
Cannot read properties of undefined (reading 'value')
This error occurs when attempting to access a property (like `.value` or `.textContent`) or an attribute on a `CssChain` or `ApiChain` collection that is empty, meaning no elements matched the selector or the initial array was empty. Getters for empty collections return `undefined`.
fix
Always check the `.length` of the collection before attempting to read properties (e.g., `if ($('selector').length > 0) { /* ... */ }`), or implement robust error handling for `undefined` return values.
Element.matches is not a function
This error typically indicates that the `Element.matches()` API, which `CssChain` might rely on (e.g., in `parent(css)`), is not supported in the current execution environment (e.g., an older browser, or a non-browser environment without a polyfill).
fix
For older browser targets, include a polyfill for `Element.matches` (e.g., from `core-js` or similar). Ensure the code is running in a modern DOM-compatible environment.
Upgrade
Version history
1.1.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources