Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

bistring

0.4.0 • Public • Published

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.normalize("NFKD");         // Unicode normalization
= s.toLowerCase();             // Case-insensitivity
= s.replace("🦊", "fox");      // Replace emoji with text
= s.replace("🐶", "dog");
= s.replace(/[^\w\s]+/g, "");  // Strip everything but letters and spaces
= s.substring(0, 19);          // Extract a substring
console.log(s.modified);         // The modified substring, after changes
// the quick brown fox
console.log(s.original);
// 𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐, 𝖇𝖗𝖔𝖜𝖓 🦊

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.

Keywords

none

Install

npm i bistring

DownloadsWeekly Downloads

1

Version

0.4.0

License

MIT

Unpacked Size

269 kB

Total Files

21

Last publish

Collaborators

  • avatar