Variable utilsConst

utils: {
    argv: {
        [key: string]: string;
    };
    arrayStartingMatch: ((a: any[], b: any[]) => boolean);
    arrayUnique: ((arr: any[]) => any[]);
    collapseObjectToArray: ((obj: Record<string, any>) => any[] | boolean);
    deepCopy: (<T>(obj: T) => T);
    ensureNoTsHeaderOrSpecFiles: ((files: string[]) => string[]);
    eventLoopDelay: ((iterations?: number) => Promise<number>);
    fileUtils: {
        createDirSafely: ((dir: string) => string);
        createFileSafely: ((file: string, data: string | ArrayBufferView, overwrite?: boolean) => string);
        createLinkfileSafely: ((filePath: string, type: string) => string);
        createSymlinkSafely: ((destination: string, source: string) => string);
        dirExists: ((dir: string) => boolean);
        fileExists: ((file: string) => boolean);
        removeLinkfileSafely: ((filePath: string) => string);
    };
    filterObjectForLogging: ((params: Record<string, any>) => Record<string, any>);
    filterResponseForLogging: ((response: Record<string, any>) => {
        [key: string]: any;
    });
    getExternalIPAddress: (() => string);
    hashMerge: ((a: Record<string, any>, b: Record<string, any>, arg?: Record<string, any>) => {
        [key: string]: any;
    });
    isPlainObject: ((o: any) => boolean);
    isRunning: ((pid: number) => boolean);
    parseCookies: ((req: {
        headers: {
            [key: string]: string | string[];
        };
    }) => object);
    parseHeadersForClientAddress: ((headers: Record<string, string | string[]>) => {
        ip: string;
        port: string | number;
    });
    parseIPv6URI: ((addr: string) => {
        host: string;
        port: number;
    });
    replaceDistWithSrc: ((f: string) => string);
    safeGlobSync: ((match: string, args?: IOptions) => string[]);
    sleep: ((time: number) => Promise<void>);
    sortGlobalMiddleware: ((globalMiddlewareList: any[], middleware: {
        [key: string]: any;
    }) => void);
    sourceRelativeLinkPath: ((linkFile: string, pluginPaths: string[]) => string | boolean);
} = ...

Utility functions for Actionhero

