lnked/react-starter

View on GitHub
src/helpers/utils/trim.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { isUndefined } from '../predicts/is-undefined'

export const trim = (str: string): string =>
  str && str.toString().replace(/^\s+|\s+$/g, '')

export const clean = (str: string): string =>
  (
    str &&
    str
      .toString()
      .replace(/\s+/gm, '')
      .replace(/_/gm, '')
      .replace(/-/gm, '')
      .replace(/[()]+/gm, '')
  ) || ''

export const trimmed = (str: string): string =>
  str && (!isUndefined(str) ? clean(str || '').toString() : '')