UNPKG

@mnrendra/read-stacked-file

Version:

Read a file based on the stack trace from any subdirectory in your project.

1 lines 2.74 kB
{"version":3,"file":"index.d.ts","sources":["../src/types/Options.ts","../src/libs/async/main.ts","../src/libs/sync/main.ts"],"sourcesContent":["/**\n * The Options interface for `readStackedFile` and `readStackedFileSync`.\n *\n * @see https://github.com/mnrendra/read-stacked-file#readme\n */\ninterface Options {\n /**\n * A caller function to serve as the stack-trace target.\n *\n * @see https://github.com/mnrendra/read-stacked-file#readme\n */\n caller?: (...args: any) => any\n\n /**\n * The `Error.stackTraceLimit` property specifies the number of stack frames\n * to be collected by a stack trace.\n *\n * @default 10\n *\n * @see https://github.com/mnrendra/read-stacked-file#readme\n */\n stackTraceLimit?: number\n}\n\nexport default Options\n","import type { Options } from '../../types'\n\nimport { initPath, movePath, validateData } from '../../utils'\n\nimport read from './read'\n\n/**\n * Read the stack-trace file asynchronously.\n *\n * @param {string} targetFile - The target file to be obtained.\n * @param {Options} [options] - The optional params.\n *\n * @returns {Promise<string>} Obtained value.\n *\n * @see https://github.com/mnrendra/read-stacked-file#readme\n */\nconst main = async (\n targetFile: string,\n {\n caller,\n stackTraceLimit = 10\n }: Options = {}\n): Promise<string> => {\n let path = initPath(targetFile, caller ?? main, stackTraceLimit)\n\n let data = await read(path)\n\n while (typeof data !== 'string') {\n path = movePath(path, '..')\n\n data = await read(path)\n\n validateData(targetFile, path, data)\n }\n\n return data\n}\n\nexport default main\n","import type { Options } from '../../types'\n\nimport { initPath, movePath, validateData } from '../../utils'\n\nimport read from './read'\n\n/**\n * Read the stack-trace file synchronously.\n *\n * @param {string} targetFile - The target file to be obtained.\n * @param {Options} [options] - The optional params.\n *\n * @returns {string} Obtained value.\n *\n * @see https://github.com/mnrendra/read-stacked-file#readme\n */\nconst main = (\n targetFile: string,\n {\n caller,\n stackTraceLimit = 10\n }: Options = {}\n): string => {\n let path = initPath(targetFile, caller ?? main, stackTraceLimit)\n\n let data = read(path)\n\n while (typeof data !== 'string') {\n path = movePath(path, '..')\n\n data = read(path)\n\n validateData(targetFile, path, data)\n }\n\n return data\n}\n\nexport default main\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;"}