• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JavaScript library for Line Breaking and identifying Word Boundaries, implementing the Unicode Line Breaking Algorithm (UAX #14)

css-line-break

CI NPM Downloads NPM Version

A JavaScript library for Line Breaking and identifying Word Boundaries, implementing the Unicode Line Breaking Algorithm (UAX #14)

Line breaking, also known as word wrapping, is the process of breaking a section of text into lines such that it will fit in the available width of a page, window or other display area. The Unicode Line Breaking Algorithm performs part of this process. Given an input text, it produces a set of positions called "break opportunities" that are appropriate points to begin a new line. The selection of actual line break positions from the set of break opportunities is not covered by the Unicode Line Breaking Algorithm, but is in the domain of higher level software with knowledge of the available width and the display size of the text.

In addition, the module implements CSS specific tailoring options to line breaking as defined in CSS Text Module Level 3.

Installing

You can install the module via npm:

npm install css-line-break

Usage

The LineBreaker creates an iterator that returns Breaks for a given text.

LineBreaker(text, [options]);

Example

JSFiddle

import {LineBreaker} from 'css-line-break';

const breaker = LineBreaker('Lorem ipsum lol.', {
    lineBreak: 'strict',
    wordBreak: 'normal'
});

const words = [];
let bk;

while (!(bk = breaker.next()).done) {
    words.push(bk.value.slice());
}

assert.deepEqual(words, ['Lorem ', 'ipsum ', 'lol.']);

Options

The following parameters are available for the options:

  • lineBreak: normal | strict
  • wordBreak: normal | break-all | break-word | keep-all

For more information how they affect the line breaking algorithms, check out CSS Text Module Level 3.

Testing

You can run the test suite with:

npm test

The library implements all the LineBreakTest.txt tests and a number of CSS web-platform-tests.

More Repositories

1

html2canvas

Screenshots with JavaScript
TypeScript
30,457
star
2

feedback.js

Feedback form with screenshot
JavaScript
868
star
3

php.js

PHP to JavaScript converter and VM written in JavaScript
PHP
859
star
4

base64-arraybuffer

Encode/decode base64 data into ArrayBuffers
TypeScript
353
star
5

WebGL-GTA

JavaScript implementation of GTA
JavaScript
258
star
6

html2canvas-proxy-nodejs

Express middleware proxy for html2canvas
JavaScript
119
star
7

react-bacon-flux-poc

JavaScript
70
star
8

WebGL-CSS-Shaders

CSS Shaders through WebGL
JavaScript
54
star
9

jquery.plugin.clipboard

jQuery plugin to modify the contents copied to clipboard
JavaScript
37
star
10

click-heatmap

Click heatmaps with Google Analytics
JavaScript
36
star
11

html2canvas-proxy

Proxies for html2canvas
Python
32
star
12

experiments.hertzen.com

Random mini experiments
HTML
19
star
13

CSS3-Shapes

CSS3 shape editor
JavaScript
18
star
14

text-segmentation

A JavaScript library for Grapheme Breaking and identifying Grapheme Boundaries, implementing the Unicode Line Breaking Algorithm (UAX #29)
TypeScript
15
star
15

mongoose-validators

Validators for Mongoose schemas with validator.js
JavaScript
13
star
16

webdriver.js

jQuery styled WebDriver bindings for node.js
JavaScript
13
star
17

jquery.plugin.placeholder

Add placeholder functionality to non-HTML5 browsers
JavaScript
8
star
18

html5-parser

html5 parser for node.js and browsers
JavaScript
8
star
19

webidl.js

WebIDL parser for JavaScript
JavaScript
6
star
20

3d-dom

http://blog.hertzen.com/post/68191200228/rendering-webpages-in-3d-with-javascript-and-webgl
JavaScript
4
star
21

css-values

JavaScript
3
star
22

utrie

Unicode Trie
TypeScript
3
star
23

reactive-templates

JavaScript
2
star
24

node-tus

Node.js resumable upload middleware
JavaScript
2
star
25

hertzen.com

CSS
1
star