0.5.0 β€’ Published 2 years ago

bistring v0.5.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

bistring

npm version

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.

0.5.0

2 years ago

0.4.0

5 years ago

0.3.0

5 years ago