Skip to content

A small rule-based library for inserting soft-hyphen, line-breaks (or similar) into long pieces of text

License

Notifications You must be signed in to change notification settings

nutgaard/softbreak

Repository files navigation

Softbreak

styled with prettier Travis codecov dependencies Status

How it works

Long words will get a soft-hyphen character (default config unicode 00ad) inserted into it to signal where the word-break can be. E.g The word 'strengths' would be converted into 'str­e­n­g­ths', which visually looks the same but actually is 4 characters longer.

Installation

npm install softbreak --save-dev

Usage

const config: Config = {
    insertCharacter: 'A',
    wordRules: [endRule, startRule],
    rules: [midRule]
  };

softbreak(config, 'alongwordhere');
softbreak([endRule, startRule], 'alongwordhere');
softbreak('alongwordhere');

rules and wordRules implement the same Rule which takes a single string, and returns a set of indicies where characters should be inserted.

rules receive the whole text, where-as wordRules receives a single word at the time. Indices from wordRules are automatically adjusted by the words original position. So all rules are interchangable between the two.

Types

Full documentation of types can be seen here, or here if you prefer reading typescript code.

Tips

  • Take a look at the original readme;

Credits

Made using the awesome typescript library starter

About

A small rule-based library for inserting soft-hyphen, line-breaks (or similar) into long pieces of text

Resources

License

Stars

Watchers

Forks

Packages

No packages published