/ student-intifada / node_modules / @npmcli / fs /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]lib/a year ago -  
[TXT]LICENSE.mda year ago798  
[TXT]README.mda year ago2.5K595aea1 more query options + view options [كارل مبارك]
[   ]package.jsona year ago1.2Kafd0ccc remove unused [كارل مبارك]
README.md

@npmcli/fs

polyfills, and extensions, of the core fs module.

Features

fs.withTempDir(root, fn, options) -> Promise

Parameters

Usage

The withTempDir function creates a temporary directory, runs the provided function (fn), then removes the temporary directory and resolves or rejects based on the result of fn.

const fs = require('@npmcli/fs')
const os = require('os')

// this function will be called with the full path to the temporary directory
// it is called with `await` behind the scenes, so can be async if desired.
const myFunction = async (tempPath) => {
  return 'done!'
}

const main = async () => {
  const result = await fs.withTempDir(os.tmpdir(), myFunction)
  // result === 'done!'
}

main()

fs.readdirScoped(root) -> Promise

Parameters

Usage

Like fs.readdir but handling @org/module dirs as if they were a single entry.

const { readdirScoped } = require('@npmcli/fs')
const entries = await readdirScoped('node_modules')
// entries will be something like: ['a', '@org/foo', '@org/bar']

fs.moveFile(source, dest, options) -> Promise

A fork of move-file with support for Common JS.

Highlights

Parameters

Usage

The built-in fs.rename() is just a JavaScript wrapper for the C rename(2) function, which doesn't support moving files across partitions or devices. This module is what you would have expected fs.rename() to be.

const { moveFile } = require('@npmcli/fs');

(async () => {
    await moveFile('source/unicorn.png', 'destination/unicorn.png');
    console.log('The file has been moved');
})();
Apache/2.4.38 (Debian) Server at www.karls.computer Port 80