Skip to content

NowTV-Assurance/node-hook-filename

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-hook-filename

Hooking node require calls for specific extensions to only return the filename or a specified module

Usage

Returning filename

var nhf = require('node-hook-filename');


nhf(['.scss', '.svg']);


var scssAsset = require('../path/too/filename.scss');
var svgAsset = require('../path/too/filename.svg');
var normalRequire = require('../path/too/js/file');

// scssAsset === '../path/too/filename.scss'
// svgAsset === '../path/too/filename.svg'

// normalRequire is unaffected

Passing a callback function

var nhf = require('node-hook-filename');
nhf(['config'], () => 'foo');

var configRequire = require('config');
// configRequire will return 'foo'

Useful if you are running a universal/isomorphic app that requires asset files.

This is mostly useful for testing and not production ready!

Greatly influenced by https://github.com/bahmutov/node-hook

About

Hooking node require calls for specific extensions to only return the filename

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors