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

shutil.js

v0.3.1

Published

A Lightweight File Operating Library

Downloads

15

Readme

shutil.js

A Lightweight File Operating Library

Build Status Coverage Status

unstable

Badge LICENSE MIT Licence

Installation

Using npm:

$ npm i -g shutil.js
$ npm i shutil.js

Note: add --save if you are using npm < 5.0.0

In Node.js:

const shutil = require('shutil.js')

let pwd = "."
for (let [root, dirs, files] of await shutil.walk(pwd)) {
	//
}

Why shutil?

This FileSystem module in Node.JS is pretty simple but we want more.

Try this

const fs = require('fs')
fs.rmdirSync("..") //Woops Error: ENOTEMPTY: directory not empty, rmdir ".."

Or this

const fs = require('fs')
fs.mkdirSync("../a/b/c") //Woops Again Error: ENOENT: no such file or directory, mkdir "./a/b/c"

Or this

const fs = require('fs')
//fs.walk(".") //Woops How to do this?

shutil will make all this things easier.

More important, shutil will do nothing more beyond pure file system operations.

API Documents

shutil.copy: (src, dest[, options]) -> Promise

	/**
	 * Copy a file/directory to another directory/file
	 * directory -> directory will do things recursively
	 * @argument
	 * 		{src}:string the path,
	 * 		{dest}:string the path,
	 * 		{options}:object
	 * 			{override}:bool, if true, the same file in `dest` path will be overrided. 
	 * 						default false
	 * 			{aswhole}:bool, if true, the `src` directory will seems as a whole part to move. 
	 * 						default false (means only move all contained files in the `src` path)
	 * @returns
	 * 		{Promise}: nothing fulfilled.
	 * @short
	 * 		same as `shutil.cp`
	 */
	const shutil = require("shutil.js")
	await shutil.copy("./from", "./to", {override: true, aswhole: false}) 	// `/from` copy to `/to/from`
	await shutil.cp("./from", "./to", {override: true, aswhole: true}) 		// `/from` copy to `/to`

shutil.exists: (src) -> Promise

	/**
	 * Check a dir/file is exists (or accessable)
	 * @argument
	 * 		{src}:string the path to check
	 * @returns
	 * 		{Promise}: fulfilled with true is the `src` path is exists, otherwise false.
	 */
	const shutil = require("shutil.js")
	if (await shutil.exists(".")) {
		//exists
	}

shutil.isdir: (src) -> Promise

	/**
	 * Check `src` path is exist as a directory
	 * @argument
	 * 		{src}:string the path
	 * @returns
	 * 		{Promise}: fulfilled with true if `src` is a exist directory , otherwise false
	 */
	const shutil = require("shutil.js")
	if (await shutil.isdir("./dir")) {
		//exists
	}

shutil.isfile: (src) -> Promise

	/**
	 * Check `src` path is exist as a file
	 * @argument
	 * 		{src}:string the path
	 * @returns
	 * 		{Promise}: fulfilled with true if `src` is a exist file , otherwise false
	 */
	const shutil = require("shutil.js")
	if (await shutil.isfile("./file")) {
		//exists
	}

shutil.listdir: (src) -> Promise

	/**
	 * List all files/dirs contains in `src` path
	 * @argument
	 * 		{src}:string the path to list
	 * @returns
	 * 		{Promise}: fulfilled with a name list; if the `src` is not a exists directory, fulfilled with empty array `[]`
	 * @short
	 * 		exactly same as `shutil.ls`
	 */
	const shutil = require("shutil.js")
	for (let all of await shutil.listdir(".")) {
		
	}
	//shot usage
	console.log(`show dirs ${await shutil.ls('.')}`)

shutil.mkdirp: (src) -> Promise

	/**
	 * Create a directory
	 * @argument
	 * 		{src}:string the path,
	 * @returns
	 * 		{Promise}: nothing fulfilled
	 * @short
	 * 		same as `shutil.md`
	 */
	const shutil = require("shutil.js")
	await shutil.mkdir("any/valid/path/will/be/created")
	await shutil.md("any/valid/path/will/be/created")

shutil.move: (src, dest[, options]) -> Promise

	/**
	 * Move a file/directory to another directory/file
	 * file -> file means rename
	 * file -> directory means move
	 * directory -> directory will do things recursively
	 * @argument
	 * 		{src}:string the path,
	 * 		{dest}:string the path,
	 * 		{options}:object
	 * 			{override}:bool, if true, the same file in `dest` path will be overrided. 
	 * 						default false
	 * 			{aswhole}:bool, if true, the `src` directory will seems as a whole part to move. 
	 * 						default false (means only move all contained files in the `src` path)
	 * @returns
	 * 		{Promise}: nothing fulfilled.
	 * @short
	 * 		same as `shutil.mv`
	 */
	const shutil = require("shutil.js")
	await shutil.move("./from", "./to", {override: true, aswhole: false}) 	// `/from` move to `/to/from`
	await shutil.mv("./from", "./to", {override: true, aswhole: true})	 	// `/from` rename to `/to`

shutil.rmtree: (src) -> Promise

	/**
	 * Remove a directory, everything will be removed.
	 * @argument
	 * 		{src}:string the path,
	 * @returns
	 * 		{Promise}: nothing fulfilled
	 * @short
	 * 		same as `shutil.rd`
	 */
	const shutil = require("shutil.js")
	await shutil.rmtree("any")
	await shutil.md("any")

shutil.walk: (src) -> Promise

	/**
	 * Travers a directory
	 * @argument
	 * 		{src}:string the path,
	 * @returns
	 * 		{Promise}: fulfilled with a [root, dirs, files] array if `src` path is exists, otherwise fulfilled with empty array `[]`
	 */
	const shutil = require("shutil.js")
	for (let [root, dirs, files] of await shutil.walk(".")){

	}

Todos

  • filters
  • excludes