mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
94 lines
2.7 KiB
TypeScript
94 lines
2.7 KiB
TypeScript
/// <reference path="gulp-cheerio.d.ts" />
|
|
/// <reference path="../vinyl/vinyl.d.ts" />
|
|
/// <reference path="../gulp/gulp.d.ts" />
|
|
/// <reference path="../cheerio/cheerio.d.ts" />
|
|
|
|
import cheerio = require('gulp-cheerio');
|
|
import gulp = require('gulp');
|
|
import Vinyl = require('vinyl');
|
|
|
|
//
|
|
// There are two ways to use gulp-cheerio: synchronous and asynchronous. See the following usage examples:
|
|
//
|
|
|
|
gulp.task('sync', function () {
|
|
return gulp
|
|
.src(['src/*.html'])
|
|
.pipe(cheerio(function ($: CheerioStatic, file: Vinyl) {
|
|
// Each file will be run through cheerio and each corresponding `$` will be passed here.
|
|
// `file` is the gulp file object
|
|
// Make all h1 tags uppercase
|
|
$('h1').each(function () {
|
|
var h1 = $(this);
|
|
h1.text(h1.text().toUpperCase());
|
|
});
|
|
}))
|
|
.pipe(gulp.dest('dist/'));
|
|
});
|
|
gulp.task('async', function () {
|
|
return gulp
|
|
.src(['src/*.html'])
|
|
.pipe(cheerio(function ($: CheerioStatic, file: Vinyl, done: Function) {
|
|
// The only difference here is the inclusion of a `done` parameter.
|
|
// Call `done` when everything is finished. `done` accepts an error if applicable.
|
|
done();
|
|
}))
|
|
.pipe(gulp.dest('dist/'));
|
|
});
|
|
//TODO
|
|
|
|
|
|
//
|
|
// Additional options can be passed by passing an object as the main argument with your function as the run option:
|
|
//
|
|
|
|
|
|
gulp.task('sync', function () {
|
|
return gulp
|
|
.src(['src/*.html'])
|
|
.pipe(cheerio({
|
|
run: function ($: CheerioStatic, file: Vinyl) {
|
|
// Each file will be run through cheerio and each corresponding `$` will be passed here.
|
|
// `file` is the gulp file object
|
|
// Make all h1 tags uppercase
|
|
$('h1').each(function () {
|
|
var h1 = $(this);
|
|
h1.text(h1.text().toUpperCase());
|
|
});
|
|
}
|
|
}))
|
|
.pipe(gulp.dest('dist/'));
|
|
});
|
|
|
|
gulp.task('async', function () {
|
|
return gulp
|
|
.src(['src/*.html'])
|
|
.pipe(cheerio({
|
|
run: function ($: CheerioStatic, file: Vinyl, done: Function) {
|
|
// The only difference here is the inclusion of a `done` parameter.
|
|
// Call `done` when everything is finished. `done` accepts an error if applicable.
|
|
done();
|
|
}
|
|
}))
|
|
.pipe(gulp.dest('dist/'));
|
|
});
|
|
|
|
cheerio({
|
|
run: function () {},
|
|
parserOptions: {
|
|
// Options here
|
|
}
|
|
});
|
|
|
|
|
|
cheerio({
|
|
run: function () {},
|
|
parserOptions: {
|
|
xmlMode: true
|
|
}
|
|
});
|
|
|
|
cheerio({
|
|
cheerio: require('../cheerio/cheerio.d.ts') as CheerioStatic // special version of `cheerio`
|
|
});
|