strip
Removes all non ASCII characters from a string.
Arabic preserved
Section titled “Arabic preserved”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 / الرياض");
Basic example
Section titled “Basic example”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)");
Custom spacer
Section titled “Custom spacer”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";