{"library":"premove","title":"Recursive File and Directory Remover","description":"premove is a lightweight, cross-platform utility for Node.js that recursively removes files and directories, functioning as a programmatic `rm -rf`. It offers both `Promise`-based asynchronous (`premove`) and synchronous (`premove/sync`) APIs. The current stable version is 4.0.0. Releases are generally infrequent but address breaking changes or add features, as seen with v3.0.0's migration to named exports and v4.0.0's consistent boolean return for non-existent paths. Key differentiators include its tiny footprint (208B-260B), explicit support for both async/await and synchronous operations, and a built-in CLI. It's an alternative to `fs.rm` (or `fs.rmdir` with `recursive` option), providing a simpler, focused API for recursive deletion with safeguards against deleting critical system paths.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install premove"],"cli":{"name":"premove","version":null}},"imports":["import { premove } from 'premove'","import { premove } from 'premove/sync'","const { premove } = require('premove')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { premove } from 'premove';\nimport { resolve, join } from 'path';\nimport { mkdir, writeFile } from 'fs/promises';\n\nasync function runExample() {\n  const baseDir = resolve(__dirname, 'temp_premove_test');\n  const targetDir = join(baseDir, 'foo', 'bar');\n  const targetFile = join(baseDir, 'hello.txt');\n\n  try {\n    // Setup: Create directories and a file for deletion\n    await mkdir(targetDir, { recursive: true });\n    await writeFile(targetFile, 'temporary content');\n    console.log(`Created test directory: ${targetDir}`);\n    console.log(`Created test file: ${targetFile}`);\n\n    // Example 1: Remove a directory recursively\n    let removedFoo = await premove(join(baseDir, 'foo'));\n    console.log(`'${join(baseDir, 'foo')}' existed and was removed: ${removedFoo}`);\n\n    // Example 2: Remove a file using cwd option\n    let removedFile = await premove('hello.txt', { cwd: baseDir });\n    console.log(`'hello.txt' in '${baseDir}' existed and was removed: ${removedFile}`);\n\n    // Example 3: Attempt to remove a non-existent path\n    let removedNonExistent = await premove(join(baseDir, 'non-existent-path'));\n    console.log(`'non-existent-path' existed and was removed: ${removedNonExistent} (expected false)`);\n\n  } catch (err) {\n    console.error('Error during premove example:', err);\n  } finally {\n    // Clean up if baseDir still exists (e.g., if an error occurred early)\n    try {\n      const { premove: premoveSync } = await import('premove/sync');\n      premoveSync(baseDir);\n      console.log(`Cleaned up base directory: ${baseDir}`);\n    } catch (cleanupErr) {\n      console.warn('Failed to clean up base directory:', cleanupErr.message);\n    }\n  }\n}\n\nrunExample();","lang":"typescript","description":"Demonstrates asynchronous recursive deletion of files and directories using `premove`, including the `cwd` option, and shows the boolean return value for existing and non-existing paths. Also includes cleanup using the sync version.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}