OPX//77
opx_lib

Lib.Text

Last updated on

Display text measured and cut in UTF-8 characters, not bytes.

Pure. No permission.

Lib.Text.Span

Byte length of the first maximum characters.

Lib.Text.Span(text, maximum)

Parameters

  • text: string
  • maximum: integer — characters

Returns

  • integer

Lib.Text.Length

How many characters a string holds.

Lib.Text.Length(value)

Parameters

  • value: any

Returns

  • integer

Lib.Text.Clean

Control characters replaced, cut to maximum characters, ellipsis appended when cut.

Lib.Text.Clean(value, maximum, ellipsis)

Parameters

  • value: any
  • maximum: integer — characters
  • ellipsis?: string

Returns

  • string?
Example
local title = Lib.Text.Clean(input.title, 32, '…')

Lib.Text.Bytes

Cuts to limit bytes without splitting a character.

Lib.Text.Bytes(text, limit)

Parameters

  • text: string
  • limit: integer — bytes

Returns

  • string

Lib.Text.Slug

A lower-cased name of letters, digits, _ and -.

Lib.Text.Slug(value, limit)

Parameters

  • value: any
  • limit?: integer
    • Bytes. Default: 64.

Returns

  • string?

Lib.Text.Rest

Joins the words from first on with spaces.

Lib.Text.Rest(words, first)

Parameters

  • words: string[]
  • first?: integer
    • Default: 1.

Returns

  • string
Example
local reason = Lib.Text.Rest(args, 2) -- '/kick 12 too loud' -> 'too loud'

Lib.Text.Switch

Reads on/off and synonyms (on true 1 yes, off false 0 no, any case, or a boolean); nil for anything else.

Lib.Text.Switch(value)

Parameters

  • value: any

Returns

  • boolean?

On this page