# @unsudo/line-wrapper

> Create an array of wrapped text lines of a certain width

Latest version **1.0.0** (published 2022-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @unsudo/line-wrapper
pnpm add @unsudo/line-wrapper
yarn add @unsudo/line-wrapper
bun add @unsudo/line-wrapper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-01-14 |
| First published | 2022-01-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Archontis-Dimitrios Maletsas |
| Maintainers | unsudo |
| Keywords | wrap, wrapper, fit, resize, line-wrap, line-wrapper, fit-line, resize-line, line-width, text-wrap, text-wrapper, fit-text, resize-text, text-width |

## Links

- npm: https://www.npmjs.com/package/@unsudo/line-wrapper
- Repository: https://github.com/unsudo/line-wrapper
- Homepage: https://github.com/unsudo/line-wrapper#readme
- Issues: https://github.com/unsudo/line-wrapper/issues
- npm.io page: https://npm.io/package/@unsudo/line-wrapper

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-01-14

## README

# line-wrapper

Create an array of wrapped text lines of a certain width from a string. Convert text to an array of lines that can fit on a pre-determined width.


## Usage
```js
const { cleanText, wrapText } = require('@unsudo/line-wrapper');


// Remove EOL, NL, CR, starting and trailing whitespaces
const text = cleanText(' \
    This is a line with words. \r\n\
    Another line. \r\n\
    This is another line with words. \r\n'
);

// Custom function to measure width 
const measure = text => text.length;

// Maximum line width is 18 units
const wrapped = wrapText(text, 18, measure);

console.log(wrapped);
/**
[
    'This is a line ',
    'with words. ',
    'Another line. ', 
    'This is another ', 
    'line with words.  '
];
*/
```

## Usage with Canvas API
```js
const ctx = getCanvasCtx();
...

const wrapped = wrapText(
    text, 
    maxWidthInPx, 
    txt => ctx.measureText(txt).width
);
```

## Installation
```bash
npm install @unsudo/line-wrapper
```

---
_Source: https://npm.io/package/@unsudo/line-wrapper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
