Skip to content

flex-development/string-wrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

string-wrap

ci github release npm npm downloads install size codecov module type: esm license conventional commits typescript vitest yarn

Wrap a string

Contents

What is this?

TODO: what is this?

Install

This package is ESM only.

In Node.js with yarn:

yarn add @flex-development/string-wrap
See 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.

Use

TODO: use

API

This package exports the following identifiers:

The default export is wrap.

lines(thing, config[, options])

Get info about the lines of a wrapped string.

Overloads

  • lines(thing: unknown, config: number | string, options?: Options | null | undefined): LinesInfo
  • lines(thing: unknown, config: Config | number | string): LinesInfo
Parameters
  • thing (unknown) — the thing to wrap. non-string values will be converted to strings
  • config (Config | number | string) — the wrap configuration or the number of columns to wrap the string to
  • options (Options | null | undefined, optional) — options for wrapping
Returns

(LinesInfo) Info about the lines forming the wrapped string

wrap(thing, config[, options])

Wrap a string to the specified column width.

Overloads

  • wrap(thing: unknown, config: number | string, options?: Options | null | undefined): string
  • wrap(thing: unknown, config: Config | number | string): string
Parameters
  • thing (unknown) — the thing to wrap. non-string values will be converted to strings
  • config (Config | number | string) — the wrap configuration or the number of columns to wrap the string to
  • options (Options | null | undefined, optional) — options for wrapping
Returns

(string) The wrapped string

Types

This package is fully typed with TypeScript.

Config

String wrapping configuration (interface).

Extends

Properties

  • columns (number | string) — the number of columns to wrap the string to

LinePadding

The strings used to pad either side of each line (type).

type LinePadding = [left: string, right: string]

LinesInfo

Info about the lines of a wrapped string (interface).

Properties

  • eol (string) — the character, or characters, used to mark the end of a line
  • indent (string) — the string used to indent each line
  • lines (readonly string[]) — the list of lines forming the wrapped string
  • padding (LinePadding) — the strings used to pad either side of each line

Options

Options for wrapping a string (interface).

Properties

  • eol? (string | null | undefined, optional) — the character, or characters, used to mark the end of a line
    • default: '\n'
  • 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 of columns

    👉 note: setting this to true will break words.

  • hard? (boolean | null | undefined, optional) — whether to hard wrap words at the specified number of columns.
    by default, long words remain unbroken and push onto the next line if they don't fit on the current line.
    setting this to true will break long words.

    👉 note: setting this to true will break words.

  • indent? (number | string | null | undefined, optional) — the size of the indent, or a string used to indent each line
  • padLeft? (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 use
  • padRight? (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 use
  • stringify? (ToString | null | undefined, optional) — convert a value to a string
  • trim? (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

ToString<[T]>

Convert value to a string (type).

type ToString<T = any> = (this: void, value: T) => string

Type Parameters

  • T (any, optional) — the thing to stringify

Parameters

  • value (T) — the thing to stringify

Returns

(string) The stringified value

Contribute

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.

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  

Languages