☁️ A collection of tools for the Node.js runtime — fs, path, package & validation helpers
The utils family · core:
@cc-heart/utils· Node.js runtime:@cc-heart/utils-service· browser:@cc-heart/utils-client
- 📁 fs —
rm,cpFile,validateFilePathOrCreateMkdir - 🛤️ path —
cwdJoin,findFilePath,findPackagePath,resolveCurrentPath - 📦 pkg —
getPackage,getPackageManager - ✅ valid —
isFile,isDirectory - 🌳 ESM + CJS dual builds with full TypeScript types
npm install @cc-heart/utils-service
# or
pnpm add @cc-heart/utils-serviceimport { findFilePath, findPackagePath } from '@cc-heart/utils-service'
// Find the nearest package.json from a directory upwards
const pkgPath = await findPackagePath(process.cwd())
// Find any file upwards
const configPath = await findFilePath(process.cwd(), '.eslintrc.js')import { getPackage, getPackageManager } from '@cc-heart/utils-service'
interface Pkg {
name: string
version: string
}
const pkg = await getPackage<Pkg>() // nearest package.json
const pm = getPackageManager() // 'npm' | 'pnpm' | 'yarn' ...import { rm, cpFile, validateFilePathOrCreateMkdir } from '@cc-heart/utils-service'
await rm('./dist') // recursive remove, safe when missing
await cpFile('./a.txt', './backup/a.txt')
await validateFilePathOrCreateMkdir('./logs/app.log') // ensure parent dir existsimport { cwdJoin, isFile, isDirectory } from '@cc-heart/utils-service'
const outDir = cwdJoin('dist', 'esm')
if (await isFile(outDir)) {
// ...
}
if (await isDirectory(outDir)) {
// ...
}@cc-heart/utils-service is licensed under the MIT License.
