Comparing version 1.0.0 to 2.0.0
73
index.js
@@ -1,69 +0,12 @@ | ||
'use strict'; | ||
/* | ||
* Dependencies. | ||
*/ | ||
var fs = require('fs'); | ||
var toVFile = require('./lib/to-vfile.js'); | ||
/* | ||
* Methods. | ||
*/ | ||
var read = fs.readFile; | ||
var readSync = fs.readFileSync; | ||
/** | ||
* Async callback. | ||
* | ||
* @callback toVFile~callback | ||
* @param {Error} err - Error from reading `filePath`. | ||
* @param {VFile} file - Virtual file. | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @module to-vfile | ||
* @fileoverview Read files from the file-system. | ||
*/ | ||
/** | ||
* Create a virtual file from `filePath` and fill it with | ||
* the actual contents at `filePath`. | ||
* | ||
* @param {string} filePath - Path to file. | ||
* @param {toVFile~callback} callback - Callback. | ||
*/ | ||
function async(filePath, callback) { | ||
var file = toVFile(filePath); | ||
'use strict'; | ||
read(filePath, 'utf-8', function (err, res) { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
file.contents = res; | ||
callback(null, file); | ||
} | ||
}); | ||
} | ||
/** | ||
* Create a virtual file from `filePath` and fill it with | ||
* the actual contents at `filePath` (synchroneously). | ||
* | ||
* @param {string} filePath - Path to file. | ||
* @throws {Error} err - When reading `filePath` fails. | ||
* @return {VFile} Virtual file. | ||
*/ | ||
function sync(filePath) { | ||
var file = toVFile(filePath); | ||
file.contents = readSync(filePath, 'utf-8'); | ||
return file; | ||
} | ||
/* | ||
* Expose. | ||
*/ | ||
toVFile.read = async; | ||
toVFile.readSync = sync; | ||
module.exports = toVFile; | ||
/* Expose. */ | ||
module.exports = require('./lib/fs'); |
{ | ||
"name": "to-vfile", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Create a vfile from a file-path", | ||
@@ -16,6 +16,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"vfile": "^1.0.0" | ||
"is-buffer": "^1.1.4", | ||
"vfile": "^2.0.0", | ||
"x-is-string": "^0.1.0" | ||
}, | ||
"main": "index.js", | ||
"browser": "lib/to-vfile.js", | ||
"browser": "lib/core.js", | ||
"files": [ | ||
@@ -25,36 +27,54 @@ "lib", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wooorm/to-vfile.git" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com>", | ||
"repository": "https://github.com/wooorm/to-vfile", | ||
"bugs": "https://github.com/wooorm/to-vfile/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
], | ||
"devDependencies": { | ||
"browserify": "^11.0.1", | ||
"eslint": "^1.0.0", | ||
"browserify": "^13.0.1", | ||
"esmangle": "^1.0.1", | ||
"istanbul": "^0.3.0", | ||
"jscs": "^2.0.0", | ||
"jscs-jsdoc": "^1.0.0", | ||
"mdast": "^1.0.0", | ||
"mdast-comment-config": "^0.1.2", | ||
"mdast-github": "^0.3.2", | ||
"mdast-lint": "^0.4.2", | ||
"mdast-slug": "^0.1.1", | ||
"mdast-validate-links": "^0.3.1", | ||
"mocha": "^2.0.0" | ||
"nyc": "^8.1.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-validate-links": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.16.0" | ||
}, | ||
"scripts": { | ||
"test-api": "mocha --check-leaks test.js", | ||
"test-coverage": "istanbul cover _mocha -- test.js", | ||
"test-travis": "npm run test-coverage", | ||
"test": "npm run test-api", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"make": "npm run lint && npm run test-coverage", | ||
"bundle": "browserify lib/to-vfile.js -s toVFile > to-vfile.js", | ||
"postbundle": "esmangle to-vfile.js > to-vfile.min.js", | ||
"build-md": "mdast . --quiet", | ||
"build": "npm run bundle && npm run build-md" | ||
"build-md": "remark . --quiet --frail", | ||
"build-bundle": "browserify index.js --bare -s toVFile > to-vfile.js", | ||
"build-mangle": "esmangle to-vfile.js > to-vfile.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"xo": { | ||
"space": true, | ||
"ignores": [ | ||
"to-vfile.js" | ||
] | ||
}, | ||
"remarkConfig": { | ||
"output": true, | ||
"plugins": { | ||
"comment-config": null, | ||
"github": null, | ||
"lint": null, | ||
"validate-links": null | ||
}, | ||
"settings": { | ||
"bullet": "*" | ||
} | ||
} | ||
} |
147
readme.md
@@ -1,8 +0,9 @@ | ||
# to-vfile [![Build Status](https://img.shields.io/travis/wooorm/to-vfile.svg)](https://travis-ci.org/wooorm/to-vfile) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/to-vfile.svg)](https://codecov.io/github/wooorm/to-vfile) | ||
# to-vfile [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
Create a [vfile](https://github.com/wooorm/vfile) from a file-path. | ||
Create a [vfile][] from a file-path. Optionally populates them from | ||
the file-system as well. | ||
## Installation | ||
[npm](https://docs.npmjs.com/cli/install): | ||
[npm][npm-install]: | ||
@@ -13,121 +14,85 @@ ```bash | ||
**to-vfile** is also available for [bower](http://bower.io/#install-packages), | ||
[component](https://github.com/componentjs/component), and [duo](http://duojs.org/#getting-started), | ||
and as an AMD, CommonJS, and globals module, [uncompressed](to-vfile.js) and [compressed](to-vfile.min.js). | ||
> **Note:** the file-system stuff is not available in the browser. | ||
> **Note:** browser-builds do not include `read` and `readSync`. | ||
## Usage | ||
Dependencies: | ||
```js | ||
var toVFile = require('to-vfile'); | ||
``` | ||
var file = toVFile('./readme.md'); | ||
/* | ||
* { contents: '', | ||
* filename: 'readme', | ||
* directory: '.', | ||
* extension: 'md', | ||
* messages: [], | ||
* __proto__: [VFile] } | ||
*/ | ||
Create a virtual file by its file-path: | ||
toVFile.read('.git/HEAD', function (err, file) { | ||
if (err) throw err; | ||
```js | ||
toVFile('readme.md'); | ||
``` | ||
console.log(file); | ||
/* | ||
* { contents: 'ref: refs/heads/master\n', | ||
* filename: 'HEAD', | ||
* directory: '.git', | ||
* extension: '', | ||
* messages: [], | ||
* __proto__: [VFile] } | ||
*/ | ||
}); | ||
Yields: | ||
var file = toVFile.readSync('.gitignore') | ||
/* | ||
* { contents: '.DS_Store\n*.log\nbower_components/\nbuild/\ncomponents/\nnode_modules/\ncoverage/\nbuild.js\n', | ||
* filename: '.gitignore', | ||
* directory: '.', | ||
* extension: '', | ||
* messages: [], | ||
* __proto__: [VFile] } | ||
*/ | ||
```js | ||
VFile { | ||
data: {}, | ||
messages: [], | ||
history: [ 'readme.md' ], | ||
cwd: '/Users/tilde/projects/oss/to-vfile' } | ||
``` | ||
## API | ||
Populate a virtual file: | ||
### toVFile(filePath) | ||
```js | ||
toVFile.readSync('.git/HEAD', 'utf8'); | ||
``` | ||
Create a virtual file from `filePath`. | ||
Yields: | ||
**Signatures** | ||
```js | ||
VFile { | ||
data: {}, | ||
messages: [], | ||
history: [ '.git/HEAD' ], | ||
cwd: '/Users/tilde/projects/oss/to-vfile', | ||
contents: 'ref: refs/heads/master\n' } | ||
``` | ||
* `file = toVFile(filePath)`. | ||
## API | ||
**Parameters** | ||
### `toVFile(options)` | ||
* `filePath` (`string`) — Path to a (possibly non-existent) file; | ||
Create a virtual file. Works like the [vfile][] constructor, | ||
except when `options` is `string` or `Buffer`, in which case | ||
it’s treated as `{path: options}` instead of `{contents: options}`. | ||
**Returns** | ||
### `toVFile.read(options[, encoding], callback)` | ||
[`vfile`](https://github.com/wooorm/vfile) — Instance. | ||
Creates a virtual file from options (`toVFile(options)`), reads the | ||
file from the file-system and populates `file.contents` with the result. | ||
If `encoding` is specified, it’s passed to `fs.readFile`. | ||
Invokes `callback` with either an error or the populated virtual file. | ||
### toVFile.read(filePath, done) | ||
### `toVFile.readSync(options[, encoding])` | ||
Create a virtual file from `filePath` and fill it with the actual contents | ||
at `filePath`. | ||
Like `toVFile.read` but synchronous. Either throws an error or | ||
returns a populated virtual file. | ||
**Signatures** | ||
## License | ||
* `toVFile.read(filePath, callback)`. | ||
[MIT][license] © [Titus Wormer][author] | ||
**Parameters** | ||
<!-- Definitions --> | ||
* `filePath` (`string`) — Path to a (possibly non-existent) file; | ||
* `callback` — See [`function done(err, vfile)`](#function-doneerr-vfile). | ||
[travis-badge]: https://img.shields.io/travis/wooorm/to-vfile.svg | ||
**Returns** | ||
[travis]: https://travis-ci.org/wooorm/to-vfile | ||
[`vfile`](https://github.com/wooorm/vfile) — Instance. | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/to-vfile.svg | ||
#### function done(err, vfile) | ||
[codecov]: https://codecov.io/github/wooorm/to-vfile | ||
Callback. | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
**Signatures** | ||
[license]: LICENSE | ||
* `function done(Error, null)`; | ||
* `function done(null, VFile)`. | ||
[author]: http://wooorm.com | ||
**Parameters** | ||
* `err` (`Error`) — Error from reading `filePath`; | ||
* `vfile` (`VFile`) — Virtual file. | ||
### toVFile.readSync(filePath) | ||
Create a virtual file from `filePath` and fill it with the actual contents at | ||
`filePath` (synchroneously). | ||
**Signatures** | ||
* `toVFile.read(filePath, callback)`. | ||
**Parameters** | ||
* `filePath` (`string`) — Path to a (possibly non-existent) file; | ||
**Returns** | ||
[`vfile`](https://github.com/wooorm/vfile) — Instance. | ||
**Throw** | ||
`Error` — When reading `filePath` fails. | ||
## License | ||
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com) | ||
[vfile]: https://github.com/wooorm/vfile |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
7220
10
6
87
3
98
2
1
+ Addedis-buffer@^1.1.4
+ Addedx-is-string@^0.1.0
+ Addedis-buffer@1.1.6(transitive)
+ Addedreplace-ext@1.0.0(transitive)
+ Addedunist-util-stringify-position@1.1.2(transitive)
+ Addedvfile@2.3.0(transitive)
+ Addedvfile-message@1.1.1(transitive)
+ Addedx-is-string@0.1.0(transitive)
- Removedvfile@1.4.0(transitive)
Updatedvfile@^2.0.0