Package Exports
- @thi.ng/strings
- @thi.ng/strings/float
- @thi.ng/strings/pad-left
- @thi.ng/strings/pad-right
- @thi.ng/strings/repeat
- @thi.ng/strings/wrap
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/strings) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
This project is part of the @thi.ng/umbrella monorepo.
About
Various (80+) string formatting, word wrapping & utility functions, some higher-order, some memoized.
Partially based on Clojure version of thi.ng/strf.
General
defFormat
/format
interpolate
/interpolateKeys
escape
/unescape
join
/splice
/split
repeat
stringify
Numeric formatters
radix
int
/intLocale
float
/floatFixedWidth
maybeParseFloat
/maybeParseInt
percent
uuid
vector
B8
/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
/capitalize
camel
/kebab
/snake
/upperSnake
Slugify
slugify
/slugifyGH
ANSI
isAnsi
/isAnsiEnd
/isAnsiStart
stripAnsi
lengthAnsi
Word wrapping
wordWrap
/wordWrapLine
/wordWrapLines
SPLIT_PLAIN
/SPLIT_ANSI
Padding / wrapping
center
padLeft
/padRight
truncate
/truncateLeft
/truncateRight
trim
wrap
Indentation
spacesToTabs
/spacesToTabsLine
tabsToSpaces
/tabsToSpacesLine
Char range presets / lookup tables
charRange
ALPHA
/ALPHA_NUM
/DIGITS
/LOWER
/UPPER
/HEX
BOM
/ESCAPES
/ESCAPES_REV
WS
/PUNCTUATION
Units
units
bits
/bytes
grams
meters
seconds
ruler
/grid
Miscellaneous
hstr
- Hollerith stringscomputeCursorPos
Status
STABLE - used in production
Search or submit any issues for this package
Installation
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: 4.08 KB / CJS: 4.38 KB / UMD: 4.15 KB
Dependencies
Usage examples
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 |
API
Basic usage examples
// 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
Karsten Schmidt
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 - 2021 Karsten Schmidt // Apache Software License 2.0