react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / umd / node_modules / rfile / package.json
80742 views{1"name": "rfile",2"version": "1.0.0",3"description": "Require a plain text or binary file in node.js",4"main": "index.js",5"scripts": {6"test": "mocha -R spec"7},8"repository": {9"type": "git",10"url": "https://github.com/ForbesLindesay/rfile.git"11},12"keywords": [13"require",14"file",15"text",16"relative",17"module"18],19"author": {20"name": "ForbesLindesay"21},22"license": "MIT",23"readmeFilename": "README.md",24"gitHead": "d82e3088d06d2a8ce94f51fa7536555c3947e74f",25"dependencies": {26"callsite": "~1.0.0",27"resolve": "~0.3.0"28},29"devDependencies": {30"mocha": "~1.8"31},32"readme": "# rfile\r\n\r\n[](http://travis-ci.org/ForbesLindesay/rfile)\r\n[](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",33"_id": "[email protected]",34"dist": {35"shasum": "59708cf90ca1e74c54c3cfc5c36fdb9810435261",36"tarball": "http://registry.npmjs.org/rfile/-/rfile-1.0.0.tgz"37},38"_from": "rfile@>=1.0.0 <1.1.0",39"_npmVersion": "1.2.10",40"_npmUser": {41"name": "forbeslindesay",42"email": "[email protected]"43},44"maintainers": [45{46"name": "forbeslindesay",47"email": "[email protected]"48}49],50"directories": {},51"_shasum": "59708cf90ca1e74c54c3cfc5c36fdb9810435261",52"_resolved": "https://registry.npmjs.org/rfile/-/rfile-1.0.0.tgz"53}545556