This project is part of the @thi.ng/umbrella monorepo.
Various higher-order, configurable string formatting & utility functions, some memoized. Please sources / docstrings for now.
Partially based on Clojure version of thi.ng/strf.
STABLE - used in production
yarn add @thi.ng/strings
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/strings?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/strings/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 2.44 KB / CJS: 2.67 KB / UMD: 2.55 KB
Several demos in this repo's /examples directory are using this package.
A selection:
Screenshot | Description | Live demo | Source |
---|---|---|---|
Basic crypto-currency candle chart with multiple moving averages plots | Demo | Source | |
Basic SPA example with atom-based UI router | Demo | Source | |
rstream based spreadsheet w/ S-expression formula DSL | Demo | Source | |
XML/HTML/SVG to hiccup/JS conversion | Demo | Source |
// 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)
defFormat
format
hstr
ignore
interpolate
str
camel
capitalize
kebab
lower
snake
slugify
upper
float
floatFixedWidth
maybeParseFloat
maybeParseInt
percent
radix
uuid
B8
/B16
/B32
- binary / bitstring presetsU8
/U16
/U24
/U32
/U64
- hex format presets (unsigned values)
center
padLeft
padRight
truncate
truncateLeft
wrap
Z2
/Z3
/Z4
- zero-pad presets
units
- define new unit w/ magnitudes & suffixesbits
bytes
grams
meters
seconds
charRange
repeat
splice
Karsten Schmidt
© 2015 - 2020 Karsten Schmidt // Apache Software License 2.0