import Json2json, { Template, Json2jsonOptions, FormattingFunction } from './Json2json'; type AnyFunction = (...args: any[]) => any; type Json2jsonReturnType = U extends string ? // if include [], then it's array U extends `${string}[]${string}` ? any[] : any : U extends FormattingFunction ? ReturnType : // only have $path, $formatting, $disable and $default {} extends { [K in Exclude]: any; } ? // has $formatting, use $formatting type U extends { $path: string; $formatting: FormattingFunction; } ? U['$path'] extends `${string}[]${string}` ? ReturnType[] : ReturnType : U extends { $formatting: FormattingFunction; } ? ReturnType : // don't have $formatting, try get $default type U extends { $default: infer D; } ? D extends AnyFunction ? ReturnType : D : any : // have other keys U extends { $path: string; } ? U['$path'] extends `${string}[]${string}` ? { [K in Exclude]: Json2jsonReturnType; }[] : { [K in Exclude]: Json2jsonReturnType; } : { [K in Exclude]: Json2jsonReturnType; }; export default function json2json( json: T, template: U, options: Json2jsonOptions = {}, ): Json2jsonReturnType { const json2jsonInstance = new Json2json(template, options); return json2jsonInstance.transform(json); } export { Template, Json2jsonOptions };