2.1.2 • Published 3 years ago

widow-js v2.1.2

Weekly downloads
59
License
ISC
Repository
github
Last release
3 years ago

alt text

Build Status

widow-js

Lightweight configurable JS tool to remove widows from dynamic text.

Table of Contents

Installation

npm i widow-js

Use case

Good use case: Removing widows from dynamics text for which you don't control.

Not so good use case: Remove widows from static site for which you are too lazy to remove yourself. But you know... no judgement here 🤷🏻‍♂️

How to use

Import widow-js

import Widow from 'widow-js';

Initializing will automatically remove widows with your options.

const widow = new Widow({words: 4, elements: 'p, span', warnings: false});

If you need to remove widows from more elements later, use the removeWidowedElements method. Note: Widow will cache elements already transformed previously to avoid extra words wrapping.

widow.removeWidowedElements('#newtext, .someClass');

If you'd like to remove widows from a string use the removeWidowedText method

widow.removeWidowedText('Some text that could cause widows');

Here's how you would use removeWidowedText in the context of a react app

render() {
    const widow = new Widow({words: 2, warnings: false});
    const text = widow.removeWidowedText(this.props.text);
    return (
        <p>{text}</p>
    )
}

If your words prop is greater than the number of words in an element, Widow will skip element.

Props

PropertydefaultDescription
words0Number value > 1
elementsnoneA DOMString containing one or more selectors to match against
warningsfalseTurn on/off warnings

Support

Please open an issue for support.

2.1.2

3 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago