Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @sap/cloud-sdk-util

cloud-sdk-utils

Package that contains general utility functions that we reuse multiple times in the SDK. While primarily designed for internal usage, they might also be benefical for consumers of the SDK.

Index

Functions

Const assocSome

  • assocSome<T>(key: string, value?: any): (Anonymous function)
  • Calls rambda's assoc function if the provided value is neither null nor undefined. Note that this is different to JS idiomatic checks for truthy/falsy values, i.e. an empty string will result in assoc being called.

    Type parameters

    • T

    Parameters

    • key: string

      The key to associate with the given value.

    • Optional value: any

      The value to associate with the given key.

    Returns (Anonymous function)

    A copy of the input object with the new key-value pair if the value is neither null nor undefined.

Const asyncPipe

  • asyncPipe(...fns: any[]): (Anonymous function)
  • Works similar to Ramdas pipe function, but works on promises, which allows using async functions.

    Parameters

    • Rest ...fns: any[]

      The functions to be chained.

    Returns (Anonymous function)

errorWithCause

  • errorWithCause(message: string, cause: Error): Error
  • Creates a new error using the provided message and appends the causes stacktrace to the new error's stacktrace.

    Parameters

    • message: string

      The message of the new error.

    • cause: Error

      The original error.

    Returns Error

    A new error instance.

flat

  • flat<T>(arr: T[][]): T[]
  • Flatten a multidimensional array

    Type parameters

    • T

    Parameters

    • arr: T[][]

      Multidimensional array to be flattened

    Returns T[]

    Flattened array

Const mergeSome

  • mergeSome(a: MapType<any>, b?: MapType<any>): MapType<any>
  • Calls rambda's merge function if second object is neither null nor undefined.

    Parameters

    • a: MapType<any>

      The object to merge into.

    • Optional b: MapType<any>

      The object which to merge into a.

    Returns MapType<any>

    A copy of the merge(a, b) or a if b is undefined or null.

propertyExists

  • propertyExists(obj: object, ...properties: string[]): boolean
  • Checks if a chain of properties exists on the given object.

    Parameters

    • obj: object

      The object to be checked.

    • Rest ...properties: string[]

      Chained properties.

    Returns boolean

    True if the property chain leads to a truthy value, false otherwise.

unique

  • unique<T>(words: T[]): T[]
  • Remove all duplicates from array

    Type parameters

    • T

    Parameters

    • words: T[]

      Array of strings that might contain duplicates

    Returns T[]

    Array of unique strings