Collection of nodejs utility.
$ pnpm add @eljs/utils
// or
$ yarn add @eljs/utils
// or
$ npm i @eljs/utils -S
import utils from '@eljs/utils'
Read a single file content asynchronously.
Read a single file content synchronously.
Read a single json file asynchronously.
Read a single json file synchronously.
Write content to a single file asynchronously.
Write content to a single file synchronously.
Safe write content to a single file asynchronously.
Safe write content to a single file synchronously.
Write json to a single file asynchronously.
Write json to a single file synchronously.
Safe write json to a single file asynchronously.
Safe write json to a single file synchronously.
Copy a file asynchronously.
Copy a file synchronously.
copyTpl(from: string, to: string, data: Record<string, any>, options?: CopyFileOptions): Promise<void>
Copy a template asynchronously.
Copy a template synchronously.
copyDirectory(from: string, to: string, data: Record<string, any>, options: CopyFileOptions): Promise<void>
Copy a directory asynchronously.
copyDirectorySync(from: string, to: string, data: Record<string, any>, options: CopyFileOptions): void
Copy a directory synchronously.
Move a directory or file asynchronously.
Move a directory or file synchronously.
Remove directory or file asynchronously.
Remove directory or file synchronously.
Create a directory asynchronously.
Create a directory synchronously.
Create a temporary directory asynchronously.
Create a temporary directory synchronously.
Whether the path is file asynchronously.
Whether the path is file synchronously.
Whether the path is directory asynchronously.
Whether the path is directory synchronously.
Whether the file is symlink asynchronously.
Whether the file is symlink synchronously.
Whether the path is exist asynchronously.
Whether the path is exist synchronously.
Load js file asynchronously.
Load js file synchronously.
Load ts file asynchronously.
Load ts file synchronously.
Load yaml file asynchronously.
Load yaml file synchronously.
renderTemplate(template: string, data: Record<string, unknown>, options?: RenderTemplateOptions): string
Render template file.
Logger in different level。
Clear the stdout.
Parse string command to arguments.
Run shell command.
Find executable command.
Normalize the command arguments.
Get the process id.
Execute commands in sudo mode.
Download the git repository.
Whether the git exist globally.
Whether the git exist project.
Whether the git working tree is clean.
Whether the git is behind remote.
Whether the git is ahead remote.
Get the git url asynchronously.
Get the git url synchronously.
Get the git branch.
Get the git upstream branch.
Get the git commit sha.
Get the git latest tag.
Analysis the git url to git remote repository.
Get the git repository asynchronously.
Get the git repository synchronously.
Get the git user asynchronously.
Get the git user synchronously.
Get the project git dir asynchronously.
Get the project git dir synchronously.
Git commit message.
Git push to remote.
Git tag.
Download the npm tarball.
Install dependencies.
Get the npm registry.
Get the npm user.
getNpmPackage(name: string, options?: { cwd?: string registry?: string timeout?: number }): Promise<Omit<NpmPackage, 'version'> | null>
getNpmPackage(name: string, options?: { version: string, cwd?: string registry?: string timeout?: number }): Promise<Omit<NpmPackage, 'version'> | null>
Get the npm package.
Get the npm prefix.
Analysis the package name.
Get the package manager.
deepMerge<T1, T2, T3, T4>(a: Partial<T1>, b: Partial<T2>, c: Partial<T3>, d: Partial<T4>): T1 & T2 & T3 & T4
deepMerge<T1, T2, T3, T4, T5>(a: Partial<T1>, b: Partial<T2>, c: Partial<T3>, d: Partial<T4>, e: Partial<T5>): T1 & T2 & T3 & T4 & T5
deepMerge<T1, T2, T3, T4, T5, T6>(a: Partial<T1>, b: Partial<T2>, c: Partial<T3>, d: Partial<T4>, e: Partial<T5>, f: Partial<T6>): T1 & T2 & T3 & T4 & T5 & T6
Deep merge objects.
Resolve windows path.
Get the workspace root.
Get the project workspaces.
Get the workspace root of pnpm.
Get the workspace root of yarn.
Get the workspace root of lerna.
Get the workspace root of npm.
Get the workspace root of bun.
Get the existing path asynchronously.
Get the existing path synchronously.
Extract the directory where the code is executed.
Create a deferred.
Waiting promise.
Resolve the promise.
Reject the promise.
Retrying a task.
Retrying a task until value is not null.
Sleep for specified milliseconds.
Throw error when timeout.
Convert to camelCase.
Convert to pascalCase.
Convert to kebabCase.
Strip the blank lines.
Whether the target is promise.
Whether the target is generator function.
Whether the target is async function.
Whether the target is es module.