about summary refs log tree commit diff
path: root/src/lib/strings/helpers.ts
blob: 183d53e31762f97a7c0e68e5d5987765397a72dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export function pluralize(n: number, base: string, plural?: string): string {
  if (n === 1) {
    return base
  }
  if (plural) {
    return plural
  }
  return base + 's'
}

export function enforceLen(str: string, len: number, ellipsis = false): string {
  str = str || ''
  if (str.length > len) {
    return str.slice(0, len) + (ellipsis ? '...' : '')
  }
  return str
}