Socket
Socket
Sign inDemoInstall

to-vfile

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-vfile - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

lib/async.js

110

lib/fs.js
'use strict'
var fs = require('fs')
var path = require('path')
var vfile = require('./core')
var sync = require('./sync')
var async = require('./async')
module.exports = vfile
vfile.read = read
vfile.readSync = readSync
vfile.write = write
vfile.writeSync = writeSync
/* Create a virtual file and read it in, asynchronously. */
function read(description, options, callback) {
var file = vfile(description)
if (!callback && typeof options === 'function') {
callback = options
options = null
}
if (!callback) {
return new Promise(executor)
}
executor(null, callback)
function executor(resolve, reject) {
var fp
try {
fp = path.resolve(file.cwd, file.path)
} catch (err) {
return reject(err)
}
fs.readFile(fp, options, done)
function done(err, res) {
if (err) {
reject(err)
} else {
file.contents = res
if (resolve) {
resolve(file)
} else {
callback(null, file)
}
}
}
}
}
/* Create a virtual file and read it in, synchronously. */
function readSync(description, options) {
var file = vfile(description)
file.contents = fs.readFileSync(path.resolve(file.cwd, file.path), options)
return file
}
/* Create a virtual file and write it out, asynchronously. */
function write(description, options, callback) {
var file = vfile(description)
/* Weird, right? Otherwise `fs` doesn’t accept it. */
if (!callback && typeof options === 'function') {
callback = options
options = undefined
}
if (!callback) {
return new Promise(executor)
}
executor(null, callback)
function executor(resolve, reject) {
var fp
try {
fp = path.resolve(file.cwd, file.path)
} catch (err) {
return reject(err)
}
fs.writeFile(fp, file.contents || '', options, done)
function done(err) {
if (err) {
reject(err)
} else if (resolve) {
resolve()
} else {
callback()
}
}
}
}
/* Create a virtual file and write it out, synchronously. */
function writeSync(description, options) {
var file = vfile(description)
fs.writeFileSync(
path.resolve(file.cwd, file.path),
file.contents || '',
options
)
}
vfile.read = async.read
vfile.readSync = sync.read
vfile.write = async.write
vfile.writeSync = sync.write
{
"name": "to-vfile",
"version": "5.0.1",
"version": "5.0.2",
"description": "Create a vfile from a file-path",

@@ -17,5 +17,5 @@ "license": "MIT",

"bugs": "https://github.com/vfile/to-vfile/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],

@@ -34,9 +34,9 @@ "main": "index.js",

"browserify": "^16.0.0",
"nyc": "^12.0.0",
"nyc": "^13.0.0",
"prettier": "^1.12.1",
"remark-cli": "^5.0.0",
"remark-cli": "^6.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.0.0",
"tinyify": "^2.4.3",
"xo": "^0.21.0"
"xo": "^0.23.0"
},

@@ -43,0 +43,0 @@ "scripts": {

@@ -106,5 +106,5 @@ # to-vfile [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

[license]: LICENSE
[license]: license
[author]: http://wooorm.com
[author]: https://wooorm.com

@@ -111,0 +111,0 @@ [vfile]: https://github.com/vfile/vfile

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc