JSPM

  • Created
  • Published
  • Downloads 478
  • Score
    100M100P100Q92230F
  • License AGPL-3.0

nodejs fs promises + goodies

Package Exports

  • @magic/fs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@magic/fs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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)
}
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)
}
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 publish

0.0.2

  • bump required node version
  • update dependencies

0.0.3 - unreleased

...