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 '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
Type aliases
Rule
Rule: function
Type declaration
( input: string ) : number []
Parameters
Returns number []
Functions
endOfText
endOfText( text: string ) : number []
Parameters
Returns number []
findInsertIndices
findInsertIndices( wordRules: Rule [] , rules: Rule [] , text: string ) : number []
Parameters
wordRules: Rule []
rules: Rule []
text: string
Returns number []
findWordInsertIndices
findWordInsertIndices( wordRules: Rule [] , text: string ) : number []
Parameters
wordRules: Rule []
text: string
Returns number []
flatten
flatten<T>( acc: T [] , value: T [] ) : T []
Type parameters
Parameters
Returns T []
indexesOf
indexesOf( text: string , regexpPattern: string ) : number []
Parameters
text: string
regexpPattern: string
Returns number []
insertCharAt
insertCharAt( char: string , index: number , text: string ) : string
Parameters
char: string
index: number
text: string
Returns string
insertChars
insertChars( char: string , indices: number [] , text: string ) : string
Parameters
char: string
indices: number []
text: string
Returns string
internal_softbreak
internal_softbreak( config: Config , text: string ) : string
Parameters
Returns string
middleOfText
middleOfText( text: string ) : number []
Parameters
Returns number []
numericSort
numericSort( a: number , b: number ) : number
Parameters
Returns number
removeDuplicates
removeDuplicates<T>( acc: T [] , value: T ) : T []
Type parameters
Parameters
Returns T []
softbreak
softbreak( configOrString: Config | Rule [] | string , optionalText?: undefined | string ) : string
Parameters
configOrString: Config | Rule [] | string
Optional optionalText: undefined | string
Returns string
splitLongWords
splitLongWords( wordPadding: number ) : Rule
startOfText
startOfText( text: string ) : number []
Parameters
Returns number []
Object literals
Const DEFAULT_CONFIG
DEFAULT_CONFIG: object
insertCharacter
insertCharacter: string = "Â"
rules
rules: never [] = []
wordRules
wordRules: function [] = [Rules.splitLongWords(3)]
Legend
Module
Object literal
Variable
Function
Function with type parameter
Index signature
Type alias
Enumeration
Enumeration member
Property
Method
Interface
Interface with type parameter
Constructor
Property
Method
Index signature
Class
Class with type parameter
Constructor
Property
Method
Accessor
Index signature
Inherited constructor
Inherited property
Inherited method
Inherited accessor
Protected property
Protected method
Protected accessor
Private property
Private method
Private accessor
Static property
Static method