3.0.0 • Published 5 years ago

fs-cheerio v3.0.0

Weekly downloads
55
License
BSD-2-Clause
Repository
github
Last release
5 years ago

Build Status npm version

fs-cheerio

DOM manipulation file system utilities. Combines Node's fs module with cheerio.

Install

npm install fs-cheerio --save

Usage

fs-cheerio allows you to read and write files to/from cheerio objects.

Note: While some of the below examples use async/await syntax, fs-cheerio will work with any Node version that supports Promises (or if you include a Promise polyfill).

readFile

Read from a file and create a cheerio object that can be manipulated. Returns a Promise that will resolve with the cheerio object.

const fsc = require("fs-cheerio");

fsc.readFile(__dirname + "/example.html").then(function($){
  // $ is a jquery/cheerio object that can be manipulated.
});

This works even better with async/await:

const fsc = require("fs-cheerio");

(async function(){
  let $ = await fsc.readFile(__dirname + "/example.html");
})();

writeFile

Write a cheerio object to a file. Returns a Promise that will resolve once the file has been written.

var fsc = require("fs-cheerio");

(async function(){

  let $ = await fsc.readFile(__dirname + "/example.html");
  $("#app").text("i changed this");

  await fsc.writeFile(__dirname + "/example.html", $);

})();

License

BSD 2 Clause

3.0.0

5 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

9 years ago