CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
README.md98 linesDownload Raw Back to fs
1# @npmcli/fs2 3polyfills, and extensions, of the core `fs` module.4 5## Features6 7- `fs.cp` polyfill for node < 16.7.08- `fs.withTempDir` added9- `fs.readdirScoped` added10- `fs.moveFile` added11 12## `fs.withTempDir(root, fn, options) -> Promise`13 14### Parameters15 16- `root`: the directory in which to create the temporary directory17- `fn`: a function that will be called with the path to the temporary directory18- `options`19  - `tmpPrefix`: a prefix to be used in the generated directory name20 21### Usage22 23The `withTempDir` function creates a temporary directory, runs the provided24function (`fn`), then removes the temporary directory and resolves or rejects25based on the result of `fn`.26 27```js28const fs = require('@npmcli/fs')29const os = require('os')30 31// this function will be called with the full path to the temporary directory32// it is called with `await` behind the scenes, so can be async if desired.33const myFunction = async (tempPath) => {34  return 'done!'35}36 37const main = async () => {38  const result = await fs.withTempDir(os.tmpdir(), myFunction)39  // result === 'done!'40}41 42main()43```44 45## `fs.readdirScoped(root) -> Promise`46 47### Parameters48 49- `root`: the directory to read50 51### Usage52 53Like `fs.readdir` but handling `@org/module` dirs as if they were54a single entry.55 56```javascript57const { readdirScoped } = require('@npmcli/fs')58const entries = await readdirScoped('node_modules')59// entries will be something like: ['a', '@org/foo', '@org/bar']60```61 62## `fs.moveFile(source, dest, options) -> Promise`63 64A fork of [move-file](https://github.com/sindresorhus/move-file) with65support for Common JS.66 67### Highlights68 69- Promise API.70- Supports moving a file across partitions and devices.71- Optionally prevent overwriting an existing file.72- Creates non-existent destination directories for you.73- Automatically recurses when source is a directory.74 75### Parameters76 77- `source`: File, or directory, you want to move.78- `dest`: Where you want the file or directory moved.79- `options`80  - `overwrite` (`boolean`, default: `true`): Overwrite existing destination file(s).81 82### Usage83 84The built-in85[`fs.rename()`](https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback)86is just a JavaScript wrapper for the C `rename(2)` function, which doesn't87support moving files across partitions or devices. This module is what you88would have expected `fs.rename()` to be.89 90```js91const { moveFile } = require('@npmcli/fs');92 93(async () => {94	await moveFile('source/unicorn.png', 'destination/unicorn.png');95	console.log('The file has been moved');96})();97```98 
basant307/AI_Governance_Project · CoolFace