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