Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@magic/fs

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magic/fs

nodejs fs promises + goodies

  • 0.0.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
399
increased by14.99%
Maintainers
2
Weekly downloads
 
Created
Source

@magic/fs

exports all fs.promises + exists + mkdirp + rmrf + getFiles + getDirs functions.

NPM version Linux Build Status Windows Build Status Coverage Status Greenkeeper badge Known Vulnerabilities

html-docs

installation

be in a nodejs project

npm install @magic/fs

import

import fs from '@magic/fs'

const run = async () => {
  await fs.mkdirp('./test_235235/dir/to/create')
  console.log('dir created')
  await fs.rmrf('./test_235235')
  console.log('dir deleted, even though it had contents.')
}
run()

promises

promises from fs:

access
copyFile
open
opendir
rename
truncate
rmdir
mkdir
readdir
readlink
symlink
lstat
stat
link
unlink
chmod
lchmod
lchown
chown
utimes
realpath
mkdtemp
writeFile
appendFile
readFile
exists
readDir
readfile
rmDir

export overloads:

rmdir, rmDir
readfile, readFile
readdir, readDir

Additional functions:

mkdirp

same as mkdir -p on unix

await fs.mkdirp('./path/to/dir')
rmrf

same as rm -rf on unix.

will not work outside process.cwd()

await fs.rmrf('./path/to/dir')
exists

same as fs.exists, but promisified and ready for esmodules.

getDirectories

get a list of directories in a directory, recursively.

import fs from '@magic/fs'

const run = async () => {
  // first level directories
  const directories = await fs.getDirectories(process.cwd())
  console.log(directories)

  // recursive run
  const deepDirectories = await fs.getDirectories(process.cwd(), true)
  console.log(deepDirectories)

  // recursive run with specified depth, 
  // just pass a number as second argument
  const deepDirectoriesDepth2 = await fs.getDirectories(process.cwd(), 2)
  console.log(deepDirectoriesDepth2)
}
run()
getFiles

get a list of files in a directory, recursively.

import fs from '@magic/fs'

const run = async () => {
  // first level directories
  const files = await fs.getFiles(process.cwd())
  console.log(files)

  // recursive run
  const deepFiles = await fs.getFiles(process.cwd(), true)
  console.log(deepFiles)

  // recursive run with specified depth, 
  // just pass a number as second argument
  const deepDirectoriesDepth2 = await fs.getFiles(process.cwd(), 2)
  console.log(deepDirectoriesDepth2)
}
run()
getFileType

get the file type of a file, based on extension, and defaulting to "txt"

import fs from '@magic/fs'

const fileType = fs.getFileType('html.html')
console.log(fileType, fileType === 'html')

const nonFileType = fs.getFileType()
console.log(nonFileType, nonFileType === 'txt')

changelog

0.0.1

first release

0.0.2
  • bump required node version
  • update dependencies
0.0.3

better error messages

0.0.4

rmrf returns true if directory does not exist.

0.0.5

use @magic/mime-types to export contentTypes

0.0.6

bump required node version to 14.2.0

0.0.7

rmrf: add dryRun option

0.0.8

update dependencies

0.0.9 - unreleased
  • remove unused imports from getDirectories
  • getDirectories and getFiles now accept a number as second argument.
// if a number is given instead of true/false, then this is the depth of recursion.
getFiles(directory, 2) // two levels down
0.0.10
  • bump required node version to 14.15.4
  • update dependencies
0.0.11

update dependencies (@magic/mime-types)

0.0.12

export all functions from native fs

0.0.13
  • getDirectories, getFiles: default root to process.cwd() if first argument is an array and root is not passed
  • update dependencies
0.0.14

update dependencies (@magic/mime-types)

0.0.15 - unreleased

...

FAQs

Package last updated on 10 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc