mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 05:20:24 +08:00
Merge remote-tracking branch 'upstream/master'
Conflicts: jquery/jquery.d.ts
This commit is contained in:
744
d3/d3-tests.ts
744
d3/d3-tests.ts
@@ -1,129 +1,615 @@
|
||||
/// <reference path="d3.d.ts" />
|
||||
|
||||
d3.selectAll("p").style("color", "white");
|
||||
d3.select("body").style("background-color", "black");
|
||||
d3.selectAll("p").style("color", function () {
|
||||
return "hsl(" + Math.random() * 360 + ",100%,50%)";
|
||||
});
|
||||
d3.selectAll("p").style("color", function (d, i) {
|
||||
return i % 2 ? "#fff" : "#eee";
|
||||
});
|
||||
d3.selectAll("p")
|
||||
.data([4, 8, 15, 16, 23, 42])
|
||||
.style("font-size", function (d) { return d + "px"; });
|
||||
d3.select("body").selectAll("p")
|
||||
.data([4, 8, 15, 16, 23, 42])
|
||||
.enter().append("p")
|
||||
.text(function (d) { return "I<>m number " + d + "!"; });
|
||||
var p = d3.select("body").selectAll("p")
|
||||
.data([4, 8, 15, 16, 23, 42])
|
||||
.text(String);
|
||||
p.enter().append("p")
|
||||
.text(String);
|
||||
p.exit().remove();
|
||||
d3.select("body").transition()
|
||||
.style("background-color", "black");
|
||||
d3.selectAll("circle").transition()
|
||||
.duration(750)
|
||||
.delay(function (d, i) { return i * 10; })
|
||||
.attr("r", function (d) { return Math.sqrt(d * scale); });
|
||||
|
||||
function testOrdinalScale() {
|
||||
var x = d3.scale.ordinal().range(["foo", "bar"]);
|
||||
x.domain([0, 1]);
|
||||
var result = x(0);
|
||||
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangePoints([120, 0]);
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangePoints([120, 0], 1);
|
||||
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangeBands([120, 0]);
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangeBands([120, 0], .2);
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangeBands([120, 0], .2, .1);
|
||||
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangeRoundBands([0, 100]);
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangeRoundBands([0, 100], .2);
|
||||
var x = d3.scale.ordinal().domain(["a", "b", "c"]).rangeRoundBands([120, 0], .2, .1);
|
||||
}
|
||||
|
||||
|
||||
function testKeys() {
|
||||
var x = d3.keys({ a: 1, b: 1 });
|
||||
|
||||
function abc() {
|
||||
this.a = 1;
|
||||
this.b = 2;
|
||||
}
|
||||
var x = d3.keys(new abc());
|
||||
}
|
||||
|
||||
function testSVGArc() {
|
||||
var a = d3.svg.arc().innerRadius(100).outerRadius(200);
|
||||
var a = d3.svg.arc().outerRadius(100).startAngle(0).endAngle(Math.PI);
|
||||
|
||||
var f = function () => {
|
||||
return 42;
|
||||
}
|
||||
var a = d3.svg.arc().innerRadius(0).outerRadius(f).startAngle(f).endAngle(f() * 2)
|
||||
|
||||
var str = a();
|
||||
var str = a({ outerRadius: 50 });
|
||||
var str = a.outerRadius(100)();
|
||||
var str = a.endAngle(Math.PI / 2)()
|
||||
var str = a({ startAngle: Math.PI / 2 });
|
||||
|
||||
var c = d3.svg.arc().innerRadius(0).outerRadius(100).startAngle(0).endAngle(2 * Math.PI).centroid();
|
||||
var num = c[0];
|
||||
}
|
||||
|
||||
function testPieLayout() {
|
||||
var p = d3.layout.pie().sort(null).value(function (d) { return d.value; });
|
||||
var data = [1, 2, 3, 4];
|
||||
var arcs = p(data);
|
||||
}
|
||||
|
||||
//Example from http://bl.ocks.org/3887235
|
||||
function testPieChart() {
|
||||
var width = 960,
|
||||
height = 500,
|
||||
radius = Math.min(width, height) / 2;
|
||||
|
||||
var color = d3.scale.ordinal()
|
||||
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
|
||||
|
||||
var arc = d3.svg.arc()
|
||||
.outerRadius(radius - 10)
|
||||
.innerRadius(0);
|
||||
|
||||
var pie = d3.layout.pie()
|
||||
.sort(null)
|
||||
.value(function (d) { return d.population; });
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
|
||||
|
||||
d3.csv("data.csv", function (error, data) {
|
||||
|
||||
data.forEach(function (d) {
|
||||
d.population = +d.population;
|
||||
});
|
||||
|
||||
var g = svg.selectAll(".arc")
|
||||
.data(pie(data))
|
||||
.enter().append("g")
|
||||
.attr("class", "arc");
|
||||
|
||||
g.append("path")
|
||||
.attr("d", arc)
|
||||
.style("fill", function (d) { return color(d.data.age); });
|
||||
|
||||
g.append("text")
|
||||
.attr("transform", function (d) { return "translate(" + arc.centroid(d) + ")"; })
|
||||
.attr("dy", ".35em")
|
||||
.style("text-anchor", "middle")
|
||||
.text(function (d) { return d.data.age; });
|
||||
|
||||
});
|
||||
}
|
||||
/// <reference path="d3.d.ts" />
|
||||
|
||||
//Example from http://bl.ocks.org/3887235
|
||||
function testPieChart() {
|
||||
var width = 960,
|
||||
height = 500,
|
||||
radius = Math.min(width, height) / 2;
|
||||
|
||||
var color = d3.scale.ordinal()
|
||||
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
|
||||
|
||||
var arc = d3.svg.arc()
|
||||
.outerRadius(radius - 10)
|
||||
.innerRadius(0);
|
||||
|
||||
var pie = d3.layout.pie()
|
||||
.sort(null)
|
||||
.value(function (d) { return d.population; });
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
|
||||
|
||||
d3.csv("data.csv", function (error, data) {
|
||||
|
||||
data.forEach(function (d) {
|
||||
d.population = +d.population;
|
||||
});
|
||||
|
||||
var g = svg.selectAll(".arc")
|
||||
.data(pie(data))
|
||||
.enter().append("g")
|
||||
.attr("class", "arc");
|
||||
|
||||
g.append("path")
|
||||
.attr("d", arc)
|
||||
.style("fill", function (d) { return color(d.data.age); });
|
||||
|
||||
g.append("text")
|
||||
.attr("transform", function (d) { return "translate(" + arc.centroid(d) + ")"; })
|
||||
.attr("dy", ".35em")
|
||||
.style("text-anchor", "middle")
|
||||
.text(function (d) { return d.data.age; });
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//Example from http://bl.ocks.org/3887051
|
||||
function groupedBarChart() => {
|
||||
var margin = { top: 20, right: 20, bottom: 30, left: 40 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
|
||||
var x0 = d3.scale.ordinal()
|
||||
.rangeRoundBands([0, width], .1);
|
||||
|
||||
var x1 = d3.scale.ordinal();
|
||||
|
||||
var y = d3.scale.linear()
|
||||
.range([height, 0]);
|
||||
|
||||
var color = d3.scale.ordinal()
|
||||
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
|
||||
|
||||
var xAxis = d3.svg.axis()
|
||||
.scale(x0)
|
||||
.orient("bottom");
|
||||
|
||||
var yAxis = d3.svg.axis()
|
||||
.scale(y)
|
||||
.orient("left")
|
||||
.tickFormat(d3.format(".2s"));
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
d3.csv("data.csv", function (error, data) {
|
||||
var ageNames = d3.keys(data[0]).filter(function (key) { return key !== "State"; });
|
||||
|
||||
data.forEach(function (d) {
|
||||
d.ages = ageNames.map(function (name) { return { name: name, value: +d[name] }; });
|
||||
});
|
||||
|
||||
x0.domain(data.map(function (d) { return d.State; }));
|
||||
x1.domain(ageNames).rangeRoundBands([0, x0.rangeBand()]);
|
||||
y.domain([0, d3.max(data, function (d) { return d3.max(d.ages, function (d) { return d.value; }); })]);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0," + height + ")")
|
||||
.call(xAxis);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis)
|
||||
.append("text")
|
||||
.attr("transform", "rotate(-90)")
|
||||
.attr("y", 6)
|
||||
.attr("dy", ".71em")
|
||||
.style("text-anchor", "end")
|
||||
.text("Population");
|
||||
|
||||
var state = svg.selectAll(".state")
|
||||
.data(data)
|
||||
.enter().append("g")
|
||||
.attr("class", "g")
|
||||
.attr("transform", function (d) { return "translate(" + x0(d.State) + ",0)"; });
|
||||
|
||||
state.selectAll("rect")
|
||||
.data(function (d) { return d.ages; })
|
||||
.enter().append("rect")
|
||||
.attr("width", x1.rangeBand())
|
||||
.attr("x", function (d) { return x1(d.name); })
|
||||
.attr("y", function (d) { return y(d.value); })
|
||||
.attr("height", function (d) { return height - y(d.value); })
|
||||
.style("fill", function (d) { return color(d.name); });
|
||||
|
||||
var legend = svg.selectAll(".legend")
|
||||
.data(ageNames.reverse())
|
||||
.enter().append("g")
|
||||
.attr("class", "legend")
|
||||
.attr("transform", function (d, i) { return "translate(0," + i * 20 + ")"; });
|
||||
|
||||
legend.append("rect")
|
||||
.attr("x", width - 18)
|
||||
.attr("width", 18)
|
||||
.attr("height", 18)
|
||||
.style("fill", color);
|
||||
|
||||
legend.append("text")
|
||||
.attr("x", width - 24)
|
||||
.attr("y", 9)
|
||||
.attr("dy", ".35em")
|
||||
.style("text-anchor", "end")
|
||||
.text(function (d) { return d; });
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//Example from http://bl.ocks.org/3886208
|
||||
function stackedBarChart() {
|
||||
var margin = { top: 20, right: 20, bottom: 30, left: 40 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
|
||||
var x = d3.scale.ordinal()
|
||||
.rangeRoundBands([0, width], .1);
|
||||
|
||||
var y = d3.scale.linear()
|
||||
.rangeRound([height, 0]);
|
||||
|
||||
var color = d3.scale.ordinal()
|
||||
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
|
||||
|
||||
var xAxis = d3.svg.axis()
|
||||
.scale(x)
|
||||
.orient("bottom");
|
||||
|
||||
var yAxis = d3.svg.axis()
|
||||
.scale(y)
|
||||
.orient("left")
|
||||
.tickFormat(d3.format(".2s"));
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
d3.csv("data.csv", function (error, data) {
|
||||
color.domain(d3.keys(data[0]).filter(function (key) { return key !== "State"; }));
|
||||
|
||||
data.forEach(function (d) {
|
||||
var y0 = 0;
|
||||
d.ages = color.domain().map(function (name) { return { name: name, y0: y0, y1: y0 += +d[name] }; });
|
||||
d.total = d.ages[d.ages.length - 1].y1;
|
||||
});
|
||||
|
||||
data.sort(function (a, b) { return b.total - a.total; });
|
||||
|
||||
x.domain(data.map(function (d) { return d.State; }));
|
||||
y.domain([0, d3.max(data, function (d) { return d.total; })]);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0," + height + ")")
|
||||
.call(xAxis);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis)
|
||||
.append("text")
|
||||
.attr("transform", "rotate(-90)")
|
||||
.attr("y", 6)
|
||||
.attr("dy", ".71em")
|
||||
.style("text-anchor", "end")
|
||||
.text("Population");
|
||||
|
||||
var state = svg.selectAll(".state")
|
||||
.data(data)
|
||||
.enter().append("g")
|
||||
.attr("class", "g")
|
||||
.attr("transform", function (d) { return "translate(" + x(d.State) + ",0)"; });
|
||||
|
||||
state.selectAll("rect")
|
||||
.data(function (d) { return d.ages; })
|
||||
.enter().append("rect")
|
||||
.attr("width", x.rangeBand())
|
||||
.attr("y", function (d) { return y(d.y1); })
|
||||
.attr("height", function (d) { return y(d.y0) - y(d.y1); })
|
||||
.style("fill", function (d) { return color(d.name); });
|
||||
|
||||
var legend = svg.selectAll(".legend")
|
||||
.data(color.domain().reverse())
|
||||
.enter().append("g")
|
||||
.attr("class", "legend")
|
||||
.attr("transform", function (d, i) { return "translate(0," + i * 20 + ")"; });
|
||||
|
||||
legend.append("rect")
|
||||
.attr("x", width - 18)
|
||||
.attr("width", 18)
|
||||
.attr("height", 18)
|
||||
.style("fill", color);
|
||||
|
||||
legend.append("text")
|
||||
.attr("x", width - 24)
|
||||
.attr("y", 9)
|
||||
.attr("dy", ".35em")
|
||||
.style("text-anchor", "end")
|
||||
.text(function (d) { return d; });
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// example from http://bl.ocks.org/3886394
|
||||
function normalizedBarChart() {
|
||||
var margin = { top: 20, right: 100, bottom: 30, left: 40 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
|
||||
var x = d3.scale.ordinal()
|
||||
.rangeRoundBands([0, width], .1);
|
||||
|
||||
var y = d3.scale.linear()
|
||||
.rangeRound([height, 0]);
|
||||
|
||||
var color = d3.scale.ordinal()
|
||||
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
|
||||
|
||||
var xAxis = d3.svg.axis()
|
||||
.scale(x)
|
||||
.orient("bottom");
|
||||
|
||||
var yAxis = d3.svg.axis()
|
||||
.scale(y)
|
||||
.orient("left")
|
||||
.tickFormat(d3.format(".0%"));
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
d3.csv("data.csv", function (error, data) {
|
||||
color.domain(d3.keys(data[0]).filter(function (key) { return key !== "State"; }));
|
||||
|
||||
data.forEach(function (d) {
|
||||
var y0 = 0;
|
||||
d.ages = color.domain().map(function (name) { return { name: name, y0: y0, y1: y0 += +d[name] }; });
|
||||
d.ages.forEach(function (d) { d.y0 /= y0; d.y1 /= y0; });
|
||||
});
|
||||
|
||||
data.sort(function (a, b) { return b.ages[0].y1 - a.ages[0].y1; });
|
||||
|
||||
x.domain(data.map(function (d) { return d.State; }));
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0," + height + ")")
|
||||
.call(xAxis);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis);
|
||||
|
||||
var state = svg.selectAll(".state")
|
||||
.data(data)
|
||||
.enter().append("g")
|
||||
.attr("class", "state")
|
||||
.attr("transform", function (d) { return "translate(" + x(d.State) + ",0)"; });
|
||||
|
||||
state.selectAll("rect")
|
||||
.data(function (d) { return d.ages; })
|
||||
.enter().append("rect")
|
||||
.attr("width", x.rangeBand())
|
||||
.attr("y", function (d) { return y(d.y1); })
|
||||
.attr("height", function (d) { return y(d.y0) - y(d.y1); })
|
||||
.style("fill", function (d) { return color(d.name); });
|
||||
|
||||
var legend = svg.select(".state:last-child").selectAll(".legend")
|
||||
.data(function (d) { return d.ages; })
|
||||
.enter().append("g")
|
||||
.attr("class", "legend")
|
||||
.attr("transform", function (d) { return "translate(" + x.rangeBand() / 2 + "," + y((d.y0 + d.y1) / 2) + ")"; });
|
||||
|
||||
legend.append("line")
|
||||
.attr("x2", 10);
|
||||
|
||||
legend.append("text")
|
||||
.attr("x", 13)
|
||||
.attr("dy", ".35em")
|
||||
.text(function (d) { return d.name; });
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// example from http://bl.ocks.org/3885705
|
||||
function sortablebarChart() {
|
||||
var margin = { top: 20, right: 20, bottom: 30, left: 40 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
|
||||
var formatPercent = d3.format(".0%");
|
||||
|
||||
var x = d3.scale.ordinal()
|
||||
.rangeRoundBands([0, width], .1, 1);
|
||||
|
||||
var y = d3.scale.linear()
|
||||
.range([height, 0]);
|
||||
|
||||
var xAxis = d3.svg.axis()
|
||||
.scale(x)
|
||||
.orient("bottom");
|
||||
|
||||
var yAxis = d3.svg.axis()
|
||||
.scale(y)
|
||||
.orient("left")
|
||||
.tickFormat(formatPercent);
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
d3.tsv("data.tsv", function (error, data) {
|
||||
|
||||
data.forEach(function (d) {
|
||||
d.frequency = +d.frequency;
|
||||
});
|
||||
|
||||
x.domain(data.map(function (d) { return d.letter; }));
|
||||
y.domain([0, d3.max(data, function (d) { return d.frequency; })]);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0," + height + ")")
|
||||
.call(xAxis);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis)
|
||||
.append("text")
|
||||
.attr("transform", "rotate(-90)")
|
||||
.attr("y", 6)
|
||||
.attr("dy", ".71em")
|
||||
.style("text-anchor", "end")
|
||||
.text("Frequency");
|
||||
|
||||
svg.selectAll(".bar")
|
||||
.data(data)
|
||||
.enter().append("rect")
|
||||
.attr("class", "bar")
|
||||
.attr("x", function (d) { return x(d.letter); })
|
||||
.attr("width", x.rangeBand())
|
||||
.attr("y", function (d) { return y(d.frequency); })
|
||||
.attr("height", function (d) { return height - y(d.frequency); });
|
||||
|
||||
d3.select("input").on("change", change);
|
||||
|
||||
var sortTimeout = setTimeout(function () {
|
||||
d3.select("input").property("checked", true).each(change);
|
||||
}, 2000);
|
||||
|
||||
function change() {
|
||||
clearTimeout(sortTimeout);
|
||||
|
||||
var x0 = x.domain(data.sort(this.checked
|
||||
? function (a, b) { return b.frequency - a.frequency; }
|
||||
: function (a, b) { return d3.ascending(a.letter, b.letter); })
|
||||
.map(function (d) { return d.letter; }))
|
||||
.copy();
|
||||
|
||||
var transition = svg.transition().duration(750),
|
||||
delay = function (d, i) { return i * 50; };
|
||||
|
||||
transition.selectAll(".bar")
|
||||
.delay(delay)
|
||||
.attr("x", function (d) { return x0(d.letter); });
|
||||
|
||||
transition.select(".x.axis")
|
||||
.call(xAxis)
|
||||
.selectAll("g")
|
||||
.delay(delay);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//example from http://bl.ocks.org/4063318
|
||||
function callenderView() {
|
||||
var width = 960,
|
||||
height = 136,
|
||||
cellSize = 17; // cell size
|
||||
|
||||
var day = d3.time.format("%w"),
|
||||
week = d3.time.format("%U"),
|
||||
percent = d3.format(".1%"),
|
||||
format = d3.time.format("%Y-%m-%d");
|
||||
|
||||
var color = d3.scale.quantize()
|
||||
.domain([-.05, .05])
|
||||
.range(d3.range(11).map(function (d) { return "q" + d + "-11"; }));
|
||||
|
||||
var svg = d3.select("body").selectAll("svg")
|
||||
.data(d3.range(1990, 2011))
|
||||
.enter().append("svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.attr("class", "RdYlGn")
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");
|
||||
|
||||
svg.append("text")
|
||||
.attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
|
||||
.style("text-anchor", "middle")
|
||||
.text(function (d) { return d; });
|
||||
|
||||
var rect = svg.selectAll(".day")
|
||||
.data(function (d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
|
||||
.enter().append("rect")
|
||||
.attr("class", "day")
|
||||
.attr("width", cellSize)
|
||||
.attr("height", cellSize)
|
||||
.attr("x", function (d) { return parseInt(week(d)) * cellSize; })
|
||||
.attr("y", function (d) { return parseInt(day(d)) * cellSize; })
|
||||
.datum(format);
|
||||
|
||||
rect.append("title")
|
||||
.text(function (d) { return d; });
|
||||
|
||||
svg.selectAll(".month")
|
||||
.data(function (d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
|
||||
.enter().append("path")
|
||||
.attr("class", "month")
|
||||
.attr("d", monthPath);
|
||||
|
||||
d3.csv("dji.csv", function (error, csv) {
|
||||
var data = d3.nest()
|
||||
.key(function (d) { return d.Date; })
|
||||
.rollup(function (d) { return (d[0].Close - d[0].Open) / d[0].Open; })
|
||||
.map(csv);
|
||||
|
||||
rect.filter(function (d) { return d in data; })
|
||||
.attr("class", function (d) { return "day " + color(data[d]); })
|
||||
.select("title")
|
||||
.text(function (d) { return d + ": " + percent(data[d]); });
|
||||
});
|
||||
|
||||
function monthPath(t0) {
|
||||
var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
|
||||
d0 = +day(t0), w0 = +week(t0),
|
||||
d1 = +day(t1), w1 = +week(t1);
|
||||
return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize
|
||||
+ "H" + w0 * cellSize + "V" + 7 * cellSize
|
||||
+ "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize
|
||||
+ "H" + (w1 + 1) * cellSize + "V" + 0
|
||||
+ "H" + (w0 + 1) * cellSize + "Z";
|
||||
}
|
||||
|
||||
d3.select(self.frameElement).style("height", "2910px");
|
||||
}
|
||||
|
||||
// example from http://bl.ocks.org/3883245
|
||||
function lineChart {
|
||||
var margin = { top: 20, right: 20, bottom: 30, left: 50 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
|
||||
var parseDate = d3.time.format("%d-%b-%y").parse;
|
||||
|
||||
var x = d3.time.scale()
|
||||
.range([0, width]);
|
||||
|
||||
var y = d3.scale.linear()
|
||||
.range([height, 0]);
|
||||
|
||||
var xAxis = d3.svg.axis()
|
||||
.scale(x)
|
||||
.orient("bottom");
|
||||
|
||||
var yAxis = d3.svg.axis()
|
||||
.scale(y)
|
||||
.orient("left");
|
||||
|
||||
var line = d3.svg.line()
|
||||
.x(function (d) { return x(d.date); })
|
||||
.y(function (d) { return y(d.close); });
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
d3.tsv("data.tsv", function (error, data) {
|
||||
data.forEach(function (d) {
|
||||
d.date = parseDate(d.date);
|
||||
d.close = +d.close;
|
||||
});
|
||||
|
||||
x.domain(d3.extent(data, function (d) { return d.date; }));
|
||||
y.domain(d3.extent(data, function (d) { return d.close; }));
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0," + height + ")")
|
||||
.call(xAxis);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis)
|
||||
.append("text")
|
||||
.attr("transform", "rotate(-90)")
|
||||
.attr("y", 6)
|
||||
.attr("dy", ".71em")
|
||||
.style("text-anchor", "end")
|
||||
.text("Price ($)");
|
||||
|
||||
svg.append("path")
|
||||
.datum(data)
|
||||
.attr("class", "line")
|
||||
.attr("d", line);
|
||||
});
|
||||
}
|
||||
|
||||
//example from http://bl.ocks.org/3884914
|
||||
function bivariateAreaChart {
|
||||
var margin = { top: 20, right: 20, bottom: 30, left: 50 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
|
||||
var parseDate = d3.time.format("%Y%m%d").parse;
|
||||
|
||||
var x = d3.time.scale()
|
||||
.range([0, width]);
|
||||
|
||||
var y = d3.scale.linear()
|
||||
.range([height, 0]);
|
||||
|
||||
var xAxis = d3.svg.axis()
|
||||
.scale(x)
|
||||
.orient("bottom");
|
||||
|
||||
var yAxis = d3.svg.axis()
|
||||
.scale(y)
|
||||
.orient("left");
|
||||
|
||||
var area = d3.svg.area()
|
||||
.x(function (d) { return x(d.date); })
|
||||
.y0(function (d) { return y(d.low); })
|
||||
.y1(function (d) { return y(d.high); });
|
||||
|
||||
var svg = d3.select("body").append("svg")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
d3.tsv("data.tsv", function (error, data) {
|
||||
data.forEach(function (d) {
|
||||
d.date = parseDate(d.date);
|
||||
d.low = +d.low;
|
||||
d.high = +d.high;
|
||||
});
|
||||
|
||||
x.domain(d3.extent(data, function (d) { return d.date; }));
|
||||
y.domain([d3.min(data, function (d) { return d.low; }), d3.max(data, function (d) { return d.high; })]);
|
||||
|
||||
svg.append("path")
|
||||
.datum(data)
|
||||
.attr("class", "area")
|
||||
.attr("d", area);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0," + height + ")")
|
||||
.call(xAxis);
|
||||
|
||||
svg.append("g")
|
||||
.attr("class", "y axis")
|
||||
.call(yAxis)
|
||||
.append("text")
|
||||
.attr("transform", "rotate(-90)")
|
||||
.attr("y", 6)
|
||||
.attr("dy", ".71em")
|
||||
.style("text-anchor", "end")
|
||||
.text("Temperature (<28>F)");
|
||||
});
|
||||
}
|
||||
|
||||
1114
d3/d3.d.ts
vendored
1114
d3/d3.d.ts
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2054
express/express.d.ts
vendored
2054
express/express.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1282
jquery.bbq/jquery.bbq-tests.ts
Normal file
1282
jquery.bbq/jquery.bbq-tests.ts
Normal file
File diff suppressed because it is too large
Load Diff
168
jquery.bbq/jquery.bbq.d.ts
vendored
168
jquery.bbq/jquery.bbq.d.ts
vendored
@@ -1,42 +1,160 @@
|
||||
// Type definitions for jquery.bbq 1.2
|
||||
// Project: http://benalman.com/projects/jquery-bbq-plugin/
|
||||
// Definitions by: https://github.com/sunetos
|
||||
// Definitions by: Adam R. Smith <https://github.com/sunetos>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface JQueryBBQ {
|
||||
pushState(params?: any, merge_mode?: number): void;
|
||||
getState(key?: string, coerce?: bool): any;
|
||||
removeState(...key: any[]): void;
|
||||
/// <reference path="../jquery/jquery.d.ts" />
|
||||
|
||||
module JQueryBbq {
|
||||
|
||||
interface JQuery {
|
||||
/**
|
||||
* Adds a 'state' into the browser history at the current position, setting
|
||||
* location.hash and triggering any bound <hashchange event> callbacks
|
||||
* (provided the new state is different than the previous state).
|
||||
*
|
||||
* @name params A serialized params string or a hash string beginning with # to merge into location.hash.
|
||||
* @name merge_mode Merge behavior defaults to 0 if merge_mode is not specified (unless a hash string beginning with # is specified, in which case merge behavior defaults to 2)
|
||||
*/
|
||||
pushState(params?: string, merge_mode?: number): void;
|
||||
|
||||
pushState(params?: any, merge_mode?: number): void;
|
||||
|
||||
/**
|
||||
* Retrieves the current 'state' from the browser history, parsing
|
||||
* location.hash for a specific key or returning an object containing the
|
||||
* entire state, optionally coercing numbers, booleans, null and undefined
|
||||
* values.
|
||||
*
|
||||
* @name key An optional state key for which to return a value.
|
||||
* @name coerce If true, coerces any numbers or true, false, null, and undefined to their actual value. Defaults to false
|
||||
*/
|
||||
getState(key?: string, coerce?: bool): any;
|
||||
|
||||
getState(coerce?: bool): any;
|
||||
|
||||
/**
|
||||
* Remove one or more keys from the current browser history 'state', creating
|
||||
* a new state, setting location.hash and triggering any bound
|
||||
* <hashchange event> callbacks (provided the new state is different than
|
||||
* the previous state).
|
||||
*
|
||||
* @name key One or more key values to remove from the current state.
|
||||
*/
|
||||
removeState(...key: any[]): void;
|
||||
}
|
||||
|
||||
interface ParamFragment {
|
||||
(url?: string): string;
|
||||
|
||||
(url: string, params: any, merge_mode?: number): string;
|
||||
|
||||
/**
|
||||
* Specify characters that will be left unescaped when fragments are created
|
||||
* or merged using <jQuery.param.fragment>, or when the fragment is modified
|
||||
* using <jQuery.bbq.pushState>. This option only applies to serialized data
|
||||
* object fragments, and not set-as-string fragments. Does not affect the
|
||||
* query string. Defaults to ",/" (comma, forward slash).
|
||||
*
|
||||
* @name chars The characters to not escape in the fragment. If unspecified, defaults to empty string (escape all characters).
|
||||
*/
|
||||
noEscape: (chars?: string) => void;
|
||||
|
||||
/**
|
||||
* TODO: DESCRIBE
|
||||
*
|
||||
* @name state TODO: DESCRIBE
|
||||
*/
|
||||
ajaxCrawlable(state?: bool): bool;
|
||||
}
|
||||
|
||||
interface JQueryDeparam {
|
||||
/**
|
||||
* Deserialize a params string into an object, optionally coercing numbers,
|
||||
* booleans, null and undefined values; this method is the counterpart to the
|
||||
* internal jQuery.param method.
|
||||
*
|
||||
* @name params A params string to be parsed.
|
||||
* @name coerce If true, coerces any numbers or true, false, null, and undefined to their actual value. Defaults to false if omitted.
|
||||
*/
|
||||
(params: string, coerce?: bool): any;
|
||||
|
||||
|
||||
/**
|
||||
* Parse the query string from a URL or the current window.location.href,
|
||||
* deserializing it into an object, optionally coercing numbers, booleans,
|
||||
* null and undefined values.
|
||||
*
|
||||
* @name url An optional params string or URL containing query string params to be parsed. If url is omitted, the current window.location.href is used.
|
||||
* @name coerce If true, coerces any numbers or true, false, null, and undefined to their actual value. Defaults to false if omitted.
|
||||
*/
|
||||
querystring(url?: string, coerce?: bool): any;
|
||||
|
||||
/**
|
||||
* Parse the fragment (hash) from a URL or the current window.location.href,
|
||||
* deserializing it into an object, optionally coercing numbers, booleans,
|
||||
* null and undefined values.
|
||||
*
|
||||
* @name url An optional params string or URL containing fragment (hash) params to be parsed. If url is omitted, the current window.location.href is used.
|
||||
* @name coerce If true, coerces any numbers or true, false, null, and undefined to their actual value. Defaults to false if omitted.
|
||||
*/
|
||||
fragment(url?: string, coerce?: bool): any;
|
||||
}
|
||||
|
||||
interface EventObject extends JQueryEventObject {
|
||||
fragment: string;
|
||||
|
||||
getState( key?: string, coerce? :bool );
|
||||
}
|
||||
}
|
||||
|
||||
interface JQueryParam {
|
||||
(obj: any): string;
|
||||
(obj: any, traditional: bool): string;
|
||||
/**
|
||||
* Parse the query string from a URL or the current window.location.href,
|
||||
* deserializing it into an object, optionally coercing numbers, booleans,
|
||||
* null and undefined values.
|
||||
*
|
||||
* @name url An optional params string or URL containing query string params to be parsed. If url is omitted, the current window.location.href is used.
|
||||
* @name coerce (Boolean) If true, coerces any numbers or true, false, null, and undefined to their actual value. Defaults to false if omitted.
|
||||
* @name merge_mode An object representing the deserialized params string.
|
||||
*/
|
||||
querystring(url?: string, coerce?: bool, merge_mode?: number): string;
|
||||
|
||||
querystring(url?: string): string;
|
||||
querystring(url: string, params: any, merge_mode?: number): string;
|
||||
fragment: {
|
||||
noEscape: (chars?: string) => void;
|
||||
(url?: string): string;
|
||||
(url: string, params: any, merge_mode?: number): string;
|
||||
};
|
||||
}
|
||||
querystring(url?: string, coerce?: any, merge_mode?: number): string;
|
||||
|
||||
interface JQueryDeparam {
|
||||
(params: string, coerce?: bool): any;
|
||||
querystring(url?: string, coerce?: bool): any;
|
||||
fragment(url?: string, coerce?: bool): any;
|
||||
fragment: JQueryBbq.ParamFragment;
|
||||
|
||||
/**
|
||||
* Returns a params string equivalent to that returned by the internal
|
||||
* jQuery.param method, but sorted, which makes it suitable for use as a
|
||||
* cache key.
|
||||
*
|
||||
* @name obj An object to be serialized.
|
||||
* @name traditional Params deep/shallow serialization mode. See the documentation at http://api.jquery.com/jQuery.param/ for more detail.
|
||||
*/
|
||||
sorted(obj: any, traditional?: bool): string;
|
||||
}
|
||||
|
||||
interface JQueryStatic {
|
||||
bbq: JQueryBBQ;
|
||||
param: JQueryParam;
|
||||
deparam: JQueryDeparam;
|
||||
bbq: JQueryBbq.JQuery;
|
||||
|
||||
elemUrlAttr(tag_attr: any): any;
|
||||
deparam: JQueryBbq.JQueryDeparam;
|
||||
|
||||
/**
|
||||
* Get the internal "Default URL attribute per tag" list, or augment the list
|
||||
* with additional tag-attribute pairs, in case the defaults are insufficient.
|
||||
*
|
||||
* @name tag_attr An object containing a list of tag names and their associated default attribute names in the format { tag: 'attr', ... } to be merged into the internal tag-attribute list.
|
||||
*/
|
||||
elemUrlAttr(tag_attr?: any): any;
|
||||
}
|
||||
|
||||
interface JQuery {
|
||||
querystring(attr?: any, params?: any, merge_mode?: number): JQuery;
|
||||
fragment(attr?: any, params?: any, merge_mode?: number): JQuery;
|
||||
querystring(attr?: any, params?: any, merge_mode?: number): JQuery;
|
||||
|
||||
fragment(attr?: any, params?: any, merge_mode?: number): JQuery;
|
||||
|
||||
hashchange(eventData?: any, handler?: (eventObject: JQueryBbq.EventObject) => any): JQuery;
|
||||
|
||||
hashchange(handler: (eventObject: JQueryBbq.EventObject) => any): JQuery;
|
||||
}
|
||||
|
||||
23
jquery/jquery.d.ts
vendored
23
jquery/jquery.d.ts
vendored
@@ -185,6 +185,11 @@ interface JQuerySupport {
|
||||
tbody?: bool;
|
||||
}
|
||||
|
||||
interface JQueryParam {
|
||||
(obj: any): string;
|
||||
(obj: any, traditional: bool): string;
|
||||
}
|
||||
|
||||
/*
|
||||
Static members of jQuery (those on $ and jQuery themselves)
|
||||
*/
|
||||
@@ -208,8 +213,7 @@ interface JQueryStatic {
|
||||
getJSON(url: string, data?: any, success?: any): JQueryXHR;
|
||||
getScript(url: string, success?: any): JQueryXHR;
|
||||
|
||||
param(obj: any): string;
|
||||
param(obj: any, traditional: bool): string;
|
||||
param: JQueryParam;
|
||||
|
||||
post(url: string, data?: any, success?: any, dataType?: any): JQueryXHR;
|
||||
|
||||
@@ -296,6 +300,9 @@ interface JQueryStatic {
|
||||
contains(container: Element, contained: Element): bool;
|
||||
|
||||
each(collection: any, callback: (indexInArray: any, valueOfElement: any) => any): any;
|
||||
each(collection: JQuery, callback: (indexInArray: number, valueOfElement: HTMLElement) => any): any;
|
||||
each(collection: string[], callback: (indexInArray: number, valueOfElement: string) => any): any;
|
||||
each(collection: number[], callback: (indexInArray: number, valueOfElement: number) => any): any;
|
||||
|
||||
extend(target: any, ...objs: any[]): Object;
|
||||
extend(deep: bool, target: any, ...objs: any[]): Object;
|
||||
@@ -375,7 +382,7 @@ interface JQuery {
|
||||
html(htmlString: string): JQuery;
|
||||
html(htmlContent: (index: number, oldhtml: string) => string): JQuery;
|
||||
|
||||
prop(propertyName: string): any;
|
||||
prop(propertyName: string): string;
|
||||
prop(propertyName: string, value: any): JQuery;
|
||||
prop(map: any): JQuery;
|
||||
prop(propertyName: string, func: (index: any, oldPropertyValue: any) => any): JQuery;
|
||||
@@ -400,11 +407,11 @@ interface JQuery {
|
||||
/***
|
||||
CSS
|
||||
****/
|
||||
css(propertyName: string): any;
|
||||
css(propertyNames: string[]): any;
|
||||
css(properties: any): any;
|
||||
css(propertyName: string, value: any): any;
|
||||
css(propertyName: any, value: any): any;
|
||||
css(propertyName: string): string;
|
||||
css(propertyNames: string[]): string;
|
||||
css(properties: any): JQuery;
|
||||
css(propertyName: string, value: any): JQuery;
|
||||
css(propertyName: any, value: any): JQuery;
|
||||
|
||||
height(): number;
|
||||
height(value: number): JQuery;
|
||||
|
||||
564
qunit/qunit.d.ts
vendored
564
qunit/qunit.d.ts
vendored
@@ -5,44 +5,127 @@
|
||||
|
||||
|
||||
interface DoneCallbackObject {
|
||||
/**
|
||||
* The number of failed assertions
|
||||
*/
|
||||
failed: number;
|
||||
|
||||
/**
|
||||
* The number of passed assertions
|
||||
*/
|
||||
passed: number;
|
||||
|
||||
/**
|
||||
* The total number of assertions
|
||||
*/
|
||||
total: number;
|
||||
|
||||
/**
|
||||
* The time in milliseconds it took tests to run from start to finish.
|
||||
*/
|
||||
runtime: number;
|
||||
}
|
||||
|
||||
interface LogCallbackObject {
|
||||
/**
|
||||
* The boolean result of an assertion, true means passed, false means failed.
|
||||
*/
|
||||
result: bool;
|
||||
|
||||
/**
|
||||
* One side of a comparision assertion. Can be undefined when ok() is used.
|
||||
*/
|
||||
actual: Object;
|
||||
|
||||
/**
|
||||
* One side of a comparision assertion. Can be undefined when ok() is used.
|
||||
*/
|
||||
expected: Object;
|
||||
|
||||
/**
|
||||
* A string description provided by the assertion.
|
||||
*/
|
||||
message: string;
|
||||
|
||||
/**
|
||||
* The associated stacktrace, either from an exception or pointing to the source
|
||||
* of the assertion. Depends on browser support for providing stacktraces, so can be
|
||||
* undefined.
|
||||
*/
|
||||
source: string;
|
||||
}
|
||||
|
||||
interface ModuleStartCallbackObject {
|
||||
/**
|
||||
* Name of the next module to run
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ModuleDoneCallbackObject {
|
||||
/**
|
||||
* Name of this module
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The number of failed assertions
|
||||
*/
|
||||
failed: number;
|
||||
|
||||
/**
|
||||
* The number of passed assertions
|
||||
*/
|
||||
passed: number;
|
||||
|
||||
/**
|
||||
* The total number of assertions
|
||||
*/
|
||||
total: number;
|
||||
}
|
||||
|
||||
interface TestDoneCallbackObject {
|
||||
/**
|
||||
* TName of the next test to run
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Name of the current module
|
||||
*/
|
||||
module: string;
|
||||
|
||||
/**
|
||||
* The number of failed assertions
|
||||
*/
|
||||
failed: number;
|
||||
|
||||
/**
|
||||
* The number of passed assertions
|
||||
*/
|
||||
passed: number;
|
||||
|
||||
/**
|
||||
* The total number of assertions
|
||||
*/
|
||||
total: number;
|
||||
|
||||
/**
|
||||
* The total runtime, including setup and teardown
|
||||
*/
|
||||
duration: number;
|
||||
}
|
||||
|
||||
interface TestStartCallbackObject {
|
||||
/**
|
||||
* Name of the next test to run
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Name of the current module
|
||||
*/
|
||||
module: string;
|
||||
failed: number;
|
||||
passed: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
interface Config {
|
||||
@@ -56,7 +139,14 @@ interface Config {
|
||||
}
|
||||
|
||||
interface LifecycleObject {
|
||||
/**
|
||||
* Runs before each test
|
||||
*/
|
||||
setup?: () => any;
|
||||
|
||||
/**
|
||||
* Runs after each test
|
||||
*/
|
||||
teardown?: () => any;
|
||||
}
|
||||
|
||||
@@ -66,92 +156,554 @@ interface QUnitAssert {
|
||||
current_testEnvironment: any;
|
||||
jsDump: any;
|
||||
|
||||
/**
|
||||
* A deep recursive comparison assertion, working on primitive types, arrays, objects,
|
||||
* regular expressions, dates and functions.
|
||||
*
|
||||
* The deepEqual() assertion can be used just like equal() when comparing the value of
|
||||
* objects, such that { key: value } is equal to { key: value }. For non-scalar values,
|
||||
* identity will be disregarded by deepEqual.
|
||||
*
|
||||
* @param actual Object or Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
deepEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A non-strict comparison assertion, roughly equivalent to JUnit assertEquals.
|
||||
*
|
||||
* The equal assertion uses the simple comparison operator (==) to compare the actual
|
||||
* and expected arguments. When they are equal, the assertion passes; otherwise, it fails.
|
||||
* When it fails, both actual and expected values are displayed in the test result,
|
||||
* in addition to a given message.
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
equal(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* An inverted deep recursive comparison assertion, working on primitive types,
|
||||
* arrays, objects, regular expressions, dates and functions.
|
||||
*
|
||||
* The notDeepEqual() assertion can be used just like equal() when comparing the
|
||||
* value of objects, such that { key: value } is equal to { key: value }. For non-scalar
|
||||
* values, identity will be disregarded by notDeepEqual.
|
||||
*
|
||||
* @param actual Object or Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
notDeepEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A non-strict comparison assertion, checking for inequality.
|
||||
*
|
||||
* The notEqual assertion uses the simple inverted comparison operator (!=) to compare
|
||||
* the actual and expected arguments. When they aren't equal, the assertion passes;
|
||||
* otherwise, it fails. When it fails, both actual and expected values are displayed
|
||||
* in the test result, in addition to a given message.
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
notEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
notPropEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
propEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A non-strict comparison assertion, checking for inequality.
|
||||
*
|
||||
* The notStrictEqual assertion uses the strict inverted comparison operator (!==)
|
||||
* to compare the actual and expected arguments. When they aren't equal, the assertion
|
||||
* passes; otherwise, it fails. When it fails, both actual and expected values are
|
||||
* displayed in the test result, in addition to a given message.
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
notStrictEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A boolean assertion, equivalent to CommonJS’s assert.ok() and JUnit’s assertTrue().
|
||||
* Passes if the first argument is truthy.
|
||||
*
|
||||
* The most basic assertion in QUnit, ok() requires just one argument. If the argument
|
||||
* evaluates to true, the assertion passes; otherwise, it fails. If a second message
|
||||
* argument is provided, it will be displayed in place of the result.
|
||||
*
|
||||
* @param state Expression being tested
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
ok(state: any, message?: string);
|
||||
|
||||
/**
|
||||
* A strict type and value comparison assertion.
|
||||
*
|
||||
* The strictEqual() assertion provides the most rigid comparison of type and value with
|
||||
* the strict equality operator (===)
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
strictEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* Assertion to test if a callback throws an exception when run.
|
||||
*
|
||||
* When testing code that is expected to throw an exception based on a specific set of
|
||||
* circumstances, use throws() to catch the error object for testing and comparison.
|
||||
*
|
||||
* @param block Function to execute
|
||||
* @param expected Error Object to compare
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
throws(block: () => any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* @param block Function to execute
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
throws(block: () => any, message?: string);
|
||||
}
|
||||
|
||||
interface QUnitStatic extends QUnitAssert{
|
||||
/* ASYNC CONTROL */
|
||||
|
||||
/**
|
||||
* Start running tests again after the testrunner was stopped. See stop().
|
||||
*
|
||||
* When your async test has multiple exit points, call start() for the corresponding number of stop() increments.
|
||||
*
|
||||
* @param decrement Optional argument to merge multiple start() calls into one. Use with multiple corrsponding stop() calls.
|
||||
*/
|
||||
start(decrement?: number);
|
||||
|
||||
/**
|
||||
* Stop the testrunner to wait for async tests to run. Call start() to continue.
|
||||
*
|
||||
* When your async test has multiple exit points, call stop() with the increment argument, corresponding to the number of start() calls you need.
|
||||
*
|
||||
* On Blackberry 5.0, window.stop is a native read-only function. If you deal with that browser, use QUnit.stop() instead, which will work anywhere.
|
||||
*
|
||||
* @param decrement Optional argument to merge multiple stop() calls into one. Use with multiple corrsponding start() calls.
|
||||
*/
|
||||
stop(increment? : number);
|
||||
|
||||
/* CALLBACKS */
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever the test suite begins.
|
||||
*
|
||||
* QUnit.begin() is called once before running any tests. (a better would've been QUnit.start,
|
||||
* but thats already in use elsewhere and can't be changed.)
|
||||
*
|
||||
* @param callback Callback to execute
|
||||
*/
|
||||
begin(callback: () => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever the test suite ends.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
done(callback: (details: DoneCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever an assertion completes.
|
||||
*
|
||||
* This is one of several callbacks QUnit provides. Its intended for integration scenarios like
|
||||
* PhantomJS or Jenkins. The properties of the details argument are listed below as options.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
log(callback: (details: LogCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a module ends.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
moduleDone(callback: (details: ModuleDoneCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a module begins.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
moduleStart(callback: (details: ModuleStartCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a test ends.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
testDone(callback: (details: TestDoneCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a test begins.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
testStart(callback: (details: TestStartCallbackObject) => any);
|
||||
|
||||
/* CONFIGURATION */
|
||||
|
||||
/**
|
||||
* QUnit has a bunch of internal configuration defaults, some of which are
|
||||
* useful to override. Check the description for each option for details.
|
||||
*/
|
||||
config: Config;
|
||||
|
||||
/* TEST */
|
||||
|
||||
/**
|
||||
* Add an asynchronous test to run. The test must include a call to start().
|
||||
*
|
||||
* For testing asynchronous code, asyncTest will automatically stop the test runner
|
||||
* and wait for your code to call start() to continue.
|
||||
*
|
||||
* @param name Title of unit being tested
|
||||
* @param expected Number of assertions in this test
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
asyncTest(name: string, expected: number, test: () => any);
|
||||
|
||||
/**
|
||||
* Add an asynchronous test to run. The test must include a call to start().
|
||||
*
|
||||
* For testing asynchronous code, asyncTest will automatically stop the test runner
|
||||
* and wait for your code to call start() to continue.
|
||||
*
|
||||
* @param name Title of unit being tested
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
asyncTest(name: string, test: () => any);
|
||||
|
||||
/**
|
||||
* Specify how many assertions are expected to run within a test.
|
||||
*
|
||||
* To ensure that an explicit number of assertions are run within any test, use
|
||||
* expect( number ) to register an expected count. If the number of assertions
|
||||
* run does not match the expected count, the test will fail.
|
||||
*
|
||||
* @param amount Number of assertions in this test.
|
||||
*/
|
||||
expect(amount: number);
|
||||
|
||||
/**
|
||||
* Group related tests under a single label.
|
||||
*
|
||||
* All tests that occur after a call to module() will be grouped into that module.
|
||||
* The test names will all be preceded by the module name in the test results.
|
||||
* You can then use that module name to select tests to run.
|
||||
*
|
||||
* @param name Label for this group of tests
|
||||
* @param lifecycle Callbacks to run before and after each test
|
||||
*/
|
||||
module(name: string, lifecycle?: LifecycleObject);
|
||||
|
||||
/**
|
||||
* Add a test to run.
|
||||
*
|
||||
* When testing the most common, synchronous code, use test().
|
||||
* The assert argument to the callback contains all of QUnit's assertion methods.
|
||||
* If you are avoiding using any of QUnit's globals, you can use the assert
|
||||
* argument instead.
|
||||
*
|
||||
* @param title Title of unit being tested
|
||||
* @param expected Number of assertions in this test
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
test(title: string, expected: number, test: (assert: QUnitAssert) => any);
|
||||
|
||||
/**
|
||||
* @param title Title of unit being tested
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
test(title: string, test: (assert: QUnitAssert) => any);
|
||||
|
||||
// https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L1568
|
||||
/**
|
||||
* https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L1568
|
||||
*/
|
||||
equiv(a: any, b: any);
|
||||
|
||||
// https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L661
|
||||
raises: any;
|
||||
|
||||
// https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L897
|
||||
/**
|
||||
* https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L897
|
||||
*/
|
||||
push(result, actual, expected, message): any;
|
||||
|
||||
// https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L839
|
||||
/**
|
||||
* https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L839
|
||||
*/
|
||||
reset(): any;
|
||||
}
|
||||
|
||||
/* ASSERT */
|
||||
|
||||
/**
|
||||
* A deep recursive comparison assertion, working on primitive types, arrays, objects,
|
||||
* regular expressions, dates and functions.
|
||||
*
|
||||
* The deepEqual() assertion can be used just like equal() when comparing the value of
|
||||
* objects, such that { key: value } is equal to { key: value }. For non-scalar values,
|
||||
* identity will be disregarded by deepEqual.
|
||||
*
|
||||
* @param actual Object or Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function deepEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A non-strict comparison assertion, roughly equivalent to JUnit assertEquals.
|
||||
*
|
||||
* The equal assertion uses the simple comparison operator (==) to compare the actual
|
||||
* and expected arguments. When they are equal, the assertion passes; otherwise, it fails.
|
||||
* When it fails, both actual and expected values are displayed in the test result,
|
||||
* in addition to a given message.
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function equal(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* An inverted deep recursive comparison assertion, working on primitive types,
|
||||
* arrays, objects, regular expressions, dates and functions.
|
||||
*
|
||||
* The notDeepEqual() assertion can be used just like equal() when comparing the
|
||||
* value of objects, such that { key: value } is equal to { key: value }. For non-scalar
|
||||
* values, identity will be disregarded by notDeepEqual.
|
||||
*
|
||||
* @param actual Object or Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function notDeepEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A non-strict comparison assertion, checking for inequality.
|
||||
*
|
||||
* The notEqual assertion uses the simple inverted comparison operator (!=) to compare
|
||||
* the actual and expected arguments. When they aren't equal, the assertion passes;
|
||||
* otherwise, it fails. When it fails, both actual and expected values are displayed
|
||||
* in the test result, in addition to a given message.
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function notEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A non-strict comparison assertion, checking for inequality.
|
||||
*
|
||||
* The notStrictEqual assertion uses the strict inverted comparison operator (!==)
|
||||
* to compare the actual and expected arguments. When they aren't equal, the assertion
|
||||
* passes; otherwise, it fails. When it fails, both actual and expected values are
|
||||
* displayed in the test result, in addition to a given message.
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function notStrictEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* A boolean assertion, equivalent to CommonJS’s assert.ok() and JUnit’s assertTrue().
|
||||
* Passes if the first argument is truthy.
|
||||
*
|
||||
* The most basic assertion in QUnit, ok() requires just one argument. If the argument
|
||||
* evaluates to true, the assertion passes; otherwise, it fails. If a second message
|
||||
* argument is provided, it will be displayed in place of the result.
|
||||
*
|
||||
* @param state Expression being tested
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function ok(state: any, message?: string);
|
||||
|
||||
/**
|
||||
* A strict type and value comparison assertion.
|
||||
*
|
||||
* The strictEqual() assertion provides the most rigid comparison of type and value with
|
||||
* the strict equality operator (===)
|
||||
*
|
||||
* @param actual Expression being tested
|
||||
* @param expected Known comparison value
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function strictEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* Assertion to test if a callback throws an exception when run.
|
||||
*
|
||||
* When testing code that is expected to throw an exception based on a specific set of
|
||||
* circumstances, use throws() to catch the error object for testing and comparison.
|
||||
*
|
||||
* @param block Function to execute
|
||||
* @param expected Error Object to compare
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function throws(block: () => any, expected: any, message?: string);
|
||||
|
||||
/**
|
||||
* @param block Function to execute
|
||||
* @param message A short description of the assertion
|
||||
*/
|
||||
declare function throws(block: () => any, message?: string);
|
||||
|
||||
/* ASYNC CONTROL */
|
||||
|
||||
/**
|
||||
* Start running tests again after the testrunner was stopped. See stop().
|
||||
*
|
||||
* When your async test has multiple exit points, call start() for the corresponding number of stop() increments.
|
||||
*
|
||||
* @param decrement Optional argument to merge multiple start() calls into one. Use with multiple corrsponding stop() calls.
|
||||
*/
|
||||
declare function start(decrement?: number);
|
||||
|
||||
/**
|
||||
* Stop the testrunner to wait for async tests to run. Call start() to continue.
|
||||
*
|
||||
* When your async test has multiple exit points, call stop() with the increment argument, corresponding to the number of start() calls you need.
|
||||
*
|
||||
* On Blackberry 5.0, window.stop is a native read-only function. If you deal with that browser, use QUnit.stop() instead, which will work anywhere.
|
||||
*
|
||||
* @param decrement Optional argument to merge multiple stop() calls into one. Use with multiple corrsponding start() calls.
|
||||
*/
|
||||
declare function stop(increment? : number);
|
||||
|
||||
/* CALLBACKS */
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever the test suite begins.
|
||||
*
|
||||
* QUnit.begin() is called once before running any tests. (a better would've been QUnit.start,
|
||||
* but thats already in use elsewhere and can't be changed.)
|
||||
*
|
||||
* @param callback Callback to execute
|
||||
*/
|
||||
declare function begin(callback: () => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever the test suite ends.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
declare function done(callback: (details: DoneCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever an assertion completes.
|
||||
*
|
||||
* This is one of several callbacks QUnit provides. Its intended for integration scenarios like
|
||||
* PhantomJS or Jenkins. The properties of the details argument are listed below as options.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
declare function log(callback: (details: LogCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a module ends.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
declare function moduleDone(callback: (details: ModuleDoneCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a module begins.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
declare function moduleStart(callback: (name: string) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a test ends.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
declare function testDone(callback: (details: TestDoneCallbackObject) => any);
|
||||
|
||||
/**
|
||||
* Register a callback to fire whenever a test begins.
|
||||
*
|
||||
* @param callback Callback to execute.
|
||||
*/
|
||||
declare function testStart(callback: (details: TestStartCallbackObject) => any);
|
||||
|
||||
/* TEST */
|
||||
|
||||
/**
|
||||
* Add an asynchronous test to run. The test must include a call to start().
|
||||
*
|
||||
* For testing asynchronous code, asyncTest will automatically stop the test runner
|
||||
* and wait for your code to call start() to continue.
|
||||
*
|
||||
* @param name Title of unit being tested
|
||||
* @param expected Number of assertions in this test
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
declare function asyncTest(name: string, expected?: any, test?: () => any);
|
||||
|
||||
/**
|
||||
* Add an asynchronous test to run. The test must include a call to start().
|
||||
*
|
||||
* For testing asynchronous code, asyncTest will automatically stop the test runner
|
||||
* and wait for your code to call start() to continue.
|
||||
*
|
||||
* @param name Title of unit being tested
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
declare function asyncTest(name: string, test: () => any);
|
||||
|
||||
/**
|
||||
* Specify how many assertions are expected to run within a test.
|
||||
*
|
||||
* To ensure that an explicit number of assertions are run within any test, use
|
||||
* expect( number ) to register an expected count. If the number of assertions
|
||||
* run does not match the expected count, the test will fail.
|
||||
*
|
||||
* @param amount Number of assertions in this test.
|
||||
*/
|
||||
declare function expect(amount: number);
|
||||
|
||||
// ** conflict with TypeScript module keyword. Must be used on QUnit namespace
|
||||
//declare var module: (name: string, lifecycle?: LifecycleObject) => any;
|
||||
|
||||
/**
|
||||
* Add a test to run.
|
||||
*
|
||||
* When testing the most common, synchronous code, use test().
|
||||
* The assert argument to the callback contains all of QUnit's assertion methods.
|
||||
* If you are avoiding using any of QUnit's globals, you can use the assert
|
||||
* argument instead.
|
||||
*
|
||||
* @param title Title of unit being tested
|
||||
* @param expected Number of assertions in this test
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
declare function test(title: string, expected: number, test: (assert?: QUnitAssert) => any);
|
||||
|
||||
/**
|
||||
* @param title Title of unit being tested
|
||||
* @param test Function to close over assertions
|
||||
*/
|
||||
declare function test(title: string, test: (assert?: QUnitAssert) => any);
|
||||
|
||||
declare function notPropEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
declare function propEqual(actual: any, expected: any, message?: string);
|
||||
|
||||
// https://github.com/jquery/qunit/blob/master/qunit/qunit.js#L1568
|
||||
|
||||
4
requirejs/require.d.ts
vendored
4
requirejs/require.d.ts
vendored
@@ -202,5 +202,5 @@ interface RequireDefine {
|
||||
}
|
||||
|
||||
// Ambient declarations for 'require' and 'define'
|
||||
var require: Require;
|
||||
var define: RequireDefine;
|
||||
declare var require: Require;
|
||||
declare var define: RequireDefine;
|
||||
|
||||
218
restify/restify-test.ts
Normal file
218
restify/restify-test.ts
Normal file
@@ -0,0 +1,218 @@
|
||||
/// <reference path="restify.d.ts" />
|
||||
|
||||
import restify = module("restify");
|
||||
|
||||
var server = restify.createServer({
|
||||
formatters: {
|
||||
'application/foo': function formatFoo(req, res, body) {
|
||||
if (body instanceof Error)
|
||||
return body.stack;
|
||||
|
||||
if (body)
|
||||
return body.toString('base64');
|
||||
|
||||
return body;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
server = restify.createServer({
|
||||
certificate: "test",
|
||||
key: "test",
|
||||
formatters: {},
|
||||
log: {},
|
||||
name: "test",
|
||||
spdy: {},
|
||||
version: "",
|
||||
responseTimeHeader: "",
|
||||
responseTimeFormatter : (durationInMilliseconds: number) => {}
|
||||
});
|
||||
|
||||
server.on('someEvent', ()=>{});
|
||||
|
||||
|
||||
server.use((req, res, next)=>{});
|
||||
server.use([(req, res, next)=>{}]);
|
||||
server.use((req, res, next)=>{}, (req, res, next)=>{});
|
||||
|
||||
function send(req, res, next) {
|
||||
req.header('key', 'val');
|
||||
req.header('key') === 'val';
|
||||
|
||||
req.accepts('test') === true;
|
||||
req.is('test') === true;
|
||||
|
||||
req.getLogger('test');
|
||||
|
||||
var log = req.log;
|
||||
log.debug({params: req.params}, 'Hello there %s', 'foo');
|
||||
|
||||
req.contentLength === 50;
|
||||
req.contentType === 'test';
|
||||
req.href === 'test';
|
||||
req.id === 'test';
|
||||
req.path === 'test';
|
||||
req.query === 'test';
|
||||
req.secure === true;
|
||||
req.time === 50;
|
||||
req.params;
|
||||
|
||||
res.header('test');
|
||||
res.header('test', {});
|
||||
res.header('test', new Date());
|
||||
|
||||
res.cache();
|
||||
res.cache('testst', {});
|
||||
|
||||
res.status(344);
|
||||
|
||||
res.send({hello: 'world'});
|
||||
res.send(201, {hello: 'world'});
|
||||
res.send(new restify.BadRequestError('meh'));
|
||||
|
||||
res.json(201, {hello: 'world'});
|
||||
res.json({hello: 'world'});
|
||||
|
||||
res.code === 50;
|
||||
res.contentLength === 50;
|
||||
res.charSet === 'test';
|
||||
res.contentType === 'test';
|
||||
res.headers;
|
||||
res.id === 'test';
|
||||
|
||||
res.send('hello ' + req.params.name);
|
||||
return next();
|
||||
}
|
||||
|
||||
|
||||
server.post('/hello', send);
|
||||
server.put( '/hello', send);
|
||||
server.del( '/hello', send);
|
||||
server.get( '/hello', send);
|
||||
server.head('/hello', send);
|
||||
|
||||
server.post(/(.*)/, send);
|
||||
server.put( /(.*)/, send);
|
||||
server.del( /(.*)/, send);
|
||||
server.get( /(.*)/, send);
|
||||
server.head(/(.*)/, send);
|
||||
|
||||
new restify.ConflictError("test");
|
||||
new restify.InvalidArguementError("message");
|
||||
new restify.RestError("message");
|
||||
new restify.BadDigestError("message");
|
||||
new restify.BadMethodError("message");
|
||||
new restify.BadRequestError('test');
|
||||
new restify.InternalError("message");
|
||||
new restify.InvalidContentError("message");
|
||||
new restify.InvalidCredentialsError("message");
|
||||
new restify.InvalidHeaderError("message");
|
||||
new restify.InvalidVersionError("message");
|
||||
new restify.MissingParameterError("message");
|
||||
new restify.NotAuthorizedError("message");
|
||||
new restify.RequestExpiredError("jjmessage");
|
||||
new restify.RequestThrottledError("message");
|
||||
new restify.ResourceNotFoundError("message");
|
||||
new restify.WrongAcceptError("message");
|
||||
|
||||
server.name = "";
|
||||
server.version = "";
|
||||
server.log = {};
|
||||
server.acceptable = ["test"];
|
||||
server.url = "";
|
||||
|
||||
server.address().port;
|
||||
server.address().family;
|
||||
server.address().address;
|
||||
|
||||
server.listen("somePath", send);
|
||||
server.close();
|
||||
|
||||
server.use(restify.acceptParser(server.acceptable));
|
||||
server.use(restify.authorizationParser());
|
||||
server.use(restify.dateParser());
|
||||
server.use(restify.queryParser());
|
||||
server.use(restify.jsonp());
|
||||
server.use(restify.gzipResponse());
|
||||
server.use(restify.bodyParser());
|
||||
server.use(restify.throttle({
|
||||
burst: 100,
|
||||
rate: 50,
|
||||
ip: true,
|
||||
overrides: {
|
||||
'192.168.1.1': {
|
||||
rate: 0,
|
||||
burst: 0
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
server.on('after', restify.auditLogger({
|
||||
log: ()=>{}
|
||||
}));
|
||||
|
||||
restify.defaultResponseHeaders = function(data) {
|
||||
this.header('Server', 'helloworld');
|
||||
};
|
||||
|
||||
restify.defaultResponseHeaders = false;
|
||||
|
||||
//RESTIFY Client Tests
|
||||
|
||||
var client = restify.createJsonClient({
|
||||
url: 'https://api.us-west-1.joyentcloud.com',
|
||||
version: '*'
|
||||
});
|
||||
|
||||
client = restify.createStringClient({
|
||||
accept: "test",
|
||||
connectTimeout: 30,
|
||||
dtrace: {},
|
||||
gzip: {},
|
||||
headers: {},
|
||||
log: {},
|
||||
retry: {},
|
||||
signRequest: ()=>{},
|
||||
url: "",
|
||||
userAgent: "",
|
||||
version: ""
|
||||
});
|
||||
|
||||
client.get("test", send);
|
||||
client.head('test', send);
|
||||
client.post('path', {}, send);
|
||||
client.put('path', {}, send);
|
||||
client.del('path', send);
|
||||
|
||||
client.post('/foo', { hello: 'world' }, function(err, req, res, obj) {
|
||||
console.log('%d -> %j', res.statusCode, res.headers);
|
||||
console.log('%j', obj);
|
||||
});
|
||||
|
||||
client.get('/foo/bar', function(err, req, res, data) {
|
||||
console.log('%s', data);
|
||||
});
|
||||
|
||||
var client2 = restify.createClient({
|
||||
url: 'http://127.0.0.1'
|
||||
});
|
||||
|
||||
client2.get('/str/mcavage', function(err, req) {
|
||||
|
||||
req.on('result', function(err, res) {
|
||||
|
||||
res.body = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function(chunk) {
|
||||
res.body += chunk;
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
console.log(res.body);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
client.basicAuth('test', 'password');
|
||||
client2.basicAuth('test', 'password');
|
||||
152
restify/restify.d.ts
vendored
Normal file
152
restify/restify.d.ts
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
interface addressInterface {
|
||||
port: number;
|
||||
family: string;
|
||||
address: string;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
header: (key: string, defaultValue?: string) => any;
|
||||
accepts: (type: string) => bool;
|
||||
is: (type: string) => bool;
|
||||
getLogger: (component: string) => any;
|
||||
contentLength: number;
|
||||
contentType: string;
|
||||
href: string;
|
||||
log: Object;
|
||||
id: string;
|
||||
path: string;
|
||||
query: string;
|
||||
secure: bool;
|
||||
time: number;
|
||||
params: any;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
header: (key: string, value ?: any) => any;
|
||||
cache: (type?: any, options?: Object) => any;
|
||||
status: (code: number) => any;
|
||||
send: (status?: any, body?: any) => any;
|
||||
json: (status?: any, body?: any) => any;
|
||||
code: number;
|
||||
contentLength: number;
|
||||
charSet: string;
|
||||
contentType: string;
|
||||
headers: Object;
|
||||
statusCode: number;
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface Server {
|
||||
use: (... handler: any[]) => any;
|
||||
post: (route: any, routeCallBack: (req: Request, res: Response, next: Function) => any) => any;
|
||||
put: (route: any, routeCallBack: (req: Request, res: Response, next: Function) => any) => any;
|
||||
del: (route: any, routeCallBack: (req: Request, res: Response, next: Function) => any) => any;
|
||||
get: (route: any, routeCallBack: (req: Request, res: Response, next: Function ) => any) => any;
|
||||
head: (route: any, routeCallBack: (req: Request, res: Response, next: Function) => any) => any;
|
||||
on: (event: string, callback: Function) => any;
|
||||
name: string;
|
||||
version: string;
|
||||
log: Object;
|
||||
acceptable: string[];
|
||||
url: string;
|
||||
address: () => addressInterface;
|
||||
listen: (... args: any[]) => any;
|
||||
close: (... args: any[]) => any;
|
||||
pre: (routeCallBack: (req: Request, res: Response, next: Function) => any) => any;
|
||||
|
||||
}
|
||||
|
||||
interface ServerOptions {
|
||||
certificate ?: string;
|
||||
key ?: string;
|
||||
formatters ?: Object;
|
||||
log ?: Object;
|
||||
name ?: string;
|
||||
spdy ?: Object;
|
||||
version ?: string;
|
||||
responseTimeHeader ?: string;
|
||||
responseTimeFormatter ?: (durationInMilliseconds: number) => any;
|
||||
}
|
||||
|
||||
interface ClientOptions {
|
||||
accept?: string;
|
||||
connectTimeout?: number;
|
||||
dtrace?: Object;
|
||||
gzip?: Object;
|
||||
headers?: Object;
|
||||
log?: Object;
|
||||
retry?: Object;
|
||||
signRequest?: Function;
|
||||
url?: string;
|
||||
userAgent?: string;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
interface Client {
|
||||
get: (path: string, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
|
||||
head: (path: string, callback?: (err: any, req: Request, res: Response) => any) => any;
|
||||
post: (path: string, object: any, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
|
||||
put: (path: string, object: any, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
|
||||
del: (path: string, callback?: (err: any, req: Request, res: Response) => any) => any;
|
||||
basicAuth: (username: string, password: string) => any;
|
||||
}
|
||||
|
||||
interface HttpClient extends Client {
|
||||
get: (path?: any, callback?: Function) => any;
|
||||
head: (path?:any, callback?: Function) => any;
|
||||
post: (opts?: any, callback?: Function) => any;
|
||||
put: (opts?: any, callback?: Function) => any;
|
||||
del: (opts?: any, callback?: Function) => any;
|
||||
}
|
||||
|
||||
interface ThrottleOptions {
|
||||
burst?: number;
|
||||
rate?: number;
|
||||
ip?: bool;
|
||||
xff?: bool;
|
||||
username?: bool;
|
||||
tokensTable?: Object;
|
||||
maxKeys?: number;
|
||||
overrides?: Object;
|
||||
}
|
||||
|
||||
declare module "restify" {
|
||||
export function createServer(options?: ServerOptions): Server;
|
||||
|
||||
export function createJsonClient(options?: ClientOptions): Client;
|
||||
export function createStringClient(options?: ClientOptions): Client;
|
||||
export function createClient(options?: ClientOptions): HttpClient;
|
||||
|
||||
export class ConflictError { constructor(message?: any); };
|
||||
export class InvalidArguementError { constructor(message?: any); };
|
||||
export class RestError { constructor(message?: any); };
|
||||
export class BadDigestError { constructor(message: any); };
|
||||
export class BadMethodError { constructor(message: any); };
|
||||
export class BadRequestError { constructor(message: any); };
|
||||
export class InternalError { constructor(message: any); };
|
||||
export class InvalidContentError { constructor(message: any); };
|
||||
export class InvalidCredentialsError { constructor(message: any); };
|
||||
export class InvalidHeaderError { constructor(message: any); };
|
||||
export class InvalidVersionError { constructor(message: any); };
|
||||
export class MissingParameterError { constructor(message: any); };
|
||||
export class NotAuthorizedError { constructor(message: any); };
|
||||
export class RequestExpiredError { constructor(message: any); };
|
||||
export class RequestThrottledError { constructor(message: any); };
|
||||
export class ResourceNotFoundError { constructor(message: any); };
|
||||
export class WrongAcceptError { constructor(message: any); };
|
||||
|
||||
export function acceptParser(parser: any);
|
||||
export function authorizationParser();
|
||||
export function dateParser(skew?: number);
|
||||
export function queryParser(options?: Object);
|
||||
export function urlEncodedBodyParser(options?: Object);
|
||||
export function jsonp(options?: Object);
|
||||
export function gzipResponse(options?: Object);
|
||||
export function bodyParser(options?: Object);
|
||||
export function requestLogger(options?: Object);
|
||||
export function serveStatic(options?: Object);
|
||||
export function throttle(options?: ThrottleOptions);
|
||||
export function conditionalRequest(options?: Object);
|
||||
export function auditLogger(options?: Object);
|
||||
export var defaultResponseHeaders : any;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Tests for Video.js API
|
||||
/// <reference path="videojs.d.ts" />
|
||||
|
||||
<<<<<<< HEAD
|
||||
_V_("example_video_1").ready(function(){
|
||||
|
||||
var myPlayer:VideoJSPlayer = this;
|
||||
@@ -72,7 +71,4 @@ _V_("example_video_1").ready(function(){
|
||||
myPlayer.addEvent("volumechange", myFunc);
|
||||
myPlayer.removeEvent("volumechange", myFunc);
|
||||
|
||||
});
|
||||
=======
|
||||
var myPlayer:VideoJSPlayer = _V_("example_video_1");
|
||||
>>>>>>> f8b142ba4c1a906b03601cd1f0d53484250f11b3
|
||||
});
|
||||
3
videojs/videojs.d.ts
vendored
3
videojs/videojs.d.ts
vendored
@@ -26,10 +26,7 @@ interface VideoJSPlayer {
|
||||
src(newSource: VideoJSSource): VideoJSPlayer;
|
||||
src(newSource: VideoJSSource[]): VideoJSPlayer;
|
||||
currentTime(seconds: number): VideoJSPlayer;
|
||||
<<<<<<< HEAD
|
||||
currentTime(): number;
|
||||
=======
|
||||
>>>>>>> f8b142ba4c1a906b03601cd1f0d53484250f11b3
|
||||
duration(): number;
|
||||
buffered(): TimeRanges;
|
||||
bufferedPercent(): number;
|
||||
|
||||
Reference in New Issue
Block a user