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

file-manager-js

v3.1.6

Published

manage files and directories on the local storage through an enhanced promise interface

Downloads

164

Readme

file-manager-js

build:? npm npm npm

Description

It uses node filesystem to manage files and directories on the local storage through an enhanced promise interface. It can list/create/remove files and directories recursively with promises.

Install

npm install file-manager-js

Usage

// require all functions
const fileManager = require('file-manager-js');

// OR specific functions
const { list, removeFile, rename } = require('file-manager-js');

.stat(path)

promisified fs.stat. retrieves the stats of a file or directory. https://nodejs.org/api/fs.html#fs_class_fs_stats

fileManager.stat('./test.txt')
  .then((stats) => // stats)
  .catch((error) => // error);

.info(path)

returns an extended stats object that includes size (bytes) and type of the path

// file info
fileManager.info('./test.txt').then((info) => {
  /*
   {
     size: 19,
     type: 'file',
     ...
   }
  */
}).catch((error) => // error);

// directory info
fileManager.info('./test')
  .then((info) => {
    /*
     {
       size: 2146, // size of all files in dir tree
       type: 'directory',
       ...
     }
    */
  })
  .catch((error) => // error);

.join(path1, path2)

join two paths. a delegate to require('path').join

let p = fileManager.join('a/b/c', 'd/e/f'); // a/b/c/d/e/f

.list(path)

list first-level files and directories inside a directory

// path can be an absolute path using __dirname
fileManager.list('./project')
  .then((entries) => {
    /*
     {
       files: ['index.js', 'README.md'],
       dirs : ['lib', 'node_modules', 'test']
     }
    */
  })
  .catch((error) => // error)

.listDeep(path)

list in-depth files and directories inside a directory

fileManager.listDeep('./content')
  .then((entries) => {
    /*
     {
       files: ['test.txt', 'abc/test.csv', 'new/content/test/a.txt'],
       dirs : ['abc', 'abc/test', 'new/content/test']
     }
    */
  })
  .catch((error) => // error)

.exists(path)

checks if a path (file or directory) exists and resolve with true or false

fileManager.exists('./content')
  .then((exists) => // true)
  .catch((error) => // error)

fileManager.exists('./newContent')
  .then((exists) => // false)
  .catch((error) => // error)

.createDir(path)

creates a single directory or a directory tree

// create a directory tree
fileManager.createDir('./a/b/c/d')
  .then((path) => // path = ./a/b/c/d)
  .catch((error) => // error)

.createFile(path)

creates a file and creates the directory tree in the path if not exists

// creates a directory structure then the file
fileManager.createFile('./x/y/z/test.txt')
  .then((path) => // path = ./x/y/z/test.txt)
  .catch((error) => // error)

.readFile(path)

reads entire file content

fileManager.readFile('./x/y/z/test.txt')
  .then((content) => // content is instance of Buffer)
  .catch((error) => // error)

.removeDir(path)

removes a directory or directory tree with all its content

// remvove a/b/c/d + a/b/c +  a/b/test.txt + a/b + a
fileManager.removeDir('./a')
  .then((path) => // ./a)
  .catch((error) => // error)

.removeFile(path)

removes a file

// removed ./test.txt
fileManager.removeFile('./test.txt')
  .then((path) => // ./test.txt)
  .catch((error) => // error)

.rename(oldPath, newPath)

rename a file or directory

// rename file ./test.txt to ./ttt.txt
fileManager.rename('./test.txt', './ttt.txt')
  .then((newPath) => // ./ttt.txt)
  .catch((error) => // error)

Build

grunt build

License

The MIT License. Full License is here