Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nutgaard/softbreak
A small rule-based library for inserting soft-hyphen, line-breaks (or similar) into long pieces of text
https://github.com/nutgaard/softbreak
Last synced: 2 months ago
JSON representation
A small rule-based library for inserting soft-hyphen, line-breaks (or similar) into long pieces of text
- Host: GitHub
- URL: https://github.com/nutgaard/softbreak
- Owner: nutgaard
- License: mit
- Created: 2018-04-20T10:50:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-23T06:06:40.000Z (over 6 years ago)
- Last Synced: 2024-10-12T21:23:05.829Z (3 months ago)
- Language: TypeScript
- Size: 348 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Softbreak
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Travis](https://img.shields.io/travis/nutgaard/softbreak.svg)](https://travis-ci.org/nutgaard/softbreak)
[![codecov](https://codecov.io/gh/nutgaard/softbreak/branch/master/graph/badge.svg)](https://codecov.io/gh/nutgaard/softbreak)
[![dependencies Status](https://david-dm.org/nutgaard/softbreak/status.svg)](https://david-dm.org/nutgaard/softbreak)### 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 'strengths', which visually looks the same but actually is 4 characters longer.### Installation
```
npm install softbreak --save-dev
```### Usage
```javascript
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](https://www.utgaard.xyz/softbreak/),
or [here](https://github.com/nutgaard/softbreak/blob/master/src/softbreak.ts) if you prefer reading typescript code.### Tips
* Take a look at the original [readme](https://github.com/alexjoverm/typescript-library-starter/blob/master/README.md);
## Credits
Made using the awesome [typescript library starter](https://github.com/alexjoverm/typescript-library-starter)