0.5.0 β’ Published 2 years ago
bistring v0.5.0
bistring
The bistring library provides non-destructive versions of common string processing operations like normalization, case folding, and find/replace. Each bistring remembers the original string, and how its substrings map to substrings of the modified version.
For example:
import BiString from "bistring";
let s = new BiString("πΏππ πππππ, πππππ π¦ πππππ ππππ πππ ππππ πΆ");
s = s.normalize("NFKD"); // Unicode normalization
s = s.toLowerCase(); // Case-insensitivity
s = s.replace("π¦", "fox"); // Replace emoji with text
s = s.replace("πΆ", "dog");
s = s.replace(/[^\w\s]+/g, ""); // Strip everything but letters and spaces
s = s.substring(0, 19); // Extract a substring
console.log(s.modified); // The modified substring, after changes
// the quick brown fox
console.log(s.original); // The original substring, before changes
// πΏππ πππππ, πππππ π¦
This allows you to perform very aggressive text processing completely invisibly.
Demo
Click here for a live demo of the bistring library in your browser.