@alwatr/package-tracer
Version:
Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.
8 lines (7 loc) • 3.16 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/main.ts"],
"sourcesContent": ["/**\n * A module for tracking package information.\n * This module is useful for keeping track of loaded packages and their versions.\n * It does not prevent the same package from being added multiple times!\n * For that, you can use the `@alwatr/dedupe` package.\n *\n * @example\n * ```typescript\n * import { packageTracer } from './package-tracer';\n *\n * packageTracer.add('express', '4.18.2');\n * packageTracer.add('lodash', '4.17.21');\n *\n * if (packageTracer.has('express')) {\n * const versions = packageTracer.get('express');\n * console.log('Express versions:', versions);\n * }\n * ```\n */\nexport const packageTracer = {\n /**\n * A dictionary storing package names and their corresponding versions.\n */\n list: {} as Readonly<DictionaryOpt<readonly string[]>>,\n\n /**\n * Adds a package and its version to the tracker.\n * It does not prevent the same package from being added multiple times!\n * For that, you can use the `@alwatr/dedupe` package.\n *\n * @param packageName - The name of the package.\n * @param version - The version of the package.\n *\n * @example\n * ```typescript\n * packageTracer.add(__package_name__, __package_version__);\n * ```\n */\n add(packageName: string, version: string): void {\n (this.list[packageName] as string[]) ??= [];\n (this.list[packageName] as string[]).push(version);\n },\n\n /**\n * Checks if a package exists in the tracker.\n *\n * @param packageName - The name of the package.\n * @returns `true` if the package exists, `false` otherwise.\n *\n * @example\n * ```typescript\n * if (packageTracer.has('axios')) {\n * console.log('Axios is tracked!');\n * }\n * ```\n */\n has(packageName: string): boolean {\n const exist = Object.prototype.hasOwnProperty.call(this.list, packageName);\n return exist;\n },\n\n /**\n * Retrieves the versions of a package.\n *\n * @param packageName - The name of the package.\n * @returns An array of versions or `undefined` if the package doesn't exist.\n *\n * @example\n * ```typescript\n * const reactVersions = packageTracer.get('react');\n * if (reactVersions) {\n * console.log('React versions:', reactVersions);\n * }\n * ```\n */\n get(packageName: string): readonly string[] | undefined {\n return this.list[packageName];\n },\n} as const;\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBO,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAI3B,MAAM,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeP,IAAI,aAAqB,SAAuB;AAC9C,IAAC,KAAK,KAAK,WAAW,MAAmB,CAAC;AAC1C,IAAC,KAAK,KAAK,WAAW,EAAe,KAAK,OAAO;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAI,aAA8B;AAChC,UAAM,QAAQ,OAAO,UAAU,eAAe,KAAK,KAAK,MAAM,WAAW;AACzE,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,IAAI,aAAoD;AACtD,WAAO,KAAK,KAAK,WAAW;AAAA,EAC9B;AACF;AAEA,aAAc,eAAc,IAAI,0BAAkB,QAAmB;",
"names": []
}