Skip to content

Latest commit

 

History

History
125 lines (107 loc) · 4.41 KB

str_readme.md

File metadata and controls

125 lines (107 loc) · 4.41 KB

Overview

str.mjs provides tools for string manipulation. Stuff missing from JS built-ins. Some of the features:

  • Unicode-aware word splitting and case conversion.
  • Unicode-aware truncation and ellipsis.
  • Sanity-checked parsing of booleans and numbers.
    • Unlike built-in parseFloat and parseInt, this library requires an entire string to be a valid input, without truncating the rest.

TOC

Perf

Written carefully and with benchmarks, but doesn't claim to be optimal at what it does. When in doubt, measure and compare.

Usage

Example case conversion:

import * as s from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/str.mjs'

s.words(`oneTwoThree`).title().snake() === `One_Two_Three`

s.words(`ΕΝΑ_ΔΥΟ_ΤΡΙΑ`).lower().kebab() === `ενα-δυο-τρια`

Misc

Nil tolerance rules:

  • Funs that take and return strings allow nil input.
  • Funs that answer questions about strings require strings.

API

Undocumented

The following APIs are exported but undocumented. Check str.mjs.