- Source
Methods
(static) getResourceId(uri, path) → {String|undefined}
Return URI fragment, if Route is a resource.
Parameters:
Name | Type | Description |
---|---|---|
uri | String | Request URI. |
path | String | Route path value. |
- Source
Returns:
- Type:
- String |
undefined
Example
const result = getResourceId('/api/test/abc123', '/api/test');
// abc123
(static) isAsyncFunc(func) → {Boolean}
Check if value is an async function.
Parameters:
Name | Type | Description |
---|---|---|
func | AsyncFunction | Async function. |
- Source
Returns:
- Type:
- Boolean
Example
const result = isAsyncFunc(async function() {}));
// true
(static) isObject(Object) → {Boolean}
Check if value is an Object instance.
Parameters:
Name | Type | Description |
---|---|---|
Object | Object | to check. |
- Source
Returns:
- Type:
- Boolean
Example
const result = Utils.isObject({foo: 'bar'});
// true
(static) isPromise(obj) → {Boolean}
Check if object is (or returns) Promise.
Parameters:
Name | Type | Description |
---|---|---|
obj | Object | Promise object. |
- Source
Returns:
- Type:
- Boolean
Example
const result = isPromise(new Promise(() => {}));
// true
const result = function() {
return Promise.resolve();
};
// true
(static) isValidFunc(value) → {Boolean}
Check if valid Route/Middleware function.
Parameters:
Name | Type | Description |
---|---|---|
value | function | Route function. |
- Source
Returns:
- Type:
- Boolean
Example
const result = isValidFunc((req, res, next) => {});
// true
(static) isValidPath(value) → {Boolean}
Check if valid URI path.
Parameters:
Name | Type | Description |
---|---|---|
value | String | URI path value. |
- Source
Returns:
- Type:
- Boolean
Example
const result = isValidPath('/api/test');
// true
(static) isValidRoute(uri, path, func) → {Boolean}
Check if valid Request/Route.
Parameters:
Name | Type | Description |
---|---|---|
uri | String | Request URI. |
path | String | Route path value. |
func | function | Route function. |
- Source
Returns:
- Type:
- Boolean
Example
const result = isValidRoute('/api/test/123456', '/api/test', (req, res) => {}));
// true
(static) moduleParent() → {String}
Get executed module parent directory.
- Source
Returns:
- Type:
- String
Example
const dir = moduleParent();
// path/to/app/parent/directory
(static) promiseEvents(promises) → {Promise}
Execute events; propagate variable state.
Parameters:
Name | Type | Description |
---|---|---|
promises | Array | Array of promised events. |
- Source
Returns:
- Type:
- Promise
Example
const state = {};
const promises = [
() => Promise.resolve(a),
(b) => Promise.resolve(b),
(c) => Promise.resolve(c),
..
];
promiseEvents(promises)
.then(obj => obj)
.catch(function(err) {
});
(static) setFuncName(func, value)
Set name for a given function (inline).
Parameters:
Name | Type | Description |
---|---|---|
func | function | Route function. |
value | function | Function name. |
- Source
Example
const func = function() {};
setFuncName(func, 'test');
func.name
// test