1.0.9 • Published 4 years ago

word-wrap-it v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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
1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago