npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magic/fs

v0.0.30

Published

nodejs fs promises + goodies

Downloads

1,751

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(), false)
  console.log(directories)

  // first level again
  const dirs = await fs.getDirectories(process.cwd(), { depth: false })

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

  // recursive run with specified depth
  const deepDirectoriesDepth2 = await fs.getDirectories(process.cwd(), { depth: 2 })
  console.log(deepDirectoriesDepth2)

  // use /some/dir as root instead of process.cwd()
  const deepDirWithRoot = await fs.getDirectories(process.cwd(), { depth: true, root: '/some/dir' })
  console.log(deepDirWithRoot)
}
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(), { depth: true })
  console.log(deepFiles)

  // recursive run with specified depth,
  const deepFilesDepth2 = await fs.getFiles(process.cwd(), { depth: 2 })
  console.log(deepFilesDepth2)
}
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

  • 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

update @magic/types to avoid circular dependency

0.0.16

add deprecation warning for calls to fs.getDirectories, fs.getFilePath and fs.getFiles that do not use an options object

0.0.17

update dependencies

0.0.18

update mime-types

0.0.19

update dependencies

0.0.20

update dependencies

0.0.21
  • add missing @magic/fs dependency
  • update dependencies
0.0.22

update dependencies

0.0.23

update dependencies

0.0.24

getFiles: allow files to be filtered by extension, using the .extension key of the second parameter

0.0.25

update dependencies

0.0.26

update dependencies

0.0.27

update dependencies

0.0.28

update dependencies

0.0.29
  • update dependencies
  • getFiles and getDirectories now accept maxDepth and minDepth config args
0.0.30
  • update dependencies
  • remove deprecated getFiles and getDirectories api
  • add minDepth option
0.0.31 - unreleased

...