diff --git a/src/ts/util.ts b/src/ts/util.ts new file mode 100644 index 0000000..0e88ddf --- /dev/null +++ b/src/ts/util.ts @@ -0,0 +1,14 @@ +/** + * callbackToPromise converts a callback based function to a promise based function. + * The function's only argument must be a function. + * + * @param {(Function) => void} func + * @returns {PromiseLike} + */ +export function callbackToPromise(func: (Function) => void): PromiseLike { + return new Promise((resolve) => { + func((...callbackArgs) => { + resolve(callbackArgs); + }); + }); +}