Skip to content

About

Tool libraries for the JavaScript runtime

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

@cc-heart/utils-service logo

@cc-heart/utils-service

☁️ A collection of tools for the Node.js runtime — fs, path, package & validation helpers

npm version npm downloads license

📖 Docs

The utils family · core: @cc-heart/utils · Node.js runtime: @cc-heart/utils-service · browser: @cc-heart/utils-client

Features

  • 📁 fs — rm, cpFile, validateFilePathOrCreateMkdir
  • 🛤️ path — cwdJoin, findFilePath, findPackagePath, resolveCurrentPath
  • 📦 pkg — getPackage, getPackageManager
  • ✅ valid — isFile, isDirectory
  • 🌳 ESM + CJS dual builds with full TypeScript types

Install

npm install @cc-heart/utils-service
# or
pnpm add @cc-heart/utils-service

Usage

Find files / packages upwards

import { 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')

Read package.json & detect package manager

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' ...

File system helpers

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 exists

Path & validation

import { cwdJoin, isFile, isDirectory } from '@cc-heart/utils-service'

const outDir = cwdJoin('dist', 'esm')

if (await isFile(outDir)) {
  // ...
}
if (await isDirectory(outDir)) {
  // ...
}

LICENSE

@cc-heart/utils-service is licensed under the MIT License.

About

Tool libraries for the JavaScript runtime

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages