Options
All
  • Public
  • Public/Protected
  • All
Menu

Module SMHelper

Collection of utilities

Index

Functions

buildQuerystring

buildUrl

  • Build a full HTTP/S URL from the various fragments.

    Parameters

    • base: string

      Base of the URL, including the protocol (e.g. http://foo.bar/)

    • Optional parts: string | string[]

      Path, either as string or array (e.g. 'api/create' or ['api', 'create'])

    • Optional args: SMHelperDictionaryType

      Dictionary with GET parameters

    Returns string

    The full URL

cloneObject

  • cloneObject(obj: any): any
  • Clone a JS object, deeply.

    Parameters

    • obj: any

      The object to clone (any scalar or non-scalar type)

    Returns any

    The cloned object

compactObject

  • Remove all empty properties from an object. If "onlyNull", remove all null value only. The object obj, which is passed by reference, is modified.

    Parameters

    • obj: SMHelperDictionaryType

      Object to compact

    • Optional onlyNull: boolean

      If true, remove only values that are strictly null (default: false)

    Returns void

getDescendantProperty

  • Get a nested property from a dictionary or array, referenced by a string in "dot notation". For example: "key1.key2.0"

    Parameters

    Returns any

    Value of the referenced property or undefined

isNumeric

  • isNumeric(obj: any): boolean
  • Check if a value is numeric.

    Parameters

    • obj: any

      Value to analyze

    Returns boolean

    True if value is numeric

isPlainObject

  • isPlainObject(obj: any): boolean
  • Check if a value is a plain object.

    Parameters

    • obj: any

      Value to analyze

    Returns boolean

    True if value is a plain object

isScalar

  • isScalar(obj: any): boolean
  • Check if a value is of a scalar type (string, number, boolean).

    Parameters

    • obj: any

      Value to analyze

    Returns boolean

    True if value is of a scalar type

objectToDotNotation

  • Flatten a dictionary to the "dot notation", as used by MongoDB. If preserveArrays is true, arrays are not transformed to the "dot notation".

    Parameters

    • obj: SMHelperDictionaryType

      Dictionary to convert

    • Optional preserveArrays: boolean

      If true, arrays are not transformed to the "dot notation" (default: false)

    Returns SMHelperDictionaryType

    Flattened dictionary in "dot notation"

pregQuote

  • pregQuote(str: string, delimiter?: string): string
  • Take str and put a backslash in front of every character that is part of the regular expression syntax. Port of the PHP function "preg_quote". See also: http://php.net/preg_quote

    Parameters

    • str: string

      String to escape

    • Optional delimiter: string

      If the optional delimiter is specified, it will also be escaped. This is useful for escaping the delimiter that is required by the regular expressions. The / is the most commonly used delimiter.

    Returns string

    Quoted (escaped) string

strIs

  • strIs(pattern: string, value: string): boolean
  • Determine if a given string matches a pattern, allowing * as wildcard.

    Parameters

    • pattern: string

      Pattern to search in value

    • value: string

      String in which the pattern is searched

    Returns boolean

    True if value matches pattern

stringToCamel

  • stringToCamel(str: string): string
  • Convert strings with dashes or underscores (eg. 'foo-bar' or 'foo_bar') to camelCase ('fooBar')

    Parameters

    • str: string

      Dashed string

    Returns string

    String converted to camelCase

stripTags

  • stripTags(input: string, allowed?: string): string
  • Strip HTML tags, except allowed ones. This function is a port of the PHP strip_tags function: http://php.net/strip_tags

    Parameters

    • input: string

      Input string

    • Optional allowed: string

      String listing allowed HTML tags, for example <br>

    Returns string

    String with HTML tags stripped

toStringSafe

  • toStringSafe(val: any): string
  • Convert a value to string, ensuring that the number 0 and the boolean false are treated correctly.

    Parameters

    • val: any

      Value to convert

    Returns string

    String value

updatePropertyInObject

  • Update a property (represented in the "dot notation") in an object. The object obj, which is passed by reference, is modified.

    Parameters

    • obj: SMHelperDictionaryType

      Object to the be updated

    • property: string

      Name of the property to update, in "dot notation"

    • value: any

      New value for the matched property

    Returns void

Generated using TypeDoc