[79a0317] | 1 | css-line-break
|
---|
| 2 | ==============
|
---|
| 3 |
|
---|
| 4 | ![CI](https://github.com/niklasvh/css-line-break/workflows/CI/badge.svg?branch=master)
|
---|
| 5 | [![NPM Downloads](https://img.shields.io/npm/dm/css-line-break.svg)](https://www.npmjs.org/package/css-line-break)
|
---|
| 6 | [![NPM Version](https://img.shields.io/npm/v/css-line-break.svg)](https://www.npmjs.org/package/css-line-break)
|
---|
| 7 |
|
---|
| 8 | A JavaScript library for Line Breaking and identifying Word Boundaries,
|
---|
| 9 | [implementing the Unicode Line Breaking Algorithm (UAX #14)](http://unicode.org/reports/tr14/)
|
---|
| 10 |
|
---|
| 11 | >> Line breaking, also known as word wrapping, is the process of breaking a section of text into
|
---|
| 12 | lines such that it will fit in the available width of a page, window or other display area.
|
---|
| 13 | The Unicode Line Breaking Algorithm performs part of this process. Given an input text,
|
---|
| 14 | it produces a set of positions called "break opportunities" that are appropriate points to
|
---|
| 15 | begin a new line. The selection of actual line break positions from the set of break opportunities
|
---|
| 16 | is not covered by the Unicode Line Breaking Algorithm, but is in the domain of higher level
|
---|
| 17 | software with knowledge of the available width and the display size of the text.
|
---|
| 18 |
|
---|
| 19 | In addition, the module implements CSS specific tailoring options to line breaking as
|
---|
| 20 | defined in [CSS Text Module Level 3](https://www.w3.org/TR/css-text-3/#line-breaking).
|
---|
| 21 |
|
---|
| 22 | ### Installing
|
---|
| 23 | You can install the module via npm:
|
---|
| 24 |
|
---|
| 25 | npm install css-line-break
|
---|
| 26 |
|
---|
| 27 | ### Usage
|
---|
| 28 | The `LineBreaker` creates an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) that returns `Break`s for a given text.
|
---|
| 29 |
|
---|
| 30 | LineBreaker(text, [options]);
|
---|
| 31 |
|
---|
| 32 | ### Example
|
---|
| 33 | [JSFiddle](https://jsfiddle.net/ofd3752k)
|
---|
| 34 | ```javascript
|
---|
| 35 | import {LineBreaker} from 'css-line-break';
|
---|
| 36 |
|
---|
| 37 | const breaker = LineBreaker('Lorem ipsum lol.', {
|
---|
| 38 | lineBreak: 'strict',
|
---|
| 39 | wordBreak: 'normal'
|
---|
| 40 | });
|
---|
| 41 |
|
---|
| 42 | const words = [];
|
---|
| 43 | let bk;
|
---|
| 44 |
|
---|
| 45 | while (!(bk = breaker.next()).done) {
|
---|
| 46 | words.push(bk.value.slice());
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | assert.deepEqual(words, ['Lorem ', 'ipsum ', 'lol.']);
|
---|
| 50 | ```
|
---|
| 51 | ### Options
|
---|
| 52 | The following parameters are available for the options:
|
---|
| 53 |
|
---|
| 54 | - `lineBreak`: `normal` | `strict`
|
---|
| 55 | - `wordBreak`: `normal` | `break-all` | `break-word` | `keep-all`
|
---|
| 56 |
|
---|
| 57 | For more information how they affect the line breaking algorithms,
|
---|
| 58 | check out [CSS Text Module Level 3](https://www.w3.org/TR/css-text-3/#line-breaking).
|
---|
| 59 |
|
---|
| 60 | ### Testing
|
---|
| 61 | You can run the test suite with:
|
---|
| 62 |
|
---|
| 63 | npm test
|
---|
| 64 |
|
---|
| 65 | The library implements all the [LineBreakTest.txt tests](http://www.unicode.org/Public/10.0.0/ucd/auxiliary/LineBreakTest.txt)
|
---|
| 66 | and a number of CSS web-platform-tests. |
---|