-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.ts
30 lines (25 loc) · 875 Bytes
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Handler, HandlerMapping, Pipeline } from './types.ts';
export function isPlainObject<T>(object: unknown): object is T {
const prototype = Object.getPrototypeOf(object);
return prototype === null || prototype.constructor === Object;
}
export const isFunction = (value: unknown) => {
return !!value &&
(Object.prototype.toString.call(value) === '[object Function]' ||
'function' === typeof value || value instanceof Function);
};
export function isPipeline(
handler: Handler | HandlerMapping | Pipeline,
): handler is Pipeline {
return Array.isArray(handler);
}
export function isHandlerMapping(
handler: Handler | HandlerMapping | Pipeline,
): handler is HandlerMapping {
return isPlainObject<HandlerMapping>(handler);
}
export function isHandler(
handler: Handler | HandlerMapping | Pipeline,
): handler is Handler {
return isFunction(handler);
}