{ "name": "rfile", "version": "1.0.0", "description": "Require a plain text or binary file in node.js", "main": "index.js", "scripts": { "test": "mocha -R spec" }, "repository": { "type": "git", "url": "https://github.com/ForbesLindesay/rfile.git" }, "keywords": [ "require", "file", "text", "relative", "module" ], "author": { "name": "ForbesLindesay" }, "license": "MIT", "readmeFilename": "README.md", "gitHead": "d82e3088d06d2a8ce94f51fa7536555c3947e74f", "dependencies": { "callsite": "~1.0.0", "resolve": "~0.3.0" }, "devDependencies": { "mocha": "~1.8" }, "readme": "# rfile\r\n\r\n[![Build Status](https://secure.travis-ci.org/ForbesLindesay/rfile.png)](http://travis-ci.org/ForbesLindesay/rfile)\r\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/rfile.png)](https://gemnasium.com/ForbesLindesay/rfile)\r\n\r\nrequire a plain text or binary file in node.js\r\n\r\n## Installation\r\n\r\n $ npm install rfile\r\n\r\n## Usage\r\n\r\n```javascript\r\nvar rfile = require('rfile');\r\n\r\nvar text = rfile('./my-text-file.txt');\r\nvar mochaReadme = rfile('mocha/readme.md');\r\nvar mochaSource = rfile('mocha');\r\nvar image = rfile('image.png', {binary: true});\r\n```\r\n\r\n## API\r\n\r\n### rfile(pkg, options)\r\n\r\n Uses `rfile.resolve` (see below) to look up your file `pkg`. This means it supports all the same options as `rfile.resolve`. Having found the file, it does the following:\r\n\r\n```javascript\r\nreturn options.binary ? read(path) : fixup(read(path).toString());\r\n```\r\n\r\n `options.binary` defaults to `false` and `fixup` removes the UTF-8 BOM if present and removes any `\\r` characters (added to newlines on windows only).\r\n\r\n### rfile.resolve(pkg, options)\r\n\r\n Internally, [resolve](https://npmjs.org/package/resolve) is used to lookup your package, so it supports all the same options as that. In addition t defaults `basedir` to the directory of the function which called `rfile` or `rfile.resolve`.\r\n\r\n The additional option `exclude` is useful if you wanted to create a wrapper arround this. It specifies the filenames not to consider for `basedir` paths. For example, you could create a module called `ruglify` for requiring and minifying JavaScript in one go.\r\n\r\n ruglify.js\r\n```javascript\r\nvar rfile = require('rfile');\r\nvar uglify require('uglify-js').minify;\r\n\r\nmodule.exports = ruglify;\r\nfunction ruglify(path, options) {\r\n return minify(rfile.resolve(path, {exclude: [__filename]}), options).code;\r\n}\r\n```\r\n\r\n#### From `resolve`\r\n\r\n - opts.basedir - directory to begin resolving from (defaults to `__dirname` of the calling module for `rfile`)\r\n - opts.extensions - array of file extensions to search in order (defaults to `['.js', '.json']` for `rfile`)\r\n - opts.readFile - how to read files asynchronously\r\n - opts.isFile - function to asynchronously test whether a file exists\r\n - opts.packageFilter - transform the parsed package.json contents before looking at the \"main\" field (useful for browserify etc.)\r\n - opts.paths - require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this)\r\n\r\n## Notes\r\n\r\nOne of the interesting features of this is that it respects the `main` field of package.json files. Say you had a module called `foo`, you could have a package.json like:\r\n\r\n```json\r\n{\r\n \"name\": \"foo\",\r\n \"version\": \"1.0.0\",\r\n \"main\": \"./foo\"\r\n}\r\n```\r\n\r\nYou might then have a `foo.js` file, containing the JavaScript code of the module, and a `foo.css` file containing the stylesheet for the module when used in the browser. Using `rfile` you could load the css by simply calling:\r\n\r\n```javascript\r\nrfile('foo', {extensions: ['.css']});\r\n```\r\n\r\n## License\r\n\r\n MIT", "bugs": { "url": "https://github.com/ForbesLindesay/rfile/issues" }, "_id": "rfile@1.0.0", "_from": "rfile@~1.0.0" }