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

freud

v1.0.3

Published

copy and mutate files by extension

Downloads

24

Readme

freud.js

Build Status npm install

Freud watches directories and copies files between them. It allows you to modify the file information before rendering using callbacks attached to file extensions.

Err that's confusing, here:

example

var Freud = require('freud')

var freud = Freud('/home/me/src', '/home/me/html')
  , md = require('md')

freud.listen('md', function (file) {
  file.data = md(file.data)
  file.name = file.name.replace(/\.md$/, '.html')
  return file
})

freud.go()

That will watch /home/me/src for changes to files with the .md extension. When there is one, it will run the file contents through md, our theoretical Markdown processor, and change the extension to .html before dumping the mutated file into /home/me/html. Of course the origin file is never modified in any way.

Listen also accepts '*:before' and '*:after' to apply to all processed files. You can probably guess when they occur. If you add a listener with '*', it will be pushed onto the '*:before' stack. Listen also accepts an array of extensions to listen for, like:

freud.listen(['md', 'markdown', 'mkd'], parseFileFunction)

The file object available within your listen statements is of structure:

{
    name: "example.txt"
  , stats: (node fs.Stats object)
  , data: "the file contents"
  , write: true
}

If the file.write property is set to false and never reset to true at any point in the chain of transformations, Freud will not write it to the target directory.

note

Freud does not watch sub-directories. In order to effectively monitor multiple directories, you will need to construct multiple Freud objects.


options

Freud also accepts an optional third parameter of an options object. The options available are as follows:

  • monitorDot to watch for dotfile changes, default is false
  • monitorSquiggle to watch for files with names ending with ~, such as are common for backups. Default is false
  • ignoreCase to not match case on event/listener matching. Default is false

events

Freud will also emit certain events that may be useful, such as:

  • started when the service begins watching.
  • stopped when service is stopped (via freud.stop())
  • extensionAdded whenever a new extension is being listened for.
  • compiling whenever a valid (ie not blocked by user monitoring options and not a duplicate or temporary file) file change event is caught. The filename will be passed.
  • compiled after a file has been processed and written to the target directory. The compiled filename will be passed.
  • recompiled after a successful compilation triggered by freud.recompile(filename).
  • blocked whenever a write to the target has been canceled due to file.write being set to false.
  • unlinked when a file has been unlinked due to removal of the file in the source directory.
  • copying when a file has no rules it will be copied rather than processed for better performance.
  • copied when copying has occurred.

license

MIT