UNPKG

dino-express

Version:

DinO enabled REST framework based on express

82 lines (81 loc) 2.9 kB
/// <reference types="node" /> import { Request } from 'express'; import { Response } from './Response'; import { GenericObject } from './Types'; /** * Helper class exposes utility methods * @public */ export declare class Helper { /** * Normalize swagger path definition to express notation * @param {String} path the API path * * @public * @static */ static normalizePath(path: any): any; /** * Allows to retrieve a variable from the configuration or as environment variable, supports * both `:` and `_` notation. * @param {Environment} environment the configuration container * @param {string} key the key for the variable to retrieve * @param {any} _default the default value if the variable is nt defined. */ static getVariable(environment: any, key: any, _default: any): any; /** * Ensure that either the value or default value are returned. * @param {any} value the value to verify * @param {any} the default value to return */ static ensureValue(value: any, _default: any): any; static requestHasBody(req: Request | GenericObject): boolean; static isPayloadBeringMethod(method?: string): boolean; /** * Format the response based on the content type defined * @returns {String} */ static format(payload: any, contentType: string): any; static isAPromise(obj: any): boolean; /** * Evaluate if an obj is an instance of a type * * @param {Any} obj the object to be verified * @param {Any} type the type the object will be verified against * @returns {Boolean} true if obj is instance of type, false otherwise */ static instanceOf(obj: any, type: any): boolean; /** * Tests if the provided string is base64 * @param {string} v the string to test for base64 * @returns true if the provided string is base64 encoded, false otherwise * @public * @static */ static isBase64(v: string): boolean; /** * Decode a base64 string, decompress and parse from JSON if needed. * * @param {string} str a string to decode if base64 encoded * @returns the decoded string or the string as is * @public * @static */ static decodeFromBase64AndParse(str: string): string; /** * Normalise the response body from the received error * @param {any} response the response for the client * @returns the body response * * @private */ static buildResponseBody(response: Response, asString: boolean, asBase64: boolean): any; /** * Decompress using zlib the provided content, if the content is not compressed or * cannot be decompressed it will be returned as is. * * @param input the content to decompress * @returns the decompressed content */ static decompress(input: Buffer): string; }