Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
@node-kit/extra.fs
Advanced tools
# 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
use import
import { cp } from '@node-kit/extra.fs'
cp()
use require
const { cp } = require('@node-kit/extra.fs')
cp()
copy files to new path
cp(path, target[, options])
& cpSync(path, target[, options])
Param | Description | Type | Optional value | Required | Default value |
---|---|---|---|---|---|
path | from path | PathLike | PathLike[] | - | true | - |
target | target path | PathLike | - | true | - |
options | copy options | CpOptions | - | false | {} |
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
import { cp, cpSync } from '@node-kit/extra.fs'
cp('./a', './b').then(() => {
console.log('copy done')
})
// or
cpSync('./a', './b')
import { cp, cpSync } from '@node-kit/extra.fs'
cp(['./a', './b'], './c').then(() => {
console.log('copy done')
})
// or
cpSync(['./a', './b'], './c')
remove files
rm(path[, options])
& rmSync(path[, options])
Param | Description | Type | Optional value | Required | Default value |
---|---|---|---|---|---|
path | from path | PathLike | PathLike[] | - | true | - |
options | remove options | RmOptions | - | false | {} |
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
import { rm, rmSync } from '@node-kit/extra.fs'
rm('./a', './b').then(() => {
console.log('remove done')
})
// or
rmSync('./a', './b')
import { rm, rmSync } from '@node-kit/extra.fs'
rm(['./a', './b']).then(() => {
console.log('remove done')
})
// or
rmSync(['./a', './b'])
move files to new path
mv(path, target[, options])
& mvSync(path, target[, options])
Param | Description | Type | Optional value | Required | Default value |
---|---|---|---|---|---|
path | from path | PathLike | PathLike[] | - | true | - |
target | target path | PathLike | - | true | - |
options | move options | MvOptions | - | false | {} |
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
import { mv, mvSync } from '@node-kit/extra.fs'
mv('./a', './b').then(() => {
console.log('move done')
})
// or
mvSync('./a', './b')
import { mv, mvSync } from '@node-kit/extra.fs'
mv(['./a', './b'], './c').then(() => {
console.log('move done')
})
// or
mvSync(['./a', './b'], './c')
read json file
readJSON(path[, options])
& readJSONSync(path[, options])
Param | Description | Type | Optional value | Required | Default value |
---|---|---|---|---|---|
path | json path | PathLike | - | true | - |
options | read file options | ReadJSONOptions | ReadJSONSyncOptions | - | false | null |
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
import { readJSON, readJSONSync } from '@node-kit/extra.fs'
readJSON('./a.json').then(data => {
console.log(data)
})
// or
const data = readJSONSync('./a.json')
write json to file
writeJSON(path, data[, options])
& writeJSONSync(path, data[, options])
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 |
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
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' })
return the canonicalized absolute pathname
getRealPath(path)
& getRealPathSync(path)
Param | Description | Type | Optional value | Required | Default value |
---|---|---|---|---|---|
path | simple path | PathLike | - | true | - |
declare function getRealPath(path: string): Promise<string>
declare function getRealPathSync(path: string): string
import { getRealPath, getRealPathSync } from '@node-kit/extra.fs'
getRealPath('./a.json').then(data => {
console.log(data)
})
// or
const data = getRealPathSync('./a.json')
Please open an issue here.
FAQs
Some shared extra utilities for nodejs build-in fs modules
We found that @node-kit/extra.fs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.