Skip to content

strip

Removes all non ASCII characters from a string.

Arabic letters are kept alongside ASCII, so right-to-left labels survive the same treatment: spaces still become the spacer and punctuation is still removed.

import {strip} from "@d3plus/text";

strip("مرحبا بالعالم");
strip("Riyadh / الرياض");

Accented letters are folded to their plain ASCII equivalent, every space becomes the spacer (- by default), and anything else that is not a letter, digit, hyphen, or underscore is dropped, which makes the result safe for ids, class names, and file names.

import {strip} from "@d3plus/text";

strip("Héllo Wörld!");
strip("São Paulo");
strip("naïve café");
strip("Crème brûlée (2024)");

The second argument replaces each space: an underscore for snake_case style ids, a plus sign for query strings, or an empty string to run the words together.

import {strip} from "@d3plus/text";

strip("São Paulo", "_");
strip("New York City", "+");
strip("a b c", "");

Parameters

import {strip} from "@d3plus/text";
valuerequiredstring

The HTML string to strip.

spacerstringDefault -

The character to replace whitespace with.