type Fetch = typeof fetch export const resolveFetch = (customFetch?: Fetch): Fetch => { if (customFetch) { return (...args) => customFetch(...args) } return (...args) => fetch(...args) } export const resolveResponse = (): typeof Response => { return Response } export const recursiveToCamel = (item: Record): unknown => { if (Array.isArray(item)) { return item.map((el) => recursiveToCamel(el)) } else if (typeof item === 'function' || item !== Object(item)) { return item } const result: Record = {} Object.entries(item).forEach(([key, value]) => { const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, '')) result[newKey] = recursiveToCamel(value) }) return result } /** * Determine if input is a plain object * An object is plain if it's created by either {}, new Object(), or Object.create(null) * source: https://github.com/sindresorhus/is-plain-obj */ export const isPlainObject = (value: object): boolean => { 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) ) }