npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@d3plus/dom

v3.1.1

Published

JavaScript functions for manipulating and analyzing DOM elements.

Readme

@d3plus/dom

NPM version codecov

JavaScript functions for manipulating and analyzing DOM elements.

Installing

If using npm, npm install @d3plus/dom. Otherwise, you can download the latest release from GitHub or load from a CDN.

import {*} from "@d3plus/dom";

In a vanilla environment, a d3plus global is exported from the pre-bundled version:

<script src="https://cdn.jsdelivr.net/npm/@d3plus/dom"></script>
<script>
  console.log(d3plus);
</script>

Examples

Live examples can be found on d3plus.org, which includes a collection of example visualizations using @d3plus/react.

API Reference

| Functions | Description | | --- | --- | | assign | A deeply recursive version of Object.assign. | | attrize | Applies each key/value in an object as an attr. | | backgroundColor | Given a DOM element, returns its background color by walking up the | | date | Parses numbers and strings into valid JavaScript Date objects, supporting years, quarters, months, and ISO 8601 formats. | | elem | Manages the enter/update/exit pattern for a single DOM element, applying enter, update, and exit attributes with optiona | | fontExists | Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or false | | [inViewport](#inviewport) | Determines whether a given DOM element is visible within the current viewport, with an optional pixel buffer. | | [isObject](#isobject) | Detects if a variable is a javascript Object. | | [parseSides](#parsesides) | Converts a string of directional CSS shorthand values into an object with the values expanded. | | [rtl](#rtl) | Returns true if the HTML or body element has either the "dir" HTML attribute or the "direction" CSS property set to "r | | [stylize](#stylize) | Applies each key/value in an object as a style. | | [textWidth`](#textwidth) | Given a text string, returns the predicted pixel width of the string when placed into DOM. |

| Type Aliases | Description | | --- | --- | | D3Selection | |

Functions

assign()

assign(...objects: Record<string, unknown>[]): Record<string, unknown>

Defined in: assign.ts:21

A deeply recursive version of Object.assign.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | ...objects | Record<string, unknown>[] | The source objects to merge into the target. |

Returns

Record<string, unknown>

Examples

assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}}));
{id: "bar", deep: {group: "A", value: 20}}

attrize()

attrize(e: Attrable, a?: Record<string, string | number | boolean | null>): void

Defined in: attrize.ts:8

Applies each key/value in an object as an attr.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | e | Attrable | The d3 selection to apply attributes to. | | a | Record<string, string | number | boolean | null> | An object of key/value attr pairs. |

Returns

void


backgroundColor()

backgroundColor(elem: Element): string

Defined in: backgroundColor.ts:7

Given a DOM element, returns its background color by walking up the ancestor chain until a non-transparent background is found. Falls back to "rgb(255, 255, 255)" (white) if every ancestor is transparent.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | elem | Element | The DOM element to check. |

Returns

string


date()

date(d: string | number | false | undefined): false | Date | undefined

Defined in: date.ts:5

Parses numbers and strings into valid JavaScript Date objects, supporting years, quarters, months, and ISO 8601 formats.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | d | string | number | false | required | The date value to parse (number, string, or Date). |

Returns

false | Date | undefined


elem()

elem(selector: string, p?: ElemParams): Selection

Defined in: elem.ts:28

Manages the enter/update/exit pattern for a single DOM element, applying enter, update, and exit attributes with optional transitions.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | selector | string | A CSS selector string for the element tag and classes. | | p? | ElemParams | Configuration object with enter, exit, update, and parent options. |

Returns

Selection


fontExists()

fontExists(font: string | string[]): string | false

Defined in: fontExists.ts:13

Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or false if none are installed on the user's machine.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | font | string | string[] | Can be either a valid CSS font-family string (single or comma-separated names) or an Array of string names. |

Returns

string | false


inViewport()

inViewport(elem: Element, buffer?: number): boolean

Defined in: inViewport.ts:6

Determines whether a given DOM element is visible within the current viewport, with an optional pixel buffer.

Parameters

| Parameter | Type | Default | Description | | ------ | ------ | ------ | ------ | | elem | Element | required | The DOM element to check. | | buffer | number | 0 | Extra pixel margin around the viewport boundary. |

Returns

boolean


isObject()

isObject(item: unknown): boolean

Defined in: isObject.ts:5

Detects if a variable is a javascript Object.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | item | unknown | The value to test. |

Returns

boolean


parseSides()

parseSides(sides: string | number): ParsedSides

Defined in: parseSides.ts:12

Converts a string of directional CSS shorthand values into an object with the values expanded.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | sides | string | number | The CSS shorthand string to expand. |

Returns

ParsedSides


rtl()

rtl(): boolean

Defined in: rtl.ts:4

Returns true if the HTML or body element has either the "dir" HTML attribute or the "direction" CSS property set to "rtl".

Returns

boolean


stylize()

stylize(e: Stylable, s?: Record<string, string | number | boolean | null>): void

Defined in: stylize.ts:8

Applies each key/value in an object as a style.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | e | Stylable | The d3 selection to apply styles to. | | s | Record<string, string | number | boolean | null> | An object of key/value style pairs. |

Returns

void


textWidth()

Call Signature

textWidth(text: string, style?: Record<string, string | number>): number

Defined in: textWidth.ts:49

Given a text string, returns the predicted pixel width of the string when placed into DOM.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | text | string | The text string to measure. | | style? | Record<string, string | number> | CSS style properties to apply when measuring. |

Returns

number

Call Signature

textWidth(text: string[], style?: Record<string, string | number>): number[]

Defined in: textWidth.ts:53

Parameters

| Parameter | Type | | ------ | ------ | | text | string[] | | style? | Record<string, string | number> |

Returns

number[]

Type Aliases

D3Selection

D3Selection = ReturnType<typeof select>

Defined in: D3Selection.ts:12