mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
Add gulp-cheerio
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/// <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`
|
||||
});
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// Type definitions for gulp-cheerio
|
||||
// Project: https://github.com/KenPowers/gulp-cheerio
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../cheerio/cheerio.d.ts" />
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
/// <reference path="../vinyl/vinyl.d.ts"/>
|
||||
|
||||
declare module "gulp-cheerio" {
|
||||
import Vinyl = require('vinyl');
|
||||
|
||||
namespace cheerio {
|
||||
interface Cheerio {
|
||||
(callback: Callback): NodeJS.ReadWriteStream;
|
||||
(option: Option): NodeJS.ReadWriteStream;
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
($: CheerioStatic, file: Vinyl, done?: Function): any;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
run?: Callback;
|
||||
parserOptions?: CheerioOptionsInterface;
|
||||
cheerio?: CheerioStatic;
|
||||
}
|
||||
}
|
||||
|
||||
var cheerio: cheerio.Cheerio;
|
||||
|
||||
export = cheerio;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user