Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "center"

Index

Variables

Variables

Const center

center: function = memoizeJ<number, string, Stringer<any>>((n, pad = " ") => {const buf = repeat(pad, n);return (x: any) => {if (x == null) return buf;x = x.toString();const r = (n - x.length) / 2;return x.length < n? buf.substr(0, r) +x +buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)): truncate(n)(x);};})

Returns stringer which pads given input with ch (default: space) on both sides and returns fixed width string of given lineWidth. Returns string of only pad characters for any null or undefined values. If the string version of an input is > lineWidth, no centering is performed, but the string will be truncated to lineWidth.

Note: The padding string can contain multiple characters.

center(20, "<>")(wrap(" ")("thi.ng"))
// "<><><> thi.ng <><><>"
param

target length

param

pad character(s)

Type declaration

    • (lineWidth: number, pad?: string | number): Stringer<any>
    • Parameters

      • lineWidth: number
      • Optional pad: string | number

      Returns Stringer<any>

Generated using TypeDoc