Socket
Socket
Sign inDemoInstall

file-utils

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-utils

Sync file utility for Node.js command line tools


Version published
Weekly downloads
4.8K
increased by17.43%
Maintainers
1
Weekly downloads
 
Created
Source

file-utils

This is a Grunt.file forks to allow the creation of scoped file utilities and the ability to add write filters.

Same as Grunt.file, this is a set of synchronous utility. As so, it should never be used on a Node.js server. This is meant for users/command line utilities.

ENV scope and filters

Creating an Env - file#createEnv([ options ]);

var file = require('file-utils');

var env = file.createEnv({
  base: 'my/scoped/path'
});

file-utils root module options are inherited by the Env instance if not overwritten in the option hash.

Write Filters

Write filters are applied on env.write and env.copy.

Add a write filter - env.registerWriteFilter( name, filter )

options

  • name (String): The name under which registering the filter
  • filter (Function): The filter function

The filter function take a file object as parameter. This file object is a hash containing a path and a contents property. You can modify these two property as you like and returning the modified object.

env.registerWriteFilter( 'coffee', function( file ) {
  if (!path.extname(file) !== '.js') return file;

  file.path = file.path.replace(/(\.js)$/, '.coffee');
  file.content = convertJsToCoffee( file.contents );

  return file;
});
Remove a write filter - env.removeWriteFilter( name )
env.removeWriteFilter('coffee');

File API

Upcoming. Meanwhile, check Grunt.file documentation.

Setting options - file.option( name, [ value ])
// Set option
file.option('write', false);

// Get option
file.option('write');

Available Options

  • write (Boolean): If write is set to false, then no file will be written or deleted. Useful for test run without side effets.
  • logger (Logger object): Used internally to log information to the console. API still work in progress
  • encoding (String): Defaults utf8. Set the default encoding used for reading/writing. Note most methods allow you to overwridde it for a single run.
  • force (Boolean): force: true Force the deletion of folders and file outside the utility scope (or CWD if no scope).

Todos

  • Real Logging system
  • Scoping the destination when copying
  • Async filtering (?)

Keywords

FAQs

Package last updated on 05 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc