@js-toolkit/config-utils
v1.0.1
Published
Shared utilities for project configuration: extensions, paths, dependency detection
Downloads
370
Readme
@js-toolkit/config-utils
Shared utilities for project configuration: file extensions, dependency detection, and path resolution.
Install
pnpm add @js-toolkit/config-utilsExports
extensions
Module extension lists and glob helpers.
import {
moduleExtensions,
getFilesGlob,
getTSExtensions,
getJSExtensions,
getSXExtensions,
getTSXExtensions,
getNonSXExtensions,
} from '@js-toolkit/config-utils/extensions';
getTSExtensions(); // ['.ts', '.mts', '.cts', '.tsx', ...]
getJSExtensions(); // ['.js', '.mjs', '.cjs', '.jsx', ...]
getFilesGlob(getTSExtensions(), 'src/'); // 'src/**/*.{ts,mts,cts,tsx,...}'
getTSExtensions(true); // ['*.ts', '*.mts', '*.cts', '*.tsx', ...]getInstalledPackage
Check if a package is installed and resolvable.
import { getInstalledPackage } from '@js-toolkit/config-utils/getInstalledPackage';
const pkg = getInstalledPackage('typescript-eslint', { resolvePaths: true });
// 'typescript-eslint' if installed, undefined otherwisegetProjectDependencies
Read all dependency names from a project's package.json.
import { getProjectDependencies } from '@js-toolkit/config-utils/getProjectDependencies';
const deps = getProjectDependencies([process.cwd()]);
// Set<string> { 'react', 'typescript', ... }findPath
Find the first existing path from a list of candidates.
import { findPath } from '@js-toolkit/config-utils/findPath';
const tsconfig = findPath('tsconfig.json', [process.cwd(), '/fallback/dir']);
// Absolute path to the first found tsconfig.json, or undefineddefaultRequire
A require function created via createRequire(import.meta.url) for use in ESM modules.
import { defaultRequire } from '@js-toolkit/config-utils/defaultRequire';
const pkg = defaultRequire('some-cjs-package');License
MIT
