
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@eljs/utils
Advanced tools
Collection of nodejs utility.
$ pnpm add @eljs/utils
// or
$ yarn add @eljs/utils
// or
$ npm i @eljs/utils -S
import utils from '@eljs/utils'
readFile(file: string, encoding?: BufferEncoding): Promise<string>Read a single file content asynchronously.
readFileSync(file: string, encoding?: BufferEncoding): stringRead a single file content synchronously.
readJson<T extends object>(file: string): Promise<T>Read a single json file asynchronously.
readJsonSync<T extends object>(file: string): TRead a single json file synchronously.
writeFile(file: string, content: string, encoding?: BufferEncoding): Promise<void>Write content to a single file asynchronously.
writeFileSync(file: string, content: string, encoding?: BufferEncoding): voidWrite content to a single file synchronously.
safeWriteFile(file: string, content: string, encoding?: BufferEncoding): Promise<void>Safe write content to a single file asynchronously.
safeWriteFileSync(file: string, content: string, encoding?: BufferEncoding): voidSafe write content to a single file synchronously.
writeJsonFile(file: string, content: string): Promise<void>Write json to a single file asynchronously.
writeJsonFileSync(file: string, content: string): voidWrite json to a single file synchronously.
safeWriteJson(file: string, content: string): Promise<void>Safe write json to a single file asynchronously.
safeWriteJsonSync(file: string, content: string): voidSafe write json to a single file synchronously.
copyFile(from: string, to: string, options?: CopyFileOptions): Promise<void>Copy a file asynchronously.
copyFileSync(from: string, to: string, options?: CopyFileOptions): voidCopy a file synchronously.
copyTpl(from: string, to: string, data: Record<string, any>, options?: CopyFileOptions): Promise<void>Copy a template asynchronously.
copyTplSync(from: string, to: string, data: Record<string, any>, options?: CopyFileOptions): voidCopy 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): voidCopy a directory synchronously.
move(from: string, to: string, overwrite?: boolean): Promise<void>Move a directory or file asynchronously.
moveSync(from: string, to: string, overwrite?: boolean): voidMove a directory or file synchronously.
remove(path: string): Promise<boolean>Remove directory or file asynchronously.
removeSync(path: string): booleanRemove directory or file synchronously.
mkdir(path: string, mode?: number | string): Promise<string | void | undefined>Create a directory asynchronously.
mkdirSync(path: string, mode?: number | string): string | void | undefinedCreate a directory synchronously.
tmpdir(random?: boolean): Promise<string>tmpdir(dirname: string, random?: boolean): Promise<string>Create a temporary directory asynchronously.
tmpdirSync(random?: boolean): stringtmpdirSync(dirname: string, random?: boolean): stringCreate a temporary directory synchronously.
isFile(file: string): Promise<Boolean>Whether the path is file asynchronously.
isFileSync(file: string): BooleanWhether the path is file synchronously.
isDirectory(path: string): Promise<Boolean>Whether the path is directory asynchronously.
isDirectorySync(path: string): BooleanWhether the path is directory synchronously.
isSymlink(link: string): Promise<Boolean>Whether the file is symlink asynchronously.
isSymlinkSync(link: string): BooleanWhether the file is symlink synchronously.
isPathExists(file: string): Promise<Boolean>Whether the path is exist asynchronously.
isPathExistsSync(file: string): BooleanWhether the path is exist synchronously.
loadJs<T>(path: string): Promise<T>Load js file asynchronously.
loadJsSync<T>(path: string): TLoad js file synchronously.
loadTs<T>(path: string): Promise<T>Load ts file asynchronously.
loadTsSync<T>(path: string): TLoad ts file synchronously.
loadYaml<T>(path: string): Promise<T>Load yaml file asynchronously.
loadYamlSync<T>(path: string): TLoad yaml file synchronously.
renderTemplate(template: string, data: Record<string, unknown>, options?: RenderTemplateOptions): stringRender template file.
logger.log(message: string, tag?: string): voidlogger.event(message: string): voidlogger.info(message: string): voidlogger.warn(message: string): voidlogger.error(message: string): voidlogger.fatal(message: string): voidlogger.wait(message: string): voidlogger.ready(message: string): voidlogger.printErrorAndExit(message: string): voidlogger.step(name: string): (message: string) => voidlogger.step(name: string, message: string): voidLogger in different level。
logger.clear(message: string): voidClear the stdout.
parseCommand(command: string): string[]Parse string command to arguments.
run(command: string, options?: RunCommandOptions): ExecaChildProcessrun(command: string, args: string[], options?: RunCommandOptions): ExecaChildProcessrunCommand(command: string, options?: RunCommandOptions): ExecaChildProcessRun shell command.
getExecutableCommand(target: string, dirs?: string[]): Promise<string | null>Find executable command.
normalizeArgs(args?: string | string[]): string[]Normalize the command arguments.
getPid(command: string): Promise<number | null>Get the process id.
sudo(options?: SudoOptions): Promise<void>sudo(args: string[], options?: SudoOptions): Promise<void>Execute commands in sudo mode.
downloadGitRepository(url: string, options?: DownloadGitRepositoryOptions): Promise<string>Download the git repository.
hasGit(): Promise<boolean>Whether the git exist globally.
hasProjectGit(cwd: string): Promise<boolean>Whether the git exist project.
isGitClean(options?: RunCommandOptions): Promise<boolean>Whether the git working tree is clean.
isGitBehindRemote(options?: RunCommandOptions): Promise<boolean>Whether the git is behind remote.
isGitAheadRemote(options?: RunCommandOptions): Promise<boolean>Whether the git is ahead remote.
getGitUrl(cwd: string, exact?: boolean): Promise<string>Get the git url asynchronously.
getGitUrlSync(cwd: string, exact?: boolean): stringGet the git url synchronously.
getGitBranch(options?: RunCommandOptions): Promise<string>Get the git branch.
getGitUpstreamBranch(options?: RunCommandOptions): Promise<string | null>Get the git upstream branch.
getGitCommitSha(options?: RunCommandOptions): Promise<string>getGitCommitSha(short: boolean, options?: RunCommandOptions): Promise<string>Get the git commit sha.
getGitLatestTag(options?: RunCommandOptions): Promise<string>getGitLatestTag(match: string, options?: RunCommandOptions): Promise<string>getGitLatestTag(match: string, args: string[], options?: RunCommandOptions): Promise<string>Get the git latest tag.
gitUrlAnalysis(url: string): GitRemoteRepository | nullAnalysis the git url to git remote repository.
getGitRepository(dir: string, exact?: boolean): Promise<GitRepository | null>Get the git repository asynchronously.
getGitRepositorySync(dir: string, exact?: boolean): GitRepository | nullGet the git repository synchronously.
getGitUser(): Promise<GitUser>Get the git user asynchronously.
getGitUserSync(): GitUserGet the git user synchronously.
getProjectGitDir(dir: string): Promise<string | undefined>Get the project git dir asynchronously.
getProjectGitDirSync(dir: string): string | undefinedGet the project git dir synchronously.
gitCommit(message: string, options?: RunCommandOptions): Promise<void>gitCommit(message: string, args: string[], options?: RunCommandOptions): Promise<void>Git commit message.
gitPush(options?: RunCommandOptions): Promise<void>gitPush(args: string[], options?: RunCommandOptions): Promise<void>Git push to remote.
gitTag(tagName: string, options?: RunCommandOptions): Promise<void>gitTag(tagName: string, args: string[], options?: RunCommandOptions): Promise<void>Git tag.
downloadNpmTarball(url: string, options?: DownloadOptions): Promise<string>downloadNpmTarball(url: string, dest: string, options?: DownloadOptions): Promise<string>Download the npm tarball.
installDeps(options?: InstallDepsOptions): Promise<void>installDeps(packageManager: PackageManager, options?: InstallDepsOptions): Promise<void>Install dependencies.
getNpmRegistry(options?: RunCommandOptions): Promise<string>Get the npm registry.
getNpmUser(options?: RunCommandOptions): Promise<string>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.
getNpmPrefix(): Promise<string>Get the npm prefix.
pkgNameAnalysis(name: string): ResolvedPkgNameAnalysis the package name.
getPackageManager(cwd?: string): Promise<PackageManager>Get the package manager.
deepMerge<T1, T2>(a: Partial<T1>, b: Partial<T2>): T1 & T2deepMerge<T1, T2, T3>(a: Partial<T1>, b: Partial<T2>, b: Partial<T3>): T1 & T2 & T3deepMerge<T1, T2, T3, T4>(a: Partial<T1>, b: Partial<T2>, c: Partial<T3>, d: Partial<T4>): T1 & T2 & T3 & T4deepMerge<T1, T2, T3, T4, T5>(a: Partial<T1>, b: Partial<T2>, c: Partial<T3>, d: Partial<T4>, e: Partial<T5>): T1 & T2 & T3 & T4 & T5deepMerge<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 & T6Deep merge objects.
winPath(path: string): stringResolve windows path.
getWorkspaceRoot(cwd: string): Promise<string>Get the workspace root.
getWorkspaces(cwd: string, relative = false): Promise<string[]>Get the project workspaces.
getPnpmWorkspaceRoot(cwd: string): Promise<string>Get the workspace root of pnpm.
getYarnWorkspaceRoot(cwd: string): Promise<string>Get the workspace root of yarn.
getLernaWorkspaceRoot(cwd: string): Promise<string>Get the workspace root of lerna.
getNpmWorkspaceRoot(cwd: string): Promise<string>Get the workspace root of npm.
getBunWorkspaceRoot(cwd: string): Promise<string>Get the workspace root of bun.
tryPaths(paths: string[]): Promise<string | undefined>Get the existing path asynchronously.
tryPathsSync(paths: string[]): Promise<string | undefined>Get the existing path synchronously.
extractCallDir(stack?: number): stringExtract the directory where the code is executed.
new Deferred<T>(): DeferredCreate a deferred.
deferred.promise: PromiseWaiting promise.
deferred.resolve: (value: T | PromiseLike<T>) => voidResolve the promise.
deferred.reject: (err: unknown) => voidReject the promise.
retry<T>(fn: () => Promise<T>, retries?: number, delay?: number): Promise<T>Retrying a task.
retryWithValue<T>(fn: () => MaybePromiseFunction<T>, retries?: number, delay?: number): Promise<T>Retrying a task until value is not null.
sleep(ms: number): Promise<void>Sleep for specified milliseconds.
timeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T> Throw error when timeout.
camelCase(str: string): stringConvert to camelCase.
pascalCase(str: string): stringConvert to pascalCase.
kebabCase(str: string): stringConvert to kebabCase.
stripBlankLines(str: string): stringStrip the blank lines.
isPromise(target: unknown): booleanWhether the target is promise.
isGenerator(target: unknown): booleanWhether the target is generator function.
isAsyncFunction(target: unknown): booleanWhether the target is async function.
isESModule(target: unknown): booleanWhether the target is es module.
FAQs
Collection of nodejs utility.
The npm package @eljs/utils receives a total of 135 weekly downloads. As such, @eljs/utils popularity was classified as not popular.
We found that @eljs/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.