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

meiro

v0.0.1

Published

Automatically move files from one folder to another

Downloads

2

Readme

meiro

Meiro is a convenient wrapper using chokidar to automatically move files around your system*. It's currently still in development and hasn't been tested alot.

LogoOfMeiro

Getting Started

Install with npm (meiro uses chokidar for file detection)

npm install meiro
npm install chokidar

Then require and initialize it with chokidar.

const chokidar = require('chokidar');
const meiro    = require('meiro')({
  chokidar : chokidar,
  logger   : console.log /* not yet implemented */
});

Methods

- meiro.startWatcher(obj)

  • Returns an instance of FSWatcher from chokidar.watch()
  • Starts a new watcher which automatically moves files from Folder A to Folder B.
  • Example:
// async/await
const watcher = await meiro.getWatcher({ /* options */});

// default promise
meiro.startWatcher({ /* options */})
  .then( watcher => {})
  .catch( e => {});

// watcher is an instance of FSWatcher from chokidar.watch()
// with already attached event handler for 'add' event
Options for meiro.startWatcher(options)
  • watchFolder (required) : Folder from which files should get moved from. Must be a directory. Uses globe pattern for wildcard * subfolder. Example: C:/Documents/*/ Will look in each subfolder of Documents .

  • targetExt (optional) : Only files with specified file extension will be moved. Example: "mov" will only look for *.mov files. You can only pass an array like ["mov", "mxf"] to look for multiple file extensions. If not specified all files will be moved.

  • destination (required) : Folder to which files should get moved to. Must be a directory.

  • before (optional) : Takes a function with 1 parameter. Will be triggered if a matching file was found, before it gets moved. Parameter is a string value with the full path to the matching file. Should return true if the file should get moved, false if not. Can be used for additional filtering. Example:

let options = {
	before : (pathToFile) => {
		return true /* File should get moved */
	}
}
  • filename (optional) : Takes a function with 1 parameter. Will be triggered before the file gets moved. Parameter is a string value with the filename (incl. ext). Should return a string value with the new filename. You need to take care of the file extension yourself. Can be used to rename files. Example:
let options = {
	filename : (filename) => {
		return Date.now() + path.extname(filename);
		// 1574954935145.mov
	}
}
  • after(optional) : Takes a function with 2 parameters. Will be triggerd after the file was moved. First parameter is a string value with the old path to the file, second parameter is a string value with the new path to the file. Example:
let options = {
	after : (from, to) => {
		console.log(`File was moved from ${from} to ${to}`);
	}
}
  • ignoreInitial (optional) - defaut : false - If set to false then meiro already gets triggered for existing files. If set to true meiro only gets triggered for new files.

  • disableGlobbing (optional) - default : false - If set to true then the string passed to watchFolder is treated as literal path name, even if it looks like a glob pattern.

  • awaitWriteFinish (optional) - default : false - By default, the meiro will fire when a file first appears on disk, before the entire file has been written. options.awaitWriteFinish can be set to an object in order to adjust timing params:

    • awaitWriteFinish.stabilityThreshold - default : 6000 - Amount of time in milliseconds for a file size to remain constant before emitting its event.
    • awaitWriteFinish.pollInterval - default: 200 - File size polling interval, in milliseconds.

How does it work ?

Meiro heavily depends on chokidar. Chokidar does most of the work underground to detect new files. Meiro is just a convenient wrapper in order to automatically move files from A to B. Check out chokidar for more details - it's awesome!

Example Usecase 1 : If you get multiple files of various filetypes (extension) written into one directory (e.g. from another service) and you want to sort them automatically into specific subdirectories. For example *.mov & *.mxf into a ./video directory and *.jpg into a ./images directory.

Example Usecase 2 : If you get multiple files written into multiple directories across your system (e.g. from another service) and you want to automatically group them into one specific main folder.