Categories

ep.scrunch()

Categories: Utilities

ep.scrunch( string, [ length ] )

Plugin: ep.core

Description: Trim the length of a text.

  • ep.scrunch( string, [ length ] )

    version added: 6.11.0

    string   A string to scrunch.

    length   A number to set the length of chars for the scrunch result. Default is 30.

  • ep.scrunch( string, [ options ] )

    version added: 6.11.0

    string   A string to scrunch.

    length   A set of key/value pairs that configure the scrunch.

The ep.scrunch() method trim the length of a text in different modes.

With the ratio argument you can set the trim position, so you can trim the begin, end or middle of a text. The trimmed text will replacer with a specified spacer.

  • Scrunch a text at the end.

    Code:
    ep.scrunch("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.")
    
    Results:
    Lorem ipsum dolor sit amet,...
    
    
  • Scrunch a text at the begin.

    Code:
    ep.scrunch( "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.", {
        ration: 0
    })
    
    Results:
    ...diam nonumy eirmod tempor.
    
    
  • Scrunch a text at the middle to length 50 without cut a word.

    Code:
    ep.scrunch( "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.", {
        ration: 0,
        cut: false,
        spacer: "....."
    });
    
    Results:
    Lorem ipsum dolor sit ..... nonumy eirmod tempor.
    
    
  • length

    version added: 6.11.0

    A number to set the length of chars for the scrunch result.

    Default: 30

  • ratio

    version added: 6.11.0

    A number between 0 (begin) and 1 (end) to set the position of scrunch and replace it with the spacer.

    Default: 1

  • cut

    version added: 6.11.0

    A boolean indicating whether to cut words.

    Default: true

  • spacer

    version added: 6.11.0

    A string to replace the text at the scrunch position.

    Default: ...