Home Reference Source Repository
import OlapicUtils from 'OlapicDevKit-ES6/src/tools/utils.js'
public class | source

OlapicUtils

A list of utlity methods for the DevKit library.

Static Method Summary

Static Public Methods
public static

assignToString(string: string, assigments: Object): string

Assign a list of parameters to a string with placeholders.

public static

rejectedPromise(response: *): Promise<null, *>

Returns an already rejected promise.

public static

resolvedPromise(response: *): Promise<*, null>

Returns an already resolved promise.

Static Public Methods

public static assignToString(string: string, assigments: Object): string source

Assign a list of parameters to a string with placeholders.

Params:

NameTypeAttributeDescription
string string

The base string.

assigments Object
  • optional
  • default: {}

A dictionary with named assignments for the string placeholders.

Return:

string

The parsed string.

Example:

// It will return 'Hello world'
OlapicUtils.assignToString('Hello {target}', { target: 'world' });

public static rejectedPromise(response: *): Promise<null, *> source

Returns an already rejected promise.

Params:

NameTypeAttributeDescription
response *

The object to send to the .catch method.

Return:

Promise<null, *>

This promise won't call .then but .catch directly.

Example:

OlapicUtils.rejectedPromise('error message').catch((e) => {
    // It will log 'error message'
    console.log(e);
});

public static resolvedPromise(response: *): Promise<*, null> source

Returns an already resolved promise.

Params:

NameTypeAttributeDescription
response *

The object to send to the .then method.

Return:

Promise<*, null>

This promise won't call .catch.

Example:

OlapicUtils.rejectedPromise('hello world').then((message) => {
    // It will log 'hello world'
    console.log(message);
});