UNPKG

stdouttojson

Version:
45 lines (43 loc) • 1.62 kB
/** * stdoutToJSON 📇 * @description a naive tool useful for outputting stdout as JSON * @notes This is a naive tool, that does a decent job of outputting a stdout string as JSON * - The use-case of a such a tool initially is for testing cli scenarios 👌 */ /** * @description matches a JSON-like shape of unknown keys and values */ type WithWildcards<T> = T & { [key: string]: WithWildcards<T>; }; /** * @description the Matcher shape matches a regex input string and expected output string, useful `String.prototype.replace` * @param {value} string a string contain a regex pattern to match * @param {edit} string */ type Matcher = { value: string | RegExp; edit: string; }; declare const OBJECT_MATCHERS: Matcher[]; declare const TRAILING_COMMAS_MATCHERS: Matcher[]; declare const BOOLEAN_MATCHERS: Matcher[]; declare const BROWSER_MATCHERS: Matcher[]; /** * matcher * @description allows more configuration options * @param {str} string * @param {matchers} array * @returns {string} */ declare function matcher(str: string, matchers?: Matcher[] | null, debug?: boolean): string; /** * stdoutToJSON * @description turns stdout into a JSON object * @param {stdout} string * @param {matchers} array * @param {debug} string * @returns {object} a JSON object of unknown type */ declare function stdoutToJSON(stdout: string, matchers?: Matcher[] | null, debug?: boolean): WithWildcards<unknown> | string; export { BOOLEAN_MATCHERS, BROWSER_MATCHERS, type Matcher, OBJECT_MATCHERS, TRAILING_COMMAS_MATCHERS, type WithWildcards, stdoutToJSON as default, matcher, stdoutToJSON };