EgoJSUtils
A set of utlity methods.
Static Method Summary
Static Public Methods | ||
public static |
mergeObjects(objects: ...Object): Object It will merge a given list of Objects into a new one. |
|
public static |
rejectedPromise(response: *): Promise<null, *> Returns an already rejected promise. |
|
public static |
Wraps a Request call into a Promise. |
|
public static |
resolvedPromise(response: *): Promise<*, null> Returns an already resolved promise. |
Static Public Methods
public static mergeObjects(objects: ...Object): Object source
It will merge a given list of Objects into a new one. It works recursively, so any "sub objects" will also be merged. This method returns a new Object, so none of the targets will be modified.
Params:
Name | Type | Attribute | Description |
objects | ...Object | The list of objects to merge. |
Example:
const a = {
b: 'c',
d: {
e: 'f',
g: {
h: ['i'],
},
},
j: 'k',
};
const b = {
j: 'key',
d: {
g: {
h: ['x', 'y', 'z'],
l: 'm',
},
},
};
// The result will be
// {
// b: 'c',
// d: {
// e: 'f',
// g: {
// h: ['x', 'y', 'z'],
// l: 'm',
// },
// },
// j: 'key',
// }
._mergeObjects(a, b);
public static rejectedPromise(response: *): Promise<null, *> source
Returns an already rejected promise.
Params:
Name | Type | Attribute | Description |
response | * | The object to send to the |
Example:
EgoJSUtils.rejectedPromise('error message').catch((e) => {
// It will log 'error message'
console.log(e);
});
public static request(data: Object): Promise<Object, Error> source
Wraps a Request call into a Promise.
Params:
Name | Type | Attribute | Description |
data | Object | The request settings. The same you would use with request(). |
Example:
request({uri: 'https://homer0.com/rosario'})
.then((response) => doSomething(response))
.catch((err) => handleErrors(err));
public static resolvedPromise(response: *): Promise<*, null> source
Returns an already resolved promise.
Params:
Name | Type | Attribute | Description |
response | * | The object to send to the |
Example:
EgoJSUtils.rejectedPromise('hello world').then((message) => {
// It will log 'hello world'
console.log(message);
});