Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Type aliases

Rule

Rule: function

Type declaration

    • (input: string): number[]
    • Parameters

      • input: string

      Returns number[]

Functions

endOfText

  • endOfText(text: string): number[]
  • Parameters

    • text: string

    Returns number[]

findInsertIndices

  • findInsertIndices(wordRules: Rule[], rules: Rule[], text: string): number[]

findWordInsertIndices

  • findWordInsertIndices(wordRules: Rule[], text: string): number[]

flatten

  • flatten<T>(acc: T[], value: T[]): T[]

indexesOf

  • indexesOf(text: string, regexpPattern: string): number[]
  • Parameters

    • text: string
    • regexpPattern: string

    Returns number[]

insertCharAt

  • insertCharAt(char: string, index: number, text: string): 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

middleOfText

  • middleOfText(text: string): number[]
  • Parameters

    • text: string

    Returns number[]

numericSort

  • numericSort(a: number, b: number): number

removeDuplicates

  • removeDuplicates<T>(acc: T[], value: T): 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

    • text: string

    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

Generated using TypeDoc