UNPKG

r19

Version:

Simple remote procedure calls in TypeScript

29 lines (28 loc) 946 B
const isPlainObject = (value) => { if (typeof value !== "object" || value === null) { return false; } const prototype = Object.getPrototypeOf(value); return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); }; const replaceLeaves = async (input, replacer) => { if (Array.isArray(input)) { const preparedProcedureArgs = []; for (let i = 0; i < input.length; i++) { preparedProcedureArgs[i] = await replaceLeaves(input[i], replacer); } return preparedProcedureArgs; } if (isPlainObject(input)) { const preparedProcedureArgs = {}; for (const key in input) { preparedProcedureArgs[key] = await replaceLeaves(input[key], replacer); } return preparedProcedureArgs; } return await replacer(input); }; export { replaceLeaves }; //# sourceMappingURL=replaceLeaves.js.map