import { sort as timsort } from 'timsort' ; import * as semver from 'semver' ; /**
 * Callback used by  LegacyAdapters .
 *  public export type LegacyCallback < TResult , TError > = ( error : TError | null | undefined , result : TResult ) => void ; public export class LegacyAdapters { private static _useTimsort : boolean | undefined = undefined ; /**
     * This function wraps a function with a callback in a promise.
     */ public static convertCallbackToPromise < TResult , TError > ( fn ) ; public static convertCallbackToPromise < TResult , TError , TArg1 > ( fn , arg1 ) ; public static convertCallbackToPromise < TResult , TError , TArg1 , TArg2 > ( fn , arg1 , arg2 ) ; public static convertCallbackToPromise < TResult , TError , TArg1 , TArg2 , TArg3 > ( fn , arg1 , arg2 , arg3 ) ; public static convertCallbackToPromise < TResult , TError , TArg1 , TArg2 , TArg3 , TArg4 > ( fn , arg1 , arg2 , arg3 , arg4 ) ; public static convertCallbackToPromise < TResult , TError , TArg1 , TArg2 , TArg3 , TArg4 > ( fn , arg1 ? , arg2 ? , arg3 ? , arg4 ? ) { return new Promise ( ( resolve , reject ) => { const cb = ( error , result ) => { if ( error ) { reject ( LegacyAdapters . scrubError ( error ) ) ; } else { resolve ( result ) ; } } ; try { if ( arg1 !== undefined && arg2 !== undefined && arg3 !== undefined && arg4 !== undefined ) { fn ( arg1 , arg2 , arg3 , arg4 , cb ) ; } else if ( arg1 !== undefined && arg2 !== undefined && arg3 !== undefined ) { fn ( arg1 , arg2 , arg3 , cb ) ; } else if ( arg1 !== undefined && arg2 !== undefined ) { fn ( arg1 , arg2 , cb ) ; } else if ( arg1 !== undefined ) { fn ( arg1 , cb ) ; } else { fn ( cb ) ; } } catch ( e ) { reject ( e as Error ) ; } } ) ; } /**
     * Normalizes an object into an `Error` object.
     */ public static scrubError ( error ) { if ( error instanceof Error ) { return error ; } else if ( typeof error === 'string' ) { return new Error ( error ) ; } else { const errorObject = new Error ( 'An error occurred.' ) ; ( errorObject as any ) . errorData = error ; return errorObject ; } } remarks public static sortStable < T > ( array , compare ? ) { if ( LegacyAdapters . _useTimsort === undefined ) { LegacyAdapters . _useTimsort = semver . major ( process . versions . node ) < 11 ; } if ( LegacyAdapters . _useTimsort ) { timsort ( array , compare ) ; } else { Array . prototype . sort . call ( array , compare ) ; } } }