npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@node-kit/extra.fs

v3.2.0

Published

Some shared extra utilities for nodejs build-in fs modules

Downloads

20,264

Readme

@node-kit/extra.fs

Some shared extra utilities for nodejs build-in fs modules

NPM version Codacy Badge Test coverage npm download License

Sonar

Install

# use pnpm
$ pnpm install -D @node-kit/extra.fs

# use yarn
$ yarn add -D @node-kit/extra.fs

# use npm
$ npm install -D @node-kit/extra.fs

Usage

use import

import { cp } from '@node-kit/extra.fs'

cp()

use require

const { cp } = require('@node-kit/extra.fs')

cp()

API reference

1. cp & cpSync

copy files to new path

  • Usage: cp(path, target[, options]) & cpSync(path, target[, options])
  • Parameters:

| Param | Description | Type | Optional value | Required | Default value | | ------- | ------------ | ------------------------ | -------------- | -------- | ------------- | | path | from path | PathLike \| PathLike[] | - | true | - | | target | target path | PathLike | - | true | - | | options | copy options | CpOptions | - | false | {} |

  • Types:
interface CpOptions extends RmDirOptions {
  force?: boolean
  silent?: boolean
}

declare function cp(
  paths: PathLike | PathLike[],
  target: PathLike,
  options: CpOptions = { silent: true, force: true }
): Promise<void>

declare function cpSync(
  paths: PathLike | PathLike[],
  target: PathLike,
  options: CpOptions = { silent: true, force: true }
): void
  • Demos:
  1. copy ./a to ./b
import { cp, cpSync } from '@node-kit/extra.fs'

cp('./a', './b').then(() => {
  console.log('copy done')
})
// or
cpSync('./a', './b')
  1. copy ./a and ./b to ./c
import { cp, cpSync } from '@node-kit/extra.fs'

cp(['./a', './b'], './c').then(() => {
  console.log('copy done')
})
// or
cpSync(['./a', './b'], './c')

2. rm & rmSync

remove files

  • Usage: rm(path[, options]) & rmSync(path[, options])
  • Parameters:

| Param | Description | Type | Optional value | Required | Default value | | ------- | -------------- | ------------------------ | -------------- | -------- | ------------- | | path | from path | PathLike \| PathLike[] | - | true | - | | options | remove options | RmOptions | - | false | {} |

  • Types:
interface RmOptions extends RmDirOptions {
  force?: boolean
  silent?: boolean
}

declare function rm(
  paths: PathLike | PathLike[],
  options: RmOptions = { silent: true, force: true }
): Promise<void>

declare function rmSync(
  paths: PathLike | PathLike[],
  options: RmOptions = { silent: true, force: true }
): void
  • Demos:
  1. remove ./a
import { rm, rmSync } from '@node-kit/extra.fs'

rm('./a', './b').then(() => {
  console.log('remove done')
})
// or
rmSync('./a', './b')
  1. remove ./a and ./b
import { rm, rmSync } from '@node-kit/extra.fs'

rm(['./a', './b']).then(() => {
  console.log('remove done')
})
// or
rmSync(['./a', './b'])

3. mv & mvSync

move files to new path

  • Usage: mv(path, target[, options]) & mvSync(path, target[, options])
  • Parameters:

| Param | Description | Type | Optional value | Required | Default value | | ------- | ------------ | ------------------------ | -------------- | -------- | ------------- | | path | from path | PathLike \| PathLike[] | - | true | - | | target | target path | PathLike | - | true | - | | options | move options | MvOptions | - | false | {} |

  • Types:
interface MvOptions extends RmDirOptions {
  force?: boolean
  boolean?: boolean
}

declare function mv(
  paths: PathLike | PathLike[],
  target: PathLike,
  options: MvOptions = { silent: true, force: true }
): Promise<void>

declare function mvSync(
  paths: PathLike | PathLike[],
  target: PathLike,
  options: MvOptions = { silent: true, force: true }
): void
  • Demos:
  1. move ./a to ./b
import { mv, mvSync } from '@node-kit/extra.fs'

mv('./a', './b').then(() => {
  console.log('move done')
})
// or
mvSync('./a', './b')
  1. move ./a and ./b to ./c
import { mv, mvSync } from '@node-kit/extra.fs'

mv(['./a', './b'], './c').then(() => {
  console.log('move done')
})
// or
mvSync(['./a', './b'], './c')

4. readJSON & readJSONSync

read json file

  • Usage: readJSON(path[, options]) & readJSONSync(path[, options])
  • Parameters:

| Param | Description | Type | Optional value | Required | Default value | | ------- | ----------------- | ---------------------------------------- | -------------- | -------- | ------------- | | path | json path | PathLike | - | true | - | | options | read file options | ReadJSONOptions \| ReadJSONSyncOptions | - | false | null |

  • Types:
type ReadJSONOptions = Parameters<typeof promises.readFile>[1]

type ReadJSONSyncOptions = Parameters<typeof promises.readFileSync>[1]

declare function readJSON(
  ...args: Parameters<typeof promises.readFile>
): Promise<Record<string, unknown> | null>

declare function readJSONSync(
  ...args: Parameters<typeof readFileSync>
): Record<string, unknown> | null
  • Demos:
  1. read ./a.json
import { readJSON, readJSONSync } from '@node-kit/extra.fs'

readJSON('./a.json').then(data => {
  console.log(data)
})
// or
const data = readJSONSync('./a.json')

5. writeJSON & writeJSONSync

write json to file

  • Usage: writeJSON(path, data[, options]) & writeJSONSync(path, data[, options])
  • Parameters:

| Param | Description | Type | Optional value | Required | Default value | | ------- | ------------------ | ------------------------------------ | -------------- | -------- | ------------- | | path | json path | PathLike | - | true | - | | data | json data | WriteJSONData \| WriteJSONSyncData | - | true | - | | options | write file options | WriteFileOptions | - | false | null |

  • Types:
type WriteJSONData = Record<string, unknown> | Parameters<typeof promises.writeFile>[1]

type WriteJSONSyncData = Record<string, unknown> | Parameters<typeof promises.writeFileSync>[1]

declare function writeJSON(
  file: Parameters<typeof promises.writeFile>[0],
  data: Record<string, unknown> | Parameters<typeof promises.writeFile>[1],
  options?: WriteFileOptions
): Promise<void>

declare function writeJSONSync(
  file: PathOrFileDescriptor,
  data: Record<string, unknown> | Parameters<typeof writeFileSync>[1],
  options?: WriteFileOptions
): void
  • Demos:
  1. write data to ./a.json
import { writeJSON, writeJSONSync } from '@node-kit/extra.fs'

writeJSON('./a.json', { name: 'saqqdy' }).then(data => {
  console.log(data)
})
// or
const data = writeJSONSync('./a.json', { name: 'saqqdy' })

6. getRealPath & getRealPathSync

return the canonicalized absolute pathname

  • Usage: getRealPath(path) & getRealPathSync(path)
  • Parameters:

| Param | Description | Type | Optional value | Required | Default value | | ----- | ----------- | ---------- | -------------- | -------- | ------------- | | path | simple path | PathLike | - | true | - |

  • Types:
declare function getRealPath(path: string): Promise<string>

declare function getRealPathSync(path: string): string
  • Demos:
  1. simple use
import { getRealPath, getRealPathSync } from '@node-kit/extra.fs'

getRealPath('./a.json').then(data => {
  console.log(data)
})
// or
const data = getRealPathSync('./a.json')

Issues & Support

Please open an issue here.

License

MIT