Type declaration

  • argv: {
        [key: string]: string;
    }
    • [key: string]: string
  • arrayStartingMatch: ((a: any[], b: any[]) => boolean)
      • (a, b): boolean
      • Compare the first n elements of an array with another, longer array

        Parameters

        • a: any[]
        • b: any[]

        Returns boolean

  • arrayUnique: ((arr: any[]) => any[])
      • (arr): any[]
      • Return only the unique values in an Array.

        Parameters

        • arr: any[]

        Returns any[]

  • collapseObjectToArray: ((obj: Record<string, any>) => any[] | boolean)
      • (obj): any[] | boolean
      • Collapses an Object with numerical keys (like arguments in a function) to an Array

        Parameters

        • obj: Record<string, any>

        Returns any[] | boolean

  • deepCopy: (<T>(obj: T) => T)
      • <T>(obj): T
      • Type Parameters

        • T

        Parameters

        • obj: T

        Returns T

  • ensureNoTsHeaderOrSpecFiles: ((files: string[]) => string[])
      • (files): string[]
      • swap out d.ts files for the JS versions when running with ts-node also filter out *.test. and *.spec. js|ts files

        Parameters

        • files: string[]

        Returns string[]

  • eventLoopDelay: ((iterations?: number) => Promise<number>)
      • (iterations?): Promise<number>
      • Returns the average delay between a tick of the node.js event loop, as measured for N calls of process.nextTick

        Parameters

        • iterations: number = 10000

        Returns Promise<number>

  • fileUtils: {
        createDirSafely: ((dir: string) => string);
        createFileSafely: ((file: string, data: string | ArrayBufferView, overwrite?: boolean) => string);
        createLinkfileSafely: ((filePath: string, type: string) => string);
        createSymlinkSafely: ((destination: string, source: string) => string);
        dirExists: ((dir: string) => boolean);
        fileExists: ((file: string) => boolean);
        removeLinkfileSafely: ((filePath: string) => string);
    }
    • createDirSafely: ((dir: string) => string)
        • (dir): string
        • Create a directory, only if it doesn't exist yet. Throws an error if the directory already exists, or encounters a filesystem problem.

          Parameters

          • dir: string

          Returns string

    • createFileSafely: ((file: string, data: string | ArrayBufferView, overwrite?: boolean) => string)
        • (file, data, overwrite?): string
        • Create a file, only if it doesn't exist yet. Throws an error if the file already exists, or encounters a filesystem problem.

          Parameters

          • file: string
          • data: string | ArrayBufferView
          • overwrite: boolean = false

          Returns string

    • createLinkfileSafely: ((filePath: string, type: string) => string)
        • (filePath, type): string
        • Create an Actionhero LinkFile, only if it doesn't exist yet. Throws an error if the file already exists, or encounters a filesystem problem.

          Parameters

          • filePath: string
          • type: string

          Returns string

    • createSymlinkSafely: ((destination: string, source: string) => string)
        • (destination, source): string
        • Create a system symbolic link. Throws an error if it encounters a filesystem problem.

          Parameters

          • destination: string
          • source: string

          Returns string

    • dirExists: ((dir: string) => boolean)
        • (dir): boolean
        • Check if a directory exists.

          Parameters

          • dir: string

          Returns boolean

    • fileExists: ((file: string) => boolean)
        • (file): boolean
        • Check if a file exists.

          Parameters

          • file: string

          Returns boolean

    • removeLinkfileSafely: ((filePath: string) => string)
        • (filePath): string
        • Remove an Actionhero LinkFile, only if it exists. Throws an error if the file does not exist, or encounters a filesystem problem.

          Parameters

          • filePath: string

          Returns string

  • filterObjectForLogging: ((params: Record<string, any>) => Record<string, any>)
      • (params): Record<string, any>
      • Prepares acton params for logging. Hides any sensitive data as defined by api.config.general.filteredParams Truncates long strings via api.config.logger.maxLogStringLength

        Parameters

        • params: Record<string, any>

        Returns Record<string, any>

  • filterResponseForLogging: ((response: Record<string, any>) => {
        [key: string]: any;
    })
      • (response): {
            [key: string]: any;
        }
      • Prepares acton response for logging. Hides any sensitive data as defined by api.config.general.filteredResponse Truncates long strings via api.config.logger.maxLogStringLength

        Parameters

        • response: Record<string, any>

        Returns {
            [key: string]: any;
        }

        • [key: string]: any
  • getExternalIPAddress: (() => string)
      • (): string
      • Returns this server's external/public IP address

        Returns string

  • hashMerge: ((a: Record<string, any>, b: Record<string, any>, arg?: Record<string, any>) => {
        [key: string]: any;
    })
      • (a, b, arg?): {
            [key: string]: any;
        }
      • Recursively merge 2 Objects together. Will resolve functions if they are present, unless the parent Object has the property _toExpand = false. Actionhero uses this internally to construct and resolve the config. Matching keys in B override A.

        Parameters

        • a: Record<string, any>
        • b: Record<string, any>
        • Optionalarg: Record<string, any>

        Returns {
            [key: string]: any;
        }

        • [key: string]: any
  • isPlainObject: ((o: any) => boolean)
      • (o): boolean
      • Is the JS Object passed in truly just an object?

        Parameters

        • o: any

        Returns boolean

  • isRunning: ((pid: number) => boolean)
      • (pid): boolean
      • Parameters

        • pid: number

        Returns boolean

  • parseCookies: ((req: {
        headers: {
            [key: string]: string | string[];
        };
    }) => object)
      • (req): object
      • Transform the cookie headers of a node HTTP req Object into a hash.

        Parameters

        • req: {
              headers: {
                  [key: string]: string | string[];
              };
          }
          • headers: {
                [key: string]: string | string[];
            }
            • [key: string]: string | string[]

        Returns object

  • parseHeadersForClientAddress: ((headers: Record<string, string | string[]>) => {
        ip: string;
        port: string | number;
    })
      • (headers): {
            ip: string;
            port: string | number;
        }
      • Return ip and port information if defined in the header

        Parameters

        • headers: Record<string, string | string[]>

        Returns {
            ip: string;
            port: string | number;
        }

        • ip: string
        • port: string | number
  • parseIPv6URI: ((addr: string) => {
        host: string;
        port: number;
    })
      • (addr): {
            host: string;
            port: number;
        }
      • Parse an IPv6 address, returning both host and port. see https://github.com/actionhero/actionhero/issues/275

        Parameters

        • addr: string

        Returns {
            host: string;
            port: number;
        }

        • host: string
        • port: number
  • replaceDistWithSrc: ((f: string) => string)
      • (f): string
      • Used by generator functions running from your dist, it replaces the path with your src Relies on api.config.general.paths

        Parameters

        • f: string

        Returns string

  • safeGlobSync: ((match: string, args?: IOptions) => string[])
      • (match, args?): string[]
      • Parameters

        • match: string
        • args: IOptions = {}

        Returns string[]

  • sleep: ((time: number) => Promise<void>)
      • (time): Promise<void>
      • Sleep with a Promise

        Parameters

        • time: number

        Returns Promise<void>

  • sortGlobalMiddleware: ((globalMiddlewareList: any[], middleware: {
        [key: string]: any;
    }) => void)
      • (globalMiddlewareList, middleware): void
      • Sorts an Array of Objects with a priority key

        Parameters

        • globalMiddlewareList: any[]
        • middleware: {
              [key: string]: any;
          }
          • [key: string]: any

        Returns void

  • sourceRelativeLinkPath: ((linkFile: string, pluginPaths: string[]) => string | boolean)
      • (linkFile, pluginPaths): string | boolean
      • Parameters

        • linkFile: string
        • pluginPaths: string[]

        Returns string | boolean