word-wrap-it
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

Word-Wrap-It

GitHub license npm version

You can use this library to wrap texts.

Usage

import { wrap } from 'word-wrap-it';
//                 L  o  r  e  m      I  p  s  u  m
const charSizes = [9, 7, 5, 7, 12, 4, 3, 8, 6, 8, 12]; // character widths for variable font
const { lines, ranges, sizes } = wrap('Lorem Ipsum', 24, (text, charIndex, localIndex) => charSizes[charIndex]);
console.log(lines);
console.log(ranges);
console.log(sizes);

The result will be

[ 'Lor', 'em', 'Ips', 'um' ] // the resulting lines
[
  { start: 0, length: 3 },
  { start: 3, length: 3 },
  { start: 5, length: 4 },
  { start: 9, length: 2 }
] // the actual character ranges
[ 21, 19, 17, 20 ] // the trimmed line widths

Readme

Keywords

none

Package Sidebar

Install

npm i word-wrap-it

Weekly Downloads

1

Version

1.0.9

License

MIT

Unpacked Size

8.88 kB

Total Files

6

Last publish

Collaborators

  • liammartens