Options
All
  • Public
  • Public/Protected
  • All
Menu

Module SMClean

Input cleanup utilities

Index

Functions

bool

  • bool(val: any): boolean
  • Cleans a boolean. The strings 'false', '0', 'no' and 'off' (case insensitive) cast to false.

    Parameters

    • val: any

      Value to clean

    Returns boolean

    Value converted to boolean

color

  • color(val: any): string | null
  • Cleans a string representing a HTML color. Accept only colors that can be used in HTML input[type=color] fields: #[A-Fa-f0-9]{6} (a subset of valid CSS colors)

    Parameters

    • val: any

      Value to clean

    Returns string | null

    Cleaned color or null

day

  • day(val: any): string | null
  • Cleans a string representing a day in format YYYY(-)MM(-)DD.

    Parameters

    • val: any

      Value to clean

    Returns string | null

    Valid day in the YYYY-MM-DD format (dashes added if absent) or null

email

  • email(val: any): string | null
  • Cleans a string representing an email address.

    Parameters

    • val: any

      Value to clean

    Returns string | null

    Cleaned email address or null

float

  • float(val: any): number
  • Cleans a string representing a floating point number. Invalid values are converted to 0.

    Parameters

    • val: any

      Value to clean

    Returns number

    Floating point number

int

  • int(val: any): number
  • Cleans a string representing an integer. Invalid values are converted to 0.

    Parameters

    • val: any

      Value to clean

    Returns number

    Integer number

objectId

  • objectId(val: any): string | null
  • Cleans a string representing a MongoDB ObjectId.

    Parameters

    • val: any

      Value to clean

    Returns string | null

    Valid MongoDB ObjectId or null

password

string

  • Cleans a string:

    1. Normalizes Unicode characters
    2. Trims whitespaces
    3. Strips control characters (optionally strips newline characters)
    4. (Optionally) Encodes HTML special characters, but does not strip tags

    Parameters

    Returns string

    Cleaned string

time

  • time(val: any, tz?: string): Date | null
  • Cleans a time and date representation, either a UNIX timestamp or a ISO 8601 full date.

    The optional parameter timezone is used as default value when passing a ISO 8601-formatted string that does not include a TZ specifier. If not specified, it will default to the system's timezone

    Parameters

    • val: any

      Value to clean, either a UNIX timestamp or a ISO 8601 full date

    • Optional tz: string

      Optional timezone for ISO 8601-formatted strings that don't include a TZ specifier; if empty, uses system default.

    Returns Date | null

    Valid Date object or null

timezone

  • timezone(val: any): string | null
  • Cleans a string representing a timezone identifier, according to the "tz database".

    Parameters

    • val: any

      Value to clean

    Returns string | null

    Valid string representing a timezone identifier or null

url

  • url(val: any): string | null
  • Clean a string representing a valid HTTP or HTTPS URL.

    Parameters

    • val: any

      Value to clean

    Returns string | null

    Valid string representing a HTTP/S URL or null

Generated using TypeDoc