Package Exports
- @thi.ng/strings
- @thi.ng/strings/ansi
- @thi.ng/strings/api
- @thi.ng/strings/case
- @thi.ng/strings/center
- @thi.ng/strings/currency
- @thi.ng/strings/cursor
- @thi.ng/strings/entities
- @thi.ng/strings/escape
- @thi.ng/strings/float
- @thi.ng/strings/format
- @thi.ng/strings/groups
- @thi.ng/strings/hollerith
- @thi.ng/strings/initials
- @thi.ng/strings/int
- @thi.ng/strings/interpolate
- @thi.ng/strings/join
- @thi.ng/strings/named-number
- @thi.ng/strings/pad-left
- @thi.ng/strings/pad-right
- @thi.ng/strings/parse
- @thi.ng/strings/percent
- @thi.ng/strings/radix
- @thi.ng/strings/range
- @thi.ng/strings/repeat
- @thi.ng/strings/ruler
- @thi.ng/strings/slugify
- @thi.ng/strings/splice
- @thi.ng/strings/split
- @thi.ng/strings/stringify
- @thi.ng/strings/tabs
- @thi.ng/strings/trim
- @thi.ng/strings/truncate
- @thi.ng/strings/truncate-left
- @thi.ng/strings/units
- @thi.ng/strings/utf8
- @thi.ng/strings/uuid
- @thi.ng/strings/vector
- @thi.ng/strings/word-wrap
- @thi.ng/strings/wrap
Readme
[!NOTE] This is one of 210 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.
🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️
About
Various (~100) string formatting, word wrapping & utility functions, some higher-order, some memoized.
Partially based on Clojure version of thi.ng/strf.
General
defFormat/formatinterpolate/interpolateKeysescape/unescapejoin/splice/splitrepeatstringify
Numeric formatters
currency/chf/eur/gpb/usd/yenradixint/intLocalefloat/floatFixedWidthmaybeParseFloat/maybeParseIntpercentuuidvectorB8/B16/B32- fixed size binary formattersU8/U16/U24/U32/U64- fixed size hex formattersZ2/Z3/Z4- fixed sized zero padded number formatters
Casing
lower/upper/capitalizecamel/kebab/snake/upperSnake
Slugify
slugify/slugifyGH
ANSI
isAnsi/isAnsiEnd/isAnsiStartstripAnsilengthAnsi
Word wrapping
wordWrap/wordWrapLine/wordWrapLinesSPLIT_PLAIN/SPLIT_ANSI
Padding / wrapping
centerpadLeft/padRighttruncate/truncateLeft/truncateRighttrimwrap
Indentation
spacesToTabs/spacesToTabsLinetabsToSpaces/tabsToSpacesLine
Char range presets / lookup tables
charRangeALPHA/ALPHA_NUM/DIGITS/LOWER/UPPER/HEXBOM/ESCAPES/ESCAPES_REVWS/PUNCTUATION
Units
unitsbits/bytesgramsmeterssecondsruler/grid
Miscellaneous
hstr- Hollerith stringscomputeCursorPos
Status
STABLE - used in production
Search or submit any issues for this package
Installation
yarn add @thi.ng/stringsESM import:
import * as str from "@thi.ng/strings";Browser ESM import:
<script type="module" src="https://esm.run/@thi.ng/strings"></script>For Node.js REPL:
const str = await import("@thi.ng/strings");Package sizes (brotli'd, pre-treeshake): ESM: 5.54 KB
Dependencies
Note: @thi.ng/api is in most cases a type-only import (not used at runtime)
Usage examples
Eight projects in this repo's /examples directory are using this package:
| Screenshot | Description | Live demo | Source |
|---|---|---|---|
![]() |
ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvas | Demo | Source |
![]() |
Large ASCII font text generator using @thi.ng/rdom | Demo | Source |
![]() |
Basic crypto-currency candle chart with multiple moving averages plots | Demo | Source |
| Basic SPA example with atom-based UI router | Demo | Source | |
![]() |
Mastodon API feed reader with support for different media types, fullscreen media modal, HTML rewriting | Demo | Source |
![]() |
Generative audio synth offline renderer and WAV file export | Demo | Source |
![]() |
rstream based spreadsheet w/ S-expression formula DSL | Demo | Source |
![]() |
XML/HTML/SVG to hiccup/JS conversion | Demo | Source |
API
Basic usage examples
import { defFormat, float, percent } from "@thi.ng/strings";
// create a custom string formatter
const fmt = defFormat([
"Price: ",
{ usd: "$", gbp: "£", eur: "€" },
float(2),
" (",
percent(2),
" off)"
]);
// use format
fmt("usd", 1.2345, 0.5);
// Price: $1.23 (50.00% off)
fmt("eur", 1.2345, 0.25)
// Price: €1.23 (25.00% off)Authors
If this project contributes to an academic publication, please cite it as:
@misc{thing-strings,
title = "@thi.ng/strings",
author = "Karsten Schmidt",
note = "https://thi.ng/strings",
year = 2015
}License
© 2015 - 2025 Karsten Schmidt // Apache License 2.0






