mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #6378 from SomaticIT/connect-livereload-typings
Add connect-livereload typings
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/// <reference path="./connect-livereload.d.ts" />
|
||||
|
||||
import * as connect from "connect";
|
||||
import * as livereload from "connect-livereload";
|
||||
|
||||
const app = connect();
|
||||
|
||||
// With no options
|
||||
app.use(livereload());
|
||||
|
||||
// With string options
|
||||
app.use(livereload({
|
||||
port: 35729,
|
||||
ignore: [".js", ".svg"]
|
||||
}));
|
||||
|
||||
// With RegExp options
|
||||
app.use(livereload({
|
||||
port: 35729,
|
||||
ignore: [/\.js(\?.*)?$/, /\.css(\?.*)?$/]
|
||||
}));
|
||||
|
||||
// With default options
|
||||
app.use(livereload({
|
||||
ignore: [
|
||||
/\.js(\?.*)?$/, /\.css(\?.*)?$/, /\.svg(\?.*)?$/, /\.ico(\?.*)?$/, /\.woff(\?.*)?$/,
|
||||
/\.png(\?.*)?$/, /\.jpg(\?.*)?$/, /\.jpeg(\?.*)?$/, /\.gif(\?.*)?$/, /\.pdf(\?.*)?$/
|
||||
],
|
||||
|
||||
// include all urls by default
|
||||
include: [/.*/],
|
||||
|
||||
// this function is used to determine if the content of `res.write` or `res.end` is html.
|
||||
html: function (str) {
|
||||
if (!str) return false;
|
||||
return /<[:_-\w\s\!\/\=\"\']+>/i.test(str);
|
||||
},
|
||||
|
||||
// rules are provided to find the place where the snippet should be inserted.
|
||||
// the main problem is that on the server side it can be tricky to determine if a string will be valid html on the client.
|
||||
// the function `fn` of the first `match` is executed like this `body.replace(rule.match, rule.fn);`
|
||||
// the function `fn` has got the arguments `fn(w, s)` where `w` is the matches string and `s` is the snippet.
|
||||
rules: [{
|
||||
match: /<\/body>(?![\s\S]*<\/body>)/i,
|
||||
fn: prepend
|
||||
}, {
|
||||
match: /<\/html>(?![\s\S]*<\/html>)/i,
|
||||
fn: prepend
|
||||
}, {
|
||||
match: /<\!DOCTYPE.+?>/i,
|
||||
fn: append
|
||||
}],
|
||||
|
||||
// port where the script is loaded
|
||||
port: 35729,
|
||||
|
||||
// location where the script is provided (not by connect-livereload). Change this e.g. when serving livereload with a proxy.
|
||||
src: "http://localhost:35729/livereload.js?snipver=1",
|
||||
|
||||
// Set this option to `true` to set `req.headers['accept-encoding']` to 'identity' (disabling compression)
|
||||
disableCompression: false
|
||||
}));
|
||||
|
||||
function prepend(w: string, s: string): string {
|
||||
return s + w;
|
||||
}
|
||||
function append(w: string, s: string): string {
|
||||
return w + s;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Type definitions for connect-livereload v0.5.3
|
||||
// Project: https://github.com/intesso/connect-livereload
|
||||
// Definitions by: Maxime LUCE <https://github.com/SomaticIT/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../connect/connect.d.ts" />
|
||||
|
||||
declare module "connect-livereload" {
|
||||
import { HandleFunction } from "connect";
|
||||
|
||||
function livereload(): HandleFunction;
|
||||
function livereload(options: livereload.Options): HandleFunction;
|
||||
|
||||
module livereload {
|
||||
export type FileMatcher = string | RegExp;
|
||||
|
||||
export interface Rule {
|
||||
match: RegExp;
|
||||
fn: (w: string, s: string) => string;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
ignore?: FileMatcher[];
|
||||
excludeList?: FileMatcher[];
|
||||
|
||||
include?: FileMatcher[];
|
||||
html?: (val: string) => boolean;
|
||||
rules?: Rule[];
|
||||
disableCompression?: boolean;
|
||||
|
||||
hostname?: string;
|
||||
port?: number;
|
||||
src?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export = livereload;
|
||||
}
|
||||
Reference in New Issue
Block a user