Wrap a string
TODO: what is this?
This package is ESM only.
In Node.js with yarn:
yarn add @flex-development/string-wrapSee Git - Protocols | Yarn for details regarding installing from Git.
In Deno with esm.sh:
import { wrap } from 'https://esm.sh/@flex-development/string-wrap'In browsers with esm.sh:
<script type="module">
import { wrap } from 'https://esm.sh/@flex-development/string-wrap'
</script>With bun:
bun add @flex-development/string-wrap
See bun add for more details.
TODO: use
This package exports the following identifiers:
The default export is wrap.
Get info about the lines of a wrapped string.
lines(thing: unknown, config: number | string, options?: Options | null | undefined): LinesInfolines(thing: unknown, config: Config | number | string): LinesInfo
thing(unknown) — the thing to wrap. non-string values will be converted to stringsconfig(Config|number|string) — the wrap configuration or the number of columns to wrap the string tooptions(Options|null|undefined,optional) — options for wrapping
(LinesInfo) Info about the lines forming the wrapped string
Wrap a string to the specified column width.
wrap(thing: unknown, config: number | string, options?: Options | null | undefined): stringwrap(thing: unknown, config: Config | number | string): string
thing(unknown) — the thing to wrap. non-string values will be converted to stringsconfig(Config|number|string) — the wrap configuration or the number of columns to wrap the string tooptions(Options|null|undefined,optional) — options for wrapping
(string) The wrapped string
This package is fully typed with TypeScript.
String wrapping configuration (interface).
columns(number|string) — the number of columns to wrap the string to
The strings used to pad either side of each line (type).
type LinePadding = [left: string, right: string]Info about the lines of a wrapped string (interface).
eol(string) — the character, or characters, used to mark the end of a lineindent(string) — the string used to indent each linelines(readonly string[]) — the list of lines forming the wrapped stringpadding(LinePadding) — the strings used to pad either side of each line
Options for wrapping a string (interface).
eol?(string|null|undefined, optional) — the character, or characters, used to mark the end of a line- default:
'\n'
- default:
fill?(boolean|null|undefined, optional) — whether to completely fill each column, splitting words as necessary.
by default, splits are made at spaces, ensuring that words aren't broken and don't extend past the configured number ofcolumns👉 note: setting this to
truewill break words.hard?(boolean|null|undefined, optional) — whether to hard wrap words at the specified number ofcolumns.
by default, long words remain unbroken and push onto the next line if they don't fit on the current line.
setting this totruewill break long words.👉 note: setting this to
truewill break words.indent?(number|string|null|undefined, optional) — the size of the indent, or a string used to indent each linepadLeft?(number|string|null|undefined, optional) — the size of the string to use for padding the left side of each line (as a number or numeric), or the string to usepadRight?(number|string|null|undefined, optional) — the size of the string to use for padding the right side of each line (as a number or numeric), or the string to usestringify?(ToString|null|undefined, optional) — convert a value to a stringtrim?(boolean|null|undefined, optional) — whether to remove whitespace from the end of each line👉 note: lines are trimmed before applying indents or padding.
- default:
true
- default:
Convert value to a string (type).
type ToString<T = any> = (this: void, value: T) => stringT(any, optional) — the thing to stringify
value(T) — the thing to stringify
(string) The stringified value
See CONTRIBUTING.md.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.