mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-24 11:29:30 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
/// <reference path="./cradle.d.ts" />
|
||||
|
||||
import cradle = require("cradle");
|
||||
|
||||
cradle.setup({
|
||||
host: 'living-room.couch',
|
||||
cache: true,
|
||||
raw: false,
|
||||
forceSave: true
|
||||
});
|
||||
|
||||
const connection = new cradle.Connection();
|
||||
const connection2 = new(cradle.Connection);
|
||||
const connection3 = new(cradle.Connection)('173.45.66.92');
|
||||
|
||||
connection.databases(function(error, response) {});
|
||||
connection.config(function(error, response) {});
|
||||
connection.databases(function(error, response) {});
|
||||
connection.info(function(error, response) {});
|
||||
connection.stats(function(error, response) {});
|
||||
connection.activeTasks(function(error, response) {});
|
||||
connection.uuids(function(error, response) {});
|
||||
connection.uuids(10, function(error, response) {});
|
||||
connection.replicate({
|
||||
source: "database",
|
||||
target: "targetDatabase"
|
||||
}, function(error, response) {});
|
||||
|
||||
const db = connection.database('starwars');
|
||||
|
||||
db.exists(function (error, exists) {
|
||||
if (error) {
|
||||
console.log('error', error);
|
||||
} else if (exists) {
|
||||
console.log('the force is with you.');
|
||||
} else {
|
||||
console.log('database does not exists.');
|
||||
db.create(function(error){
|
||||
/* do something if there's an erroror */
|
||||
/* populate design documents */
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
db.get<{
|
||||
name: string;
|
||||
}>('vader', function (error, doc) {
|
||||
doc.name; // 'Darth Vader'
|
||||
});
|
||||
|
||||
db.get('luke', function (error, doc) {
|
||||
doc.prop;
|
||||
});
|
||||
|
||||
db.get(['luke', 'vader'], function (error, doc) {
|
||||
//
|
||||
});
|
||||
|
||||
db.save('skywalker', {
|
||||
force: 'light',
|
||||
name: 'Luke Skywalker'
|
||||
}, function (error, res) {
|
||||
if (error) {
|
||||
// Handle erroror
|
||||
} else {
|
||||
// Handle success
|
||||
}
|
||||
});
|
||||
|
||||
db.save({
|
||||
force: 'dark', name: 'Darth'
|
||||
}, function (err, res) {
|
||||
// Handle response
|
||||
});
|
||||
|
||||
db.save('luke', '1-94B6F82', {
|
||||
force: 'dark', name: 'Luke'
|
||||
}, function (err, res) {
|
||||
// Handle response
|
||||
});
|
||||
|
||||
db.save([
|
||||
{ name: 'Yoda' },
|
||||
{ name: 'Han Solo' },
|
||||
{ name: 'Leia' }
|
||||
], function (err, res) {
|
||||
// Handle response
|
||||
});
|
||||
|
||||
db.merge('luke', {jedi: true}, function (err, res) {
|
||||
// Luke is now a jedi,
|
||||
// but remains on the dark side of the force.
|
||||
});
|
||||
|
||||
db.view('characters/all', function (err, res) {
|
||||
res.forEach(function (row: any) {
|
||||
console.log("%s is on the %s side of the force.", row.name, row.force);
|
||||
});
|
||||
});
|
||||
|
||||
db.view('characters/all', {group: true, reduce: true} , function (err, res) {
|
||||
res.forEach(function (row: any) {
|
||||
console.log("%s is on the %s side of the force.", row.name, row.force);
|
||||
});
|
||||
});
|
||||
|
||||
db.temporaryView({
|
||||
map: function (doc: any) {
|
||||
//
|
||||
}
|
||||
}, function (err, res) {
|
||||
if (err) console.log(err);
|
||||
console.log(res);
|
||||
});
|
||||
|
||||
db.remove('luke', '1-94B6F82', function (err, res) {
|
||||
// Handle response
|
||||
});
|
||||
|
||||
db.update('my_designdoc/update_handler_name', 'luke', undefined, { my_param: false }, function (err, res) {
|
||||
// Handle the response, specified by the update handler
|
||||
});
|
||||
|
||||
db.changes(function (err, list) {
|
||||
list.forEach(function (change) { console.log(change) });
|
||||
});
|
||||
|
||||
db.changes({ since: 42 }, function (err, list) {
|
||||
//
|
||||
});
|
||||
|
||||
const feed = db.changes({ since: 42 });
|
||||
|
||||
feed.on('change', function (change: any) {
|
||||
console.log(change);
|
||||
});
|
||||
|
||||
const idAndRevData = {
|
||||
id: 'luke',
|
||||
rev: 'my-rev'
|
||||
};
|
||||
|
||||
const attachmentData = {
|
||||
name: 'fooAttachment.txt',
|
||||
'Content-Type': 'text/plain',
|
||||
body: 'Foo document text'
|
||||
};
|
||||
|
||||
db.saveAttachment(idAndRevData, attachmentData, function (err, reply) {
|
||||
if (err) {
|
||||
console.dir(err)
|
||||
return
|
||||
}
|
||||
console.dir(reply)
|
||||
});
|
||||
|
||||
|
||||
db.getAttachment('luke', 'foo.txt', function (err, reply) {
|
||||
if (err) {
|
||||
console.dir(err);
|
||||
return;
|
||||
}
|
||||
console.dir(reply);
|
||||
});
|
||||
|
||||
db.removeAttachment('luke', 'foo.txt', function (err, reply) {
|
||||
if (err) {
|
||||
console.dir(err);
|
||||
return;
|
||||
}
|
||||
console.dir(reply);
|
||||
});
|
||||
|
||||
db.info(function(error, response) {});
|
||||
db.all(function(error, response) {});
|
||||
db.all({
|
||||
body: {
|
||||
keys: ['key1', 'key2']
|
||||
}
|
||||
}, function(error, response) {});
|
||||
db.compact(function(error, response) {});
|
||||
db.compact('design', function(error, response) {});
|
||||
db.viewCleanup(function(error, response) {});
|
||||
db.replicate('database', function(error, response) {});
|
||||
db.replicate('database', {}, function(error, response) {});
|
||||
Vendored
+122
@@ -0,0 +1,122 @@
|
||||
// Type definitions for cradle
|
||||
// Project: https://github.com/flatiron/cradle
|
||||
// Definitions by: Panu Horsmalahti <https://github.com/panuhorsmalahti>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "cradle" {
|
||||
interface Options {
|
||||
host?: string;
|
||||
hostname?: string;
|
||||
cache?: boolean;
|
||||
raw?: boolean;
|
||||
forceSave?: boolean;
|
||||
auth?: string | {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
ca?: string;
|
||||
secure?: boolean;
|
||||
retries?: number;
|
||||
retryTimeout?: number;
|
||||
maxSockets?: number;
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
(error: any, response: any): void;
|
||||
}
|
||||
|
||||
interface ErrorCallback {
|
||||
(error: any): void;
|
||||
}
|
||||
|
||||
export class Connection {
|
||||
constructor(uri?: string, port?: number, options?: Options);
|
||||
database(name: string): Database;
|
||||
databases(Callback: Callback): void;
|
||||
config(callback: Callback): void;
|
||||
info(callback: Callback): void;
|
||||
stats(callback: Callback): void;
|
||||
activeTasks(callback: Callback): void;
|
||||
uuids(callback: Callback): void;
|
||||
uuids(count: number, callback: Callback): void;
|
||||
replicate(options: {
|
||||
source: string | {
|
||||
url: string;
|
||||
};
|
||||
target: string | {
|
||||
url: string;
|
||||
};
|
||||
cancel?: boolean;
|
||||
continuous?: boolean;
|
||||
create_target?: boolean;
|
||||
doc_ids?: string[];
|
||||
filter?: string;
|
||||
proxy?: string;
|
||||
query_params?: any;
|
||||
}, callback: Callback): void;
|
||||
}
|
||||
|
||||
export interface ChangesOptions {
|
||||
since: number;
|
||||
}
|
||||
|
||||
export class Database {
|
||||
name: string;
|
||||
get(id: string, callback: (error: any, document: any) => void): void;
|
||||
get<T>(id: string, callback: (error: any, document: T) => void): void;
|
||||
get(id: string, rev: string, callback: (error: any, document: any) => void): void;
|
||||
get<T>(id: string, rev: string, callback: (error: any, document: T) => void): void;
|
||||
get(ids: string[], callback: Callback): void;
|
||||
save(document: any, callback: Callback): void;
|
||||
save(id: string, document: any, callback: Callback): void;
|
||||
save(id: string, revision: string, document: any,
|
||||
callback: Callback): void;
|
||||
save<T>(document: T, callback: Callback): void;
|
||||
save<T>(id: string, document: T, callback: Callback): void;
|
||||
save<T>(id: string, revision: string, document: T,
|
||||
callback: Callback): void;
|
||||
save(documents: any[], callback: Callback): void;
|
||||
merge(id: string, document: any, callback: Callback): void;
|
||||
merge<T>(id: string, document: T, callback: Callback): void;
|
||||
remove(id: string, revision: string, callback: Callback): void;
|
||||
update(name: string, id: string, queryObject: any, documentBody: any,
|
||||
callback: Callback): void;
|
||||
view(name: string, callback: Callback): void;
|
||||
view(name: string, options: {
|
||||
group?: boolean;
|
||||
reduce?: boolean;
|
||||
key?: string;
|
||||
startkey?: any;
|
||||
endkey?: any;
|
||||
include_docs?: boolean;
|
||||
limit?: number;
|
||||
descending?: boolean;
|
||||
}, callback: Callback): void;
|
||||
temporaryView(view: any, callback: Callback): void;
|
||||
create(callback: ErrorCallback): void;
|
||||
exists(callback: (error: any, exists: boolean) => void): void;
|
||||
destroy(callback: ErrorCallback): void;
|
||||
changes(options: ChangesOptions): any;
|
||||
changes(callback: (error: any, list: any[]) => void): void;
|
||||
changes(options: ChangesOptions, callback: (error: any,
|
||||
list: any[]) => void): void;
|
||||
saveAttachment(idAndRevData: {
|
||||
id: string;
|
||||
rev: string;
|
||||
}, attachmentData: any, callback: Callback): void;
|
||||
getAttachment(id: string, attachmentName: string,
|
||||
callback: Callback): void;
|
||||
removeAttachment(id: string, attachmentName: string,
|
||||
callback: Callback): void;
|
||||
info(callback: Callback): void;
|
||||
all(callback: Callback): void;
|
||||
all(options: any, callback: Callback): void;
|
||||
compact(callback: Callback): void;
|
||||
compact(design: string, callback: Callback): void;
|
||||
viewCleanup(callback: Callback): void;
|
||||
replicate(target: string, callback: Callback): void;
|
||||
replicate(target: string, options: any, callback: Callback): void;
|
||||
}
|
||||
|
||||
export function setup(options: Options): void;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/// <reference path="cucumber.d.ts" />
|
||||
|
||||
function StepSample() {
|
||||
type Callback = cucumber.CallbackStepDefinition;
|
||||
var step = <cucumber.StepDefinitions>this;
|
||||
var hook = <cucumber.Hooks>this;
|
||||
|
||||
hook.Before(function(scenario, callback){
|
||||
scenario.isFailed() && callback.pending();
|
||||
})
|
||||
|
||||
hook.Around(function(scenario, runScenario) {
|
||||
scenario.isFailed() && runScenario(null, function(){
|
||||
console.log('finish tasks');
|
||||
});
|
||||
});
|
||||
|
||||
hook.registerHandler('AfterFeatures', function (event, callback) {
|
||||
callback();
|
||||
});
|
||||
|
||||
step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback:Callback) {
|
||||
this.visit('https://github.com/cucumber/cucumber-js', callback);
|
||||
});
|
||||
|
||||
step.When(/^I go to the README file$/, function(title:string, callback:Callback) {
|
||||
callback.pending();
|
||||
});
|
||||
|
||||
step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback:Callback) {
|
||||
var pageTitle = this.browser.text('title');
|
||||
|
||||
if (title === pageTitle) {
|
||||
callback();
|
||||
} else {
|
||||
callback(new Error("Expected to be on page with title " + title));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
// Type definitions for cucumber-js
|
||||
// Project: https://github.com/cucumber/cucumber-js
|
||||
// Definitions by: Abraão Alves <https://github.com/abraaoalves>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../es6-promise/es6-promise.d.ts" />
|
||||
|
||||
declare module cucumber {
|
||||
|
||||
export interface CallbackStepDefinition{
|
||||
pending : () => Thenable<any>;
|
||||
(errror?:any):void;
|
||||
}
|
||||
|
||||
interface StepDefinitionCode {
|
||||
(...stepArgs: Array<string |CallbackStepDefinition>): Thenable<any> | any | void;
|
||||
}
|
||||
|
||||
interface StepDefinitionOptions{
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export interface StepDefinitions {
|
||||
Given(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void;
|
||||
Given(pattern: RegExp | string, code: StepDefinitionCode): void;
|
||||
When(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void;
|
||||
When(pattern: RegExp | string, code: StepDefinitionCode): void;
|
||||
Then(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void;
|
||||
Then(pattern: RegExp | string, code: StepDefinitionCode): void;
|
||||
setDefaultTimeout(time:number): void;
|
||||
}
|
||||
|
||||
interface HookScenario{
|
||||
attach(text: string, mimeType?: string, callback?: (err?:any) => void): void;
|
||||
isFailed() : boolean;
|
||||
}
|
||||
|
||||
interface HookCode {
|
||||
(scenario: HookScenario, callback?: CallbackStepDefinition): void;
|
||||
}
|
||||
|
||||
interface AroundCode{
|
||||
(scenario: HookScenario, runScenario?: (error:string, callback?:Function)=>void): void;
|
||||
}
|
||||
|
||||
export interface Hooks {
|
||||
Before(code: HookCode): void;
|
||||
After(code: HookCode): void;
|
||||
Around(code: AroundCode):void;
|
||||
setDefaultTimeout(time:number): void;
|
||||
registerHandler(handlerOption:string, code:(event:any, callback:CallbackStepDefinition) =>void): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'cucumber'{
|
||||
export = cucumber;
|
||||
}
|
||||
Vendored
+1
@@ -247,6 +247,7 @@ declare module FullCalendar {
|
||||
backgroundColor?: string;
|
||||
borderColor?: string;
|
||||
textColor?: string;
|
||||
rendering?: string;
|
||||
}
|
||||
|
||||
export interface ViewObject extends Timespan {
|
||||
|
||||
Vendored
+1
-1
@@ -1700,7 +1700,7 @@ declare module GitHubElectron {
|
||||
interface Electron {
|
||||
clipboard: GitHubElectron.Clipboard;
|
||||
crashReporter: GitHubElectron.CrashReporter;
|
||||
nativeImage: GitHubElectron.NativeImage;
|
||||
nativeImage: typeof GitHubElectron.NativeImage;
|
||||
screen: GitHubElectron.Screen;
|
||||
shell: GitHubElectron.Shell;
|
||||
remote: GitHubElectron.Remote;
|
||||
|
||||
@@ -46,4 +46,11 @@ let hmac5:string = shaObj1.getHMAC("HEX", { outputUpper: true, b64Pad: '=' });
|
||||
shaObj.setHMACKey("abc", "TEXT");
|
||||
shaObj.update("This is a test");
|
||||
let hmac = shaObj.getHMAC("HEX");
|
||||
}
|
||||
|
||||
// Browser global test
|
||||
{
|
||||
var shaObj = new jsSHA("SHA-512", "TEXT");
|
||||
shaObj.update("This is a test");
|
||||
var hash = shaObj.getHash("HEX");
|
||||
}
|
||||
Vendored
+2
-2
@@ -79,7 +79,7 @@ declare module jsSHA {
|
||||
}
|
||||
}
|
||||
|
||||
declare var jsSHA: jsSHA.jsSHA;
|
||||
declare module 'jssha' {
|
||||
var jsSHA: jsSHA.jsSHA;
|
||||
export = jsSHA;
|
||||
}
|
||||
}
|
||||
|
||||
+28
-11
@@ -5532,17 +5532,34 @@ result = <boolean>_<any>([]).isFinite();
|
||||
result = <boolean>_({}).isFinite();
|
||||
|
||||
// _.isFunction
|
||||
result = <boolean>_.isFunction(any);
|
||||
result = <boolean>_(1).isFunction();
|
||||
result = <boolean>_<any>([]).isFunction();
|
||||
result = <boolean>_({}).isFunction();
|
||||
{
|
||||
let value: Function|string = "foo";
|
||||
if (_.isFunction(value)) {
|
||||
value();
|
||||
} else {
|
||||
let result: string = value;
|
||||
}
|
||||
module TestIsFunction {
|
||||
{
|
||||
let value: number|Function;
|
||||
|
||||
if (_.isFunction(value)) {
|
||||
let result: Function = value;
|
||||
}
|
||||
else {
|
||||
let result: number = value;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let result: boolean;
|
||||
|
||||
result = _.isFunction(any);
|
||||
result = _(1).isFunction();
|
||||
result = _<any>([]).isFunction();
|
||||
result = _({}).isFunction();
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitWrapper<boolean>;
|
||||
|
||||
result = _(1).chain().isFunction();
|
||||
result = _<any>([]).chain().isFunction();
|
||||
result = _({}).chain().isFunction();
|
||||
}
|
||||
}
|
||||
|
||||
// _.isMatch
|
||||
|
||||
Vendored
+9
-1
@@ -9434,9 +9434,10 @@ declare module _ {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Checks if value is classified as a Function object.
|
||||
*
|
||||
* @param value The value to check.
|
||||
* @return Returns true if value is correctly classified, else false.
|
||||
**/
|
||||
*/
|
||||
isFunction(value?: any): value is Function;
|
||||
}
|
||||
|
||||
@@ -9447,6 +9448,13 @@ declare module _ {
|
||||
isFunction(): boolean;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapperBase<T, TWrapper> {
|
||||
/**
|
||||
* @see _.isFunction
|
||||
*/
|
||||
isFunction(): LoDashExplicitWrapper<boolean>;
|
||||
}
|
||||
|
||||
//_.isMatch
|
||||
interface isMatchCustomizer {
|
||||
(value: any, other: any, indexOrKey?: number|string): boolean;
|
||||
|
||||
@@ -40,6 +40,8 @@ function test() {
|
||||
function testExporter() {
|
||||
new makerjs.exporter.Exporter({});
|
||||
makerjs.exporter.toDXF(model);
|
||||
makerjs.exporter.toOpenJsCad(model);
|
||||
makerjs.exporter.toSTL(model);
|
||||
makerjs.exporter.toSVG(model);
|
||||
makerjs.exporter.tryGetModelUnits(model);
|
||||
}
|
||||
@@ -66,12 +68,17 @@ function test() {
|
||||
function testModel(){
|
||||
makerjs.model.combine(model, model, true, false, true, false);
|
||||
makerjs.model.convertUnits(model, makerjs.unitType.Centimeter);
|
||||
makerjs.model.countChildModels(model);
|
||||
makerjs.model.detachLoop(model);
|
||||
makerjs.model.findLoops(model);
|
||||
makerjs.model.getSimilarPathId(model, 'foo');
|
||||
makerjs.model.isPathInsideModel(paths.line, model);
|
||||
makerjs.model.mirror(model, false, true);
|
||||
makerjs.model.move(makerjs.model.originate(model, [9,9]), [0,0]);
|
||||
makerjs.model.moveRelative(model, [1,1]);
|
||||
makerjs.model.originate(model);
|
||||
makerjs.model.rotate(makerjs.model.scale(model, 6), 45, [0,0]);
|
||||
makerjs.model.scale(model, 7);
|
||||
makerjs.model.walkPaths(model, (modelContext: MakerJs.IModel, pathId: string, pathContext: MakerJs.IPath) => {});
|
||||
}
|
||||
|
||||
@@ -80,6 +87,7 @@ function test() {
|
||||
new makerjs.models.BoltCircle(7, 7, 7, 7),
|
||||
new makerjs.models.BoltRectangle(2, 2, 2),
|
||||
new makerjs.models.ConnectTheDots(true, [ [0,0], [1,1] ]),
|
||||
new makerjs.models.Dome(5, 7),
|
||||
new makerjs.models.Oval(7, 7),
|
||||
new makerjs.models.OvalArc(6, 4, 2, 12),
|
||||
new makerjs.models.Polygon(7, 5),
|
||||
@@ -141,7 +149,9 @@ function test() {
|
||||
makerjs.point.middle(paths.line);
|
||||
makerjs.point.mirror(p1, true, false);
|
||||
makerjs.point.rotate(p1, 5, p2);
|
||||
makerjs.point.rounded(p1);
|
||||
makerjs.point.scale(p2, 8);
|
||||
makerjs.point.serialize(p1);
|
||||
makerjs.point.subtract(p2, p1);
|
||||
makerjs.point.zero();
|
||||
}
|
||||
|
||||
Vendored
+125
-10
@@ -247,6 +247,37 @@ declare module MakerJs {
|
||||
*/
|
||||
path2Angles?: number[];
|
||||
}
|
||||
/**
|
||||
* Options when matching points
|
||||
*/
|
||||
interface IPointMatchOptions {
|
||||
/**
|
||||
* Optional exemplar of number of decimal places.
|
||||
*/
|
||||
accuracy?: number;
|
||||
}
|
||||
/**
|
||||
* Options to pass to model.findLoops.
|
||||
*/
|
||||
interface IFindLoopsOptions extends IPointMatchOptions {
|
||||
/**
|
||||
* Flag to remove looped paths from the original model.
|
||||
*/
|
||||
removeFromOriginal?: boolean;
|
||||
}
|
||||
/**
|
||||
* A path that may be indicated to "flow" in either direction between its endpoints.
|
||||
*/
|
||||
interface IPathDirectional extends IPath {
|
||||
/**
|
||||
* The endpoints of the path.
|
||||
*/
|
||||
endPoints: IPoint[];
|
||||
/**
|
||||
* Path flows forwards or reverse.
|
||||
*/
|
||||
reversed?: boolean;
|
||||
}
|
||||
/**
|
||||
* Path objects by id.
|
||||
*/
|
||||
@@ -302,6 +333,12 @@ declare module MakerJs {
|
||||
*/
|
||||
layer?: string;
|
||||
}
|
||||
/**
|
||||
* Callback signature for model.walkPaths().
|
||||
*/
|
||||
interface IModelPathCallback {
|
||||
(modelContext: IModel, pathId: string, pathContext: IPath): void;
|
||||
}
|
||||
/**
|
||||
* Test to see if an object implements the required properties of a model.
|
||||
*/
|
||||
@@ -408,6 +445,7 @@ declare module MakerJs.point {
|
||||
*
|
||||
* @param a First point.
|
||||
* @param b Second point.
|
||||
* @param accuracy Optional exemplar of number of decimal places.
|
||||
* @returns true if points are the same, false if they are not
|
||||
*/
|
||||
function areEqualRounded(a: IPoint, b: IPoint, accuracy?: number): boolean;
|
||||
@@ -456,7 +494,7 @@ declare module MakerJs.point {
|
||||
*/
|
||||
function fromPathEnds(pathContext: IPath): IPoint[];
|
||||
/**
|
||||
* Get the middle point of a path. Currently only supports Arc and Line paths.
|
||||
* Get the middle point of a path.
|
||||
*
|
||||
* @param pathContext The path object.
|
||||
* @param ratio Optional ratio (between 0 and 1) of point along the path. Default is .5 for middle.
|
||||
@@ -472,6 +510,14 @@ declare module MakerJs.point {
|
||||
* @returns Mirrored point.
|
||||
*/
|
||||
function mirror(pointToMirror: IPoint, mirrorX: boolean, mirrorY: boolean): IPoint;
|
||||
/**
|
||||
* Round the values of a point.
|
||||
*
|
||||
* @param pointContext The point to serialize.
|
||||
* @param accuracy Optional exemplar number of decimal places.
|
||||
* @returns A new point with the values rounded.
|
||||
*/
|
||||
function rounded(pointContext: IPoint, accuracy?: number): IPoint;
|
||||
/**
|
||||
* Rotate a point.
|
||||
*
|
||||
@@ -489,6 +535,14 @@ declare module MakerJs.point {
|
||||
* @returns A new point.
|
||||
*/
|
||||
function scale(pointToScale: IPoint, scaleValue: number): IPoint;
|
||||
/**
|
||||
* Get a string representation of a point.
|
||||
*
|
||||
* @param pointContext The point to serialize.
|
||||
* @param accuracy Optional exemplar of number of decimal places.
|
||||
* @returns String representing the point.
|
||||
*/
|
||||
function serialize(pointContext: IPoint, accuracy?: number): string;
|
||||
/**
|
||||
* Subtract a point from another point, and return the result as a new point. Shortcut to Add(a, b, subtract = true).
|
||||
*
|
||||
@@ -637,6 +691,13 @@ declare module MakerJs.paths {
|
||||
}
|
||||
}
|
||||
declare module MakerJs.model {
|
||||
/**
|
||||
* Count the number of child models within a given model.
|
||||
*
|
||||
* @param modelContext The model containing other models.
|
||||
* @returns Number of child models.
|
||||
*/
|
||||
function countChildModels(modelContext: IModel): number;
|
||||
/**
|
||||
* Get an unused id in the paths map with the same prefix.
|
||||
*
|
||||
@@ -702,12 +763,6 @@ declare module MakerJs.model {
|
||||
* @returns The scaled model (for chaining).
|
||||
*/
|
||||
function convertUnits(modeltoConvert: IModel, destUnitType: string): IModel;
|
||||
/**
|
||||
* Callback signature for walkPaths.
|
||||
*/
|
||||
interface IModelPathCallback {
|
||||
(modelContext: IModel, pathId: string, pathContext: IPath): void;
|
||||
}
|
||||
/**
|
||||
* Recursively walk through all paths for a given model.
|
||||
*
|
||||
@@ -717,6 +772,15 @@ declare module MakerJs.model {
|
||||
function walkPaths(modelContext: IModel, callback: IModelPathCallback): void;
|
||||
}
|
||||
declare module MakerJs.model {
|
||||
/**
|
||||
* Check to see if a path is inside of a model.
|
||||
*
|
||||
* @param pathContext The path to check.
|
||||
* @param modelContext The model to check against.
|
||||
* @param farPoint Optional point of reference which is outside the bounds of the modelContext.
|
||||
* @returns Boolean true if the path is inside of the modelContext.
|
||||
*/
|
||||
function isPathInsideModel(pathContext: IPath, modelContext: IModel, farPoint?: IPoint): boolean;
|
||||
/**
|
||||
* Combine 2 models. The models should be originated.
|
||||
*
|
||||
@@ -726,9 +790,10 @@ declare module MakerJs.model {
|
||||
* @param includeAOutsideB Flag to include paths from modelA which are outside of modelB.
|
||||
* @param includeBInsideA Flag to include paths from modelB which are inside of modelA.
|
||||
* @param includeBOutsideA Flag to include paths from modelB which are outside of modelA.
|
||||
* @param keepDuplicates Flag to include paths which are duplicate in both models.
|
||||
* @param farPoint Optional point of reference which is outside the bounds of both models.
|
||||
*/
|
||||
function combine(modelA: IModel, modelB: IModel, includeAInsideB: boolean, includeAOutsideB: boolean, includeBInsideA: boolean, includeBOutsideA: boolean, farPoint?: IPoint): void;
|
||||
function combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, keepDuplicates?: boolean, farPoint?: IPoint): void;
|
||||
}
|
||||
declare module MakerJs.units {
|
||||
/**
|
||||
@@ -927,7 +992,7 @@ declare module MakerJs.path {
|
||||
* @param line2 Second line to fillet, which will be modified to fit the fillet.
|
||||
* @returns Arc path object of the new fillet.
|
||||
*/
|
||||
function dogbone(line1: IPathLine, line2: IPathLine, filletRadius: number): IPathArc;
|
||||
function dogbone(line1: IPathLine, line2: IPathLine, filletRadius: number, options?: IPointMatchOptions): IPathArc;
|
||||
/**
|
||||
* Adds a round corner to the inside angle between 2 paths. The paths must meet at one point.
|
||||
*
|
||||
@@ -935,7 +1000,7 @@ declare module MakerJs.path {
|
||||
* @param path2 Second path to fillet, which will be modified to fit the fillet.
|
||||
* @returns Arc path object of the new fillet.
|
||||
*/
|
||||
function fillet(path1: IPath, path2: IPath, filletRadius: number): IPathArc;
|
||||
function fillet(path1: IPath, path2: IPath, filletRadius: number, options?: IPointMatchOptions): IPathArc;
|
||||
}
|
||||
declare module MakerJs.kit {
|
||||
/**
|
||||
@@ -998,6 +1063,22 @@ declare module MakerJs.kit {
|
||||
*/
|
||||
function getParameterValues(ctor: IKit): any[];
|
||||
}
|
||||
declare module MakerJs.model {
|
||||
/**
|
||||
* Find paths that have common endpoints and form loops.
|
||||
*
|
||||
* @param modelContext The model to search for loops.
|
||||
* @param options Optional options object.
|
||||
* @returns A new model with child models ranked according to their containment within other found loops. The paths of models will be IPathDirectionalWithPrimeContext.
|
||||
*/
|
||||
function findLoops(modelContext: IModel, options?: IFindLoopsOptions): IModel;
|
||||
/**
|
||||
* Remove all paths in a loop model from the model(s) which contained them.
|
||||
*
|
||||
* @param loopToDetach The model to search for loops.
|
||||
*/
|
||||
function detachLoop(loopToDetach: IModel): void;
|
||||
}
|
||||
declare module MakerJs.exporter {
|
||||
/**
|
||||
* Attributes for an XML tag.
|
||||
@@ -1052,6 +1133,34 @@ declare module MakerJs.exporter {
|
||||
toString(): string;
|
||||
}
|
||||
}
|
||||
declare module MakerJs.exporter {
|
||||
function toOpenJsCad(modelToExport: IModel, options?: IOpenJsCadOptions): string;
|
||||
function toOpenJsCad(pathsToExport: IPath[], options?: IOpenJsCadOptions): string;
|
||||
function toOpenJsCad(pathToExport: IPath, options?: IOpenJsCadOptions): string;
|
||||
/**
|
||||
* Executes a JavaScript string with the OpenJsCad engine - converts 2D to 3D.
|
||||
*
|
||||
* @param modelToExport Model object to export.
|
||||
* @param options Export options object.
|
||||
* @param options.extrusion Height of 3D extrusion.
|
||||
* @param options.resolution Size of facets.
|
||||
* @returns String of STL format of 3D object.
|
||||
*/
|
||||
function toSTL(modelToExport: IModel, options?: IOpenJsCadOptions): string;
|
||||
/**
|
||||
* OpenJsCad export options.
|
||||
*/
|
||||
interface IOpenJsCadOptions extends IFindLoopsOptions {
|
||||
/**
|
||||
* Optional depth of 3D extrusion.
|
||||
*/
|
||||
extrusion?: number;
|
||||
/**
|
||||
* Optional size of curve facets.
|
||||
*/
|
||||
facetSize?: number;
|
||||
}
|
||||
}
|
||||
declare module MakerJs.exporter {
|
||||
function toSVG(modelToExport: IModel, options?: ISVGRenderOptions): string;
|
||||
function toSVG(pathsToExport: IPath[], options?: ISVGRenderOptions): string;
|
||||
@@ -1118,6 +1227,12 @@ declare module MakerJs.models {
|
||||
constructor(width: number, height: number, holeRadius: number);
|
||||
}
|
||||
}
|
||||
declare module MakerJs.models {
|
||||
class Dome implements IModel {
|
||||
paths: IPathMap;
|
||||
constructor(width: number, height: number, radius?: number);
|
||||
}
|
||||
}
|
||||
declare module MakerJs.models {
|
||||
class RoundRectangle implements IModel {
|
||||
paths: IPathMap;
|
||||
|
||||
Vendored
+167
-83
@@ -5,90 +5,174 @@
|
||||
|
||||
//Mithril type definitions for Typescript
|
||||
|
||||
interface MithrilStatic {
|
||||
(selector: string, attributes: Object, children?: any): MithrilVirtualElement;
|
||||
(selector: string, children?: any): MithrilVirtualElement;
|
||||
prop<T>(value?: T): (value?: T) => T;
|
||||
prop<T>(promise: MithrilPromise<T>): MithrilPromiseProperty<T>;
|
||||
withAttr(property: string, callback: (value: any) => void): (e: Event) => any;
|
||||
module(rootElement: Node, module: MithrilModule): void;
|
||||
trust(html: string): String;
|
||||
render(rootElement: Element, children?: any): void;
|
||||
render(rootElement: HTMLDocument, children?: any): void;
|
||||
redraw: MithrilRedraw;
|
||||
route: MithrilRoute;
|
||||
request(options: MithrilXHROptions): MithrilPromise<any>;
|
||||
deferred<T>(): MithrilDeferred<T>;
|
||||
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T>;
|
||||
startComputation(): void;
|
||||
endComputation(): void;
|
||||
declare module _mithril {
|
||||
interface MithrilStatic {
|
||||
|
||||
<T extends MithrilController>(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement|MithrilComponent<T>>): MithrilVirtualElement;
|
||||
<T extends MithrilController>(selector: string, ...children: Array<string|MithrilVirtualElement|MithrilComponent<T>>): MithrilVirtualElement;
|
||||
|
||||
prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
|
||||
prop<T>(value: T): MithrilProperty<T>;
|
||||
prop(): MithrilProperty<Object>; // might be that this should be Property<any>
|
||||
|
||||
withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
|
||||
|
||||
module<T extends MithrilController>(rootElement: Node, component: MithrilComponent<T>): T;
|
||||
module<T extends MithrilController>(rootElement: Node): T;
|
||||
mount<T extends MithrilController>(rootElement: Node, component: MithrilComponent<T>): T;
|
||||
mount<T extends MithrilController>(rootElement: Node): T;
|
||||
|
||||
component<T extends MithrilController>(component: MithrilComponent<T>, ...args: Array<any>): MithrilComponent<T>
|
||||
|
||||
trust(html: string): string;
|
||||
|
||||
render(rootElement: Element|HTMLDocument): void;
|
||||
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
|
||||
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
|
||||
|
||||
redraw: {
|
||||
(force?: boolean): void;
|
||||
strategy: MithrilProperty<string>;
|
||||
}
|
||||
|
||||
route: {
|
||||
<T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||
<T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||
|
||||
(element: Element, isInitialized: boolean, context: Object, vdom: Object): void;
|
||||
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
|
||||
(): string;
|
||||
|
||||
param(key: string): string;
|
||||
mode: string;
|
||||
buildQueryString(data: Object): String
|
||||
parseQueryString(data: String): Object
|
||||
}
|
||||
|
||||
request<T>(options: MithrilXHROptions): MithrilPromise<T>;
|
||||
|
||||
deferred: {
|
||||
onerror(e: Error): void;
|
||||
<T>(): MithrilDeferred<T>;
|
||||
}
|
||||
|
||||
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
|
||||
|
||||
startComputation(): void;
|
||||
endComputation(): void;
|
||||
|
||||
// For test suite
|
||||
deps: {
|
||||
(mockWindow: Window): Window;
|
||||
factory: Object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export interface MithrilVirtualElement {
|
||||
key?: number;
|
||||
tag?: string;
|
||||
attrs?: MithrilAttributes;
|
||||
children?: any[];
|
||||
}
|
||||
|
||||
// Configuration function for an element
|
||||
interface MithrilElementConfig {
|
||||
(element: Element, isInitialized: boolean, context?: any, vdom?: MithrilVirtualElement): void;
|
||||
}
|
||||
|
||||
// Attributes on a virtual element
|
||||
interface MithrilAttributes {
|
||||
title?: string;
|
||||
className?: string;
|
||||
class?: string;
|
||||
config?: MithrilElementConfig;
|
||||
}
|
||||
|
||||
// Defines the subset of Event that Mithril needs
|
||||
interface MithrilEvent {
|
||||
currentTarget: Element;
|
||||
}
|
||||
|
||||
interface MithrilController {
|
||||
onunload?(evt: Event): any;
|
||||
}
|
||||
|
||||
interface MithrilControllerFunction extends MithrilController {
|
||||
(): any;
|
||||
}
|
||||
|
||||
interface MithrilView<T extends MithrilController> {
|
||||
(ctrl: T): string|MithrilVirtualElement;
|
||||
}
|
||||
|
||||
interface MithrilComponent<T extends MithrilController> {
|
||||
controller: MithrilControllerFunction|{ new(): T };
|
||||
view: MithrilView<T>;
|
||||
}
|
||||
|
||||
interface MithrilProperty<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilRoutes<T extends MithrilController> {
|
||||
[key: string]: MithrilComponent<T>;
|
||||
}
|
||||
|
||||
|
||||
interface MithrilDeferred<T> {
|
||||
resolve(value?: T): void;
|
||||
reject(value?: any): void;
|
||||
promise: MithrilPromise<T>;
|
||||
}
|
||||
|
||||
interface MithrilSuccessCallback<T, U> {
|
||||
(value: T): U;
|
||||
(value: T): MithrilPromise<U>;
|
||||
}
|
||||
|
||||
interface MithrilErrorCallback<U> {
|
||||
(value: Error): U;
|
||||
(value: string): U;
|
||||
}
|
||||
|
||||
interface MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
then<U>(success: (value: T) => U): MithrilPromise<U>;
|
||||
then<U>(success: (value: T) => MithrilPromise<U>): MithrilPromise<U>;
|
||||
then<U,V>(success: (value: T) => U, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
|
||||
then<U,V>(success: (value: T) => MithrilPromise<U>, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
|
||||
}
|
||||
interface MithrilXHROptions {
|
||||
method?: string;
|
||||
url: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
data?: any;
|
||||
background?: boolean;
|
||||
unwrapSuccess?(data: any): any;
|
||||
unwrapError?(data: any): any;
|
||||
serialize?(dataToSerialize: any): string;
|
||||
deserialize?(dataToDeserialize: string): any;
|
||||
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
|
||||
type?(data: Object): void;
|
||||
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
|
||||
dataType?: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface MithrilRoute {
|
||||
(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
|
||||
(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
|
||||
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
|
||||
(element: Element, isInitialized: boolean): void;
|
||||
(): string;
|
||||
mode: string;
|
||||
param: MithrilParam;
|
||||
buildQueryString(data: Object): string;
|
||||
parseQueryString(queryString: string): Object;
|
||||
}
|
||||
declare var Mithril: _mithril.MithrilStatic;
|
||||
declare var m: _mithril.MithrilStatic;
|
||||
|
||||
interface MithrilParam {
|
||||
(param: string): string;
|
||||
declare module "mithril" {
|
||||
export = m;
|
||||
}
|
||||
|
||||
interface MithrilRedraw {
|
||||
(): void;
|
||||
strategy: (value?: string) => string;
|
||||
}
|
||||
|
||||
interface MithrilVirtualElement {
|
||||
tag: string;
|
||||
attrs: Object;
|
||||
children: any;
|
||||
}
|
||||
|
||||
interface MithrilModule {
|
||||
controller: Function;
|
||||
view: (controller?: any) => MithrilVirtualElement;
|
||||
}
|
||||
|
||||
interface MithrilDeferred<T> {
|
||||
resolve(value?: T): void;
|
||||
reject(value?: any): void;
|
||||
promise: MithrilPromise<T>;
|
||||
}
|
||||
|
||||
interface MithrilPromise<T> {
|
||||
(value?: T): T;
|
||||
then<R>(successCallback?: (value: T) => R, errorCallback?: (value: any) => any): MithrilPromise<R>;
|
||||
then<R>(successCallback?: (value: T) => MithrilPromise<R>, errorCallback?: (value: any) => any): MithrilPromise<R>;
|
||||
}
|
||||
|
||||
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilXHROptions {
|
||||
method: string;
|
||||
url: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
data?: any;
|
||||
background?: boolean;
|
||||
unwrapSuccess?(data: any): any;
|
||||
unwrapError?(data: any): any;
|
||||
serialize?(dataToSerialize: any): string;
|
||||
deserialize?(dataToDeserialize: string): any;
|
||||
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
|
||||
type?(data: Object): void;
|
||||
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
|
||||
}
|
||||
|
||||
declare var Mithril: MithrilStatic;
|
||||
declare var m: MithrilStatic;
|
||||
|
||||
@@ -20,6 +20,8 @@ class DialogTestController {
|
||||
template: "login.html",
|
||||
className: "default flat-ui",
|
||||
closeByEscape: false,
|
||||
data: "string",
|
||||
disableAnimation: false,
|
||||
name: "login-popup"
|
||||
});
|
||||
|
||||
|
||||
Vendored
+10
@@ -61,6 +61,12 @@ declare module angular.dialog {
|
||||
* It will be appended with the "ngdialog" class e.g. className is "default-theme flat-ui" it will be class="ngdialog default-theme flat-ui".
|
||||
*/
|
||||
className?: string;
|
||||
|
||||
/**
|
||||
* If true then animation for the dialog will be disabled, default false.
|
||||
*/
|
||||
disableAnimation?: boolean;
|
||||
|
||||
/**
|
||||
* If false it allows to hide overlay div behind the modals, default true.
|
||||
*/
|
||||
@@ -106,5 +112,9 @@ declare module angular.dialog {
|
||||
* Scope object that will be passed to dialog. If you use controller with separate $scope service this object will be passed to $scope.$parent param.
|
||||
*/
|
||||
scope?: ng.IScope;
|
||||
/**
|
||||
* Any serializable data that you want to be stored in the controller's dialog scope.
|
||||
*/
|
||||
data?: string|Object|any[];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='../angularjs/angular.d.ts'/>
|
||||
/// <reference path="ng-notify.d.ts" />
|
||||
|
||||
class NgNotifyTestController {
|
||||
|
||||
static $inject = ['$scope', 'ngNotify'];
|
||||
|
||||
constructor($scope:ng.IScope, ngNotify:ngNotify.INotifyService) {
|
||||
ngNotify.set('Your error message goes here!', 'error');
|
||||
}
|
||||
};
|
||||
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
// Type definitions for ng-notify 0.7.1
|
||||
// Project: https://github.com/matowens/ng-notify
|
||||
// Definitions by: Nick Zamosenchuk <https://github.com/nzamosenchuk>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
/// <reference path='../angularjs/angular.d.ts'/>
|
||||
|
||||
declare module ngNotify {
|
||||
|
||||
/**
|
||||
* Contains the options used to configure notification.
|
||||
*/
|
||||
interface IUserOptions{
|
||||
type?: string;
|
||||
theme?: string;
|
||||
position?: string;
|
||||
duration?: number;
|
||||
sticky?: boolean;
|
||||
button?: boolean;
|
||||
html?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply and lightweight notification service for AngularJS
|
||||
*/
|
||||
interface INotifyService {
|
||||
|
||||
/**
|
||||
* Allows to create a whole new set of styles for each notification type.
|
||||
* @param themeName The name used when setting the theme in the config object.
|
||||
* @param className The class used to target this theme in the stylesheet.
|
||||
*/
|
||||
addTheme(themeName:string, className:string):void;
|
||||
|
||||
/**
|
||||
* Allows to create a new type of notification to use in their app.
|
||||
* @param typeName The name used to trigger this notification type in the set method.
|
||||
* @param className The class used to target this type in the stylesheet.
|
||||
*/
|
||||
addType(typeName:string, className:string):void;
|
||||
|
||||
/**
|
||||
* Sets default settings for all notifications to take into account when displaying.
|
||||
* @param userOptions Notification configuration object
|
||||
*/
|
||||
config(userOptions: IUserOptions):void;
|
||||
|
||||
/**
|
||||
* Manually dismisses any sticky notifications that may still be set.
|
||||
*/
|
||||
dismiss():void;
|
||||
|
||||
/**
|
||||
* Displays a notification message.
|
||||
* @param message A message text to display.
|
||||
*/
|
||||
set(message: string):void;
|
||||
|
||||
/**
|
||||
* Displays a notification message and sets the type for this one notification.
|
||||
* @param message A message text to display.
|
||||
* @param type The type of the notification.
|
||||
*/
|
||||
set(message: string, type: string):void;
|
||||
|
||||
/**
|
||||
* displays a notification message and sets the formatting/behavioral options for this one notification.
|
||||
* @param message A message text to display.
|
||||
* @param userOptions Notification configuration object.
|
||||
*/
|
||||
set(message: string, userOptions: IUserOptions):void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/// <reference path="../es6-promise/es6-promise.d.ts"/>
|
||||
/// <reference path="./react-datagrid.d.ts" />
|
||||
/// <reference path="../react/react.d.ts" />
|
||||
|
||||
import * as React from "react";
|
||||
import ReactDataGrid = require("react-datagrid");
|
||||
|
||||
var data: any[] = [];
|
||||
|
||||
var columns: ReactDataGrid.Column[] = [
|
||||
{ name: 'index', title: '#', width: 50 },
|
||||
{ name: 'firstName', style: { color: 'red' }, visible: true},
|
||||
{ name: 'lastName', render: (v) => {return v + " Phd"}},
|
||||
{ name: 'city', textAlign: 'right', defaultVisible: true},
|
||||
{ name: 'email', defaultHidden: true }
|
||||
];
|
||||
var selected = {};
|
||||
var sortInfo: ReactDataGrid.SortInfo[] = [ { name: 'country', dir: 'asc'}]
|
||||
|
||||
export module X {
|
||||
export class ExampleBasic extends React.Component<{},{}> {
|
||||
render(): React.ReactElement<any> {
|
||||
return (
|
||||
<ReactDataGrid
|
||||
key={0}
|
||||
ref='dlgBasic'
|
||||
idProperty='id'
|
||||
dataSource={data}
|
||||
columns={columns}/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleFull extends React.Component<{},{}> {
|
||||
|
||||
render(): React.ReactElement<any> {
|
||||
return (
|
||||
<ReactDataGrid
|
||||
key={1}
|
||||
ref='dlgFull'
|
||||
idProperty='id'
|
||||
dataSource={data}
|
||||
columns={columns}
|
||||
style={{height: 500}}
|
||||
withColumnMenu={false}
|
||||
selected={selected}
|
||||
sortInfo={sortInfo}
|
||||
groupBy={['country','grade']}
|
||||
liveFilter={true}
|
||||
emptyText={'No records'}
|
||||
loading={true}
|
||||
loadMaskOverHeader={false}
|
||||
rowStyle={{color: 'blue'}}
|
||||
showCellBorders="vertical"
|
||||
rowHeight={50}
|
||||
defaultPageSize={110}
|
||||
paginationToolbarProps={{
|
||||
pageSizes: [100, 1000,2000],
|
||||
showPageSize: false,
|
||||
showRefreshIcon: false,
|
||||
iconSize: 30,
|
||||
iconProps: {
|
||||
style: {fill: '#FF8484'},
|
||||
overStyle: {fill: 'red'},
|
||||
disabledStyle: { fill: '#808080'}
|
||||
}
|
||||
}}
|
||||
pagination={true}
|
||||
page={1}
|
||||
pageSize={100}
|
||||
onPageChange={(page: number) => {}}
|
||||
onPageSizeChange={(pageSize: number, props: ReactDataGrid.DataGridProps) => {}}
|
||||
onColumnOrderChange={(index: number, dropIndex: number) => {}}
|
||||
onColumnResize={(firstCol: ReactDataGrid.Column, firstSize: number, secondCol: ReactDataGrid.Column, secondSize: number) => {}}
|
||||
onSelectionChange={(newSelectedId: string, data: any) => {}}
|
||||
onSortChange={(sortInfo: ReactDataGrid.SortInfo[]) => {}}
|
||||
onFilter={(column: ReactDataGrid.Column, value: any, allFilterValues: any[]) => {} }
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
Vendored
+311
@@ -0,0 +1,311 @@
|
||||
// Type definitions for react-datagrid 1.2.15
|
||||
// Project: https://github.com/zippyui/react-datagrid.git
|
||||
// Definitions by: Stephen Jelfs <https://github.com/stephenjelfs>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../react/react.d.ts"/>
|
||||
/// <reference path="../es6-promise/es6-promise.d.ts"/>
|
||||
|
||||
declare module "react-datagrid" {
|
||||
import DataGrid = ReactDataGrid.DataGrid;
|
||||
export = DataGrid;
|
||||
}
|
||||
|
||||
declare namespace ReactDataGrid {
|
||||
import React = __React;
|
||||
|
||||
interface DataGridProps extends React.Props<DataGrid> {
|
||||
/**
|
||||
* Array/String/Function/Promise - for local data, an array of object
|
||||
* to render in the grid. For remote data, a string url, or a function
|
||||
* that returns a promise.
|
||||
*/
|
||||
dataSource: any[] | string | ((query: {pageSize: number, skip: number}) => Promise<any[]>);
|
||||
|
||||
dataSourceCount?: number;
|
||||
|
||||
/**
|
||||
* String - the name of the property where the id is found for each
|
||||
* object in the data array.
|
||||
*/
|
||||
idProperty: string;
|
||||
|
||||
/**
|
||||
* Array - an array of columns that are going to be rendered in the
|
||||
* grid.
|
||||
*/
|
||||
columns: Column[];
|
||||
|
||||
/**
|
||||
* Sorting the data array is not done by the grid. You can however
|
||||
* pass in sort info so the grid renders with sorting icons as needed.
|
||||
*/
|
||||
onSortChange?: (sortInfo: SortInfo[]) => void;
|
||||
|
||||
/**
|
||||
* Array - an array with sorting information.
|
||||
*/
|
||||
sortInfo?: SortInfo[];
|
||||
|
||||
style?: __React.CSSProperties;
|
||||
|
||||
/**
|
||||
* Object/Function - you can specify either a style object to be
|
||||
* applied to all rows, or a function. The function is called with
|
||||
* (data, props) (so you have access to props.index for example) and
|
||||
* is expected to return a style object.
|
||||
*/
|
||||
rowStyle?: __React.CSSProperties | ((data: any, props: RowProps) => React.CSSProperties);
|
||||
|
||||
/**
|
||||
* Boolean - show a column menu to show/hide columns.
|
||||
*/
|
||||
withColumnMenu?: boolean;
|
||||
|
||||
/**
|
||||
* If you want to enable column reordering, just specify the
|
||||
* onColumnOrderChange prop on the grid:
|
||||
*/
|
||||
onColumnOrderChange?: (index: number, dropIndex: number) => void;
|
||||
|
||||
/**
|
||||
* If you want to enable column resized, just specify the
|
||||
* onColumnResize prop on the grid:
|
||||
*/
|
||||
onColumnResize?: (firstCol: Column, firstSize: number,
|
||||
secondCol: Column, secondSize: number) => void;
|
||||
|
||||
/**
|
||||
* If you want to enable selection, just specify the
|
||||
* onSelectionChange prop on the grid:
|
||||
*/
|
||||
onSelectionChange?: (newSelected: {}, data: any) => void;
|
||||
|
||||
/**
|
||||
* When a column is shown/hidden, you can be notified using the
|
||||
* onColumnVisibilityChange callback prop.
|
||||
*/
|
||||
onColumnVisibilityChange?: (column: Column, visibility: boolean) => void;
|
||||
|
||||
/**
|
||||
* The current selection.
|
||||
*/
|
||||
selected?: {};
|
||||
|
||||
/**
|
||||
* Group rows by matching values.
|
||||
*/
|
||||
groupBy?: any[];
|
||||
|
||||
/**
|
||||
* If you want to enable filter, just specify the
|
||||
* onFilter prop on the grid:
|
||||
*/
|
||||
onFilter?: (column: Column, value: any, allFilterValues: any[]) => void;
|
||||
|
||||
/**
|
||||
* To apply the filter while typing.
|
||||
*/
|
||||
liveFilter?: boolean;
|
||||
|
||||
/**
|
||||
* Empty text for no records.
|
||||
*/
|
||||
emptyText?: string;
|
||||
|
||||
/**
|
||||
* Loading grid.
|
||||
*/
|
||||
loading?: boolean;
|
||||
|
||||
/**
|
||||
* If you dont want loadMask over header, specify
|
||||
*/
|
||||
loadMaskOverHeader?: boolean;
|
||||
|
||||
/**
|
||||
* Show cell borders. Other valid values: 'horizontal', 'vertical'.
|
||||
*/
|
||||
showCellBorders?: boolean | string;
|
||||
|
||||
/**
|
||||
* Custom row height.
|
||||
*/
|
||||
rowHeight?: number;
|
||||
|
||||
/**
|
||||
* When you have remote data, pagination is setup by default. If you
|
||||
* want to disable pagination, specify the pagination prop with a false
|
||||
* value.
|
||||
*/
|
||||
pagination?: boolean;
|
||||
defaultPageSize?: number;
|
||||
defaultPage?: number;
|
||||
|
||||
/**
|
||||
* Number - controlled alternative for defaultPageSize. When pageSize
|
||||
* changes, onPageSizeChange(pageSize) is called.
|
||||
*/
|
||||
pageSize?: number;
|
||||
|
||||
/**
|
||||
* Number - controlled alternative for defaultPage. When page changes,
|
||||
* onPageChange(page) is called.
|
||||
*/
|
||||
page?: number;
|
||||
|
||||
/**
|
||||
* Customize the pagination toolbar.
|
||||
*/
|
||||
paginationToolbarProps?: PaginationToolbarProps;
|
||||
|
||||
/**
|
||||
* handle page changes.
|
||||
*/
|
||||
onPageChange?: (page: number) => void;
|
||||
|
||||
/**
|
||||
* handle page size changes.
|
||||
*/
|
||||
onPageSizeChange?: (pageSize: number, props: DataGridProps) => void;
|
||||
}
|
||||
|
||||
interface SortInfo {
|
||||
name: string;
|
||||
dir: string;
|
||||
}
|
||||
|
||||
interface Column {
|
||||
/**
|
||||
* String - each column should have a name property.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* String/ReactElement - a title to show in the header. If not
|
||||
* specified, a humanized version of name will be used. Can be a string
|
||||
* or anything that React can render, so you can customize it as you
|
||||
* please.
|
||||
*/
|
||||
title?: string | React.ReactElement<any>;
|
||||
|
||||
/**
|
||||
* Function - if you want custom rendering, specify this property.
|
||||
*
|
||||
* The column.render function is called with 3 args:
|
||||
* value - the default value to be rendered (equals to data[column.name])
|
||||
* data - the corresponding data object for the current row
|
||||
cellProps - an object with props for the current cell
|
||||
*/
|
||||
render?: (value: any, data: any, cellProps: CellProps) => any;
|
||||
|
||||
/**
|
||||
* Object - if you want cells in this column to be have a custom
|
||||
* style.
|
||||
*/
|
||||
style?: __React.CSSProperties;
|
||||
|
||||
/**
|
||||
* String - one of 'left', 'right', 'center'.
|
||||
*/
|
||||
textAlign?: string;
|
||||
|
||||
/**
|
||||
* String - a className to be applied to all cells in this column
|
||||
*/
|
||||
className?: string;
|
||||
|
||||
width?: number;
|
||||
|
||||
minWidth?: number;
|
||||
|
||||
/**
|
||||
* Columns are flexible via flexbox. Specify a flex property for this.
|
||||
* Unless a column specifies a flex or a width property, it is assumed
|
||||
* to have flex: 1.
|
||||
*/
|
||||
flex?: number;
|
||||
|
||||
/**
|
||||
* Specify a column as visible/hidden.
|
||||
*/
|
||||
defaultVisible?: boolean;
|
||||
defaultHidden?: boolean;
|
||||
|
||||
/**
|
||||
* Boolean - controlled (which means you have to manually set column
|
||||
* visibility when it changes, by using onColumnVisibilityChange).
|
||||
*/
|
||||
visible?: boolean;
|
||||
}
|
||||
|
||||
interface CellProps {
|
||||
/**
|
||||
* the index of the row
|
||||
*/
|
||||
rowIndex: number;
|
||||
|
||||
/**
|
||||
* the index of the column
|
||||
*/
|
||||
index: number;
|
||||
|
||||
/**
|
||||
* a style for the cell
|
||||
*/
|
||||
style: React.CSSProperties;
|
||||
|
||||
/**
|
||||
* a class name for the cell
|
||||
*/
|
||||
className: string;
|
||||
}
|
||||
|
||||
interface RowProps {
|
||||
/**
|
||||
* the index of the row
|
||||
*/
|
||||
index: number;
|
||||
|
||||
/**
|
||||
* a class name for the row when the mouse is over it
|
||||
*/
|
||||
overClassName: string;
|
||||
|
||||
/**
|
||||
* a class name for the row when selected
|
||||
*/
|
||||
selectedClassName: string;
|
||||
|
||||
/**
|
||||
* a class name for the row
|
||||
*/
|
||||
className: string;
|
||||
}
|
||||
|
||||
interface PaginationToolbarProps {
|
||||
/**
|
||||
* Available page sizes.
|
||||
*/
|
||||
pageSizes: number[];
|
||||
|
||||
/**
|
||||
* Hide/show page sizes.
|
||||
*/
|
||||
showPageSize: boolean;
|
||||
|
||||
/**
|
||||
* Customize icons.
|
||||
*/
|
||||
showRefreshIcon: boolean;
|
||||
iconSize: number;
|
||||
iconProps: {
|
||||
style: React.SVGAttributes,
|
||||
overStyle: React.SVGAttributes,
|
||||
disabledStyle: React.SVGAttributes
|
||||
}
|
||||
}
|
||||
|
||||
export class DataGrid extends __React.Component<DataGridProps, {}> {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
/// <reference path="sql.js.d.ts" />
|
||||
|
||||
import fs = require("fs");
|
||||
import SQL = require("sql.js");
|
||||
|
||||
var DB_PATH = "data.db";
|
||||
|
||||
function createFile(path: string): void {
|
||||
var fd = fs.openSync(path, "a");
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
|
||||
// Open the database file. If it does not exist, create a blank database in memory.
|
||||
var databaseData: Buffer;
|
||||
databaseData = fs.existsSync(DB_PATH) ? fs.readFileSync(DB_PATH) : null;
|
||||
var db = new SQL.Database(databaseData);
|
||||
|
||||
// Create a new table 'test_table' in the database in memory.
|
||||
var createTableStatement =
|
||||
"DROP TABLE IF EXISTS test_table;" +
|
||||
"CREATE TABLE test_table (id INTEGER PRIMARY KEY, content TEXT);";
|
||||
db.run(createTableStatement);
|
||||
|
||||
// Insert 2 records for testing.
|
||||
var insertRecordStatement =
|
||||
"INSERT INTO test_table (id, content) VALUES (@id, @content);";
|
||||
db.run(insertRecordStatement, {
|
||||
"@id": 1,
|
||||
"@content": "Content 1"
|
||||
});
|
||||
db.run(insertRecordStatement, {
|
||||
"@id": 2,
|
||||
"@content": "Content 2"
|
||||
});
|
||||
|
||||
try {
|
||||
// This query will throw exception: primary key constraint failed.
|
||||
db.run(insertRecordStatement, {
|
||||
"@id": 1,
|
||||
"@content": "Content 3"
|
||||
});
|
||||
} catch (ex) {
|
||||
console.warn(ex);
|
||||
}
|
||||
|
||||
// A simple SELECT query.
|
||||
var selectRecordStatement =
|
||||
"SELECT * FROM test_table WHERE id = @id;"
|
||||
var selectStatementObject = db.prepare(selectRecordStatement);
|
||||
var results = selectStatementObject.get({
|
||||
"@id": 1
|
||||
});
|
||||
console.log(results);
|
||||
selectStatementObject.free();
|
||||
|
||||
// Access the results one by one, asynchronously.
|
||||
var selectRecordsStatement =
|
||||
"SELECT * FROM test_table;";
|
||||
db.each(
|
||||
selectRecordsStatement,
|
||||
(obj: { [columnName: string]: number | string | Uint8Array }): void => {
|
||||
console.log(obj);
|
||||
},
|
||||
(): void => {
|
||||
console.info("Iteration done.");
|
||||
dbAccessDone();
|
||||
});
|
||||
|
||||
|
||||
function dbAccessDone(): void {
|
||||
// Save the database into SQLite version 3 format.
|
||||
if (!fs.existsSync(DB_PATH)) {
|
||||
createFile(DB_PATH);
|
||||
}
|
||||
var exportedData = db.export();
|
||||
fs.writeFileSync(DB_PATH, exportedData);
|
||||
|
||||
// Finally, close the database connection and release the resources in memory.
|
||||
db.close();
|
||||
}
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
// Type definitions for sql.js
|
||||
// Project: https://github.com/kripken/sql.js
|
||||
// Definitions by: George Wu <https://github.com/Hozuki/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module "sql.js" {
|
||||
|
||||
class Database {
|
||||
constructor(data: Buffer);
|
||||
constructor(data: Uint8Array);
|
||||
constructor(data: number[]);
|
||||
|
||||
run(sql: string): Database;
|
||||
run(sql: string, params: { [key: string]: number | string | Uint8Array }): Database;
|
||||
run(sql: string, params: (number | string | Uint8Array)[]): Database;
|
||||
|
||||
exec(sql: string): QueryResults[];
|
||||
|
||||
each(sql: string, callback: (obj: { [columnName: string]: number | string | Uint8Array }) => void, done: () => void): void;
|
||||
each(sql: string, params: { [key: string]: number | string | Uint8Array }, callback: (obj: { [columnName: string]: number | string | Uint8Array }) => void, done: () => void): void;
|
||||
each(sql: string, params: (number | string | Uint8Array)[], callback: (obj: { [columnName: string]: number | string | Uint8Array }) => void, done: () => void): void;
|
||||
|
||||
prepare(sql: string): Statement;
|
||||
prepare(sql: string, params: { [key: string]: number | string | Uint8Array }): Statement;
|
||||
prepare(sql: string, params: (number | string | Uint8Array)[]): Statement;
|
||||
|
||||
export(): Uint8Array;
|
||||
|
||||
close(): void;
|
||||
}
|
||||
|
||||
class Statement {
|
||||
bind(): boolean;
|
||||
bind(values: { [key: string]: number | string | Uint8Array }): boolean;
|
||||
bind(values: (number | string | Uint8Array)[]): boolean;
|
||||
|
||||
step(): boolean;
|
||||
|
||||
get(): (number | string | Uint8Array)[];
|
||||
get(params: { [key: string]: number | string | Uint8Array }): (number | string | Uint8Array)[];
|
||||
get(params: (number | string | Uint8Array)[]): (number | string | Uint8Array)[];
|
||||
|
||||
getColumnNames(): string[];
|
||||
|
||||
getAsObject(): { [columnName: string]: number | string | Uint8Array };
|
||||
getAsObject(params: { [key: string]: number | string | Uint8Array }): { [columnName: string]: number | string | Uint8Array };
|
||||
getAsObject(params: (number | string | Uint8Array)[]): { [columnName: string]: number | string | Uint8Array };
|
||||
|
||||
run(): void;
|
||||
run(values: { [key: string]: number | string | Uint8Array }): void;
|
||||
run(values: (number | string | Uint8Array)[]): void;
|
||||
|
||||
reset(): void;
|
||||
|
||||
freemem(): void;
|
||||
|
||||
free(): boolean;
|
||||
}
|
||||
|
||||
interface QueryResults {
|
||||
columns: string[];
|
||||
values: (number | string | Uint8Array)[][];
|
||||
}
|
||||
|
||||
}
|
||||
+411
@@ -0,0 +1,411 @@
|
||||
// adapted from `cat wu.js/test/* |sed '/= require/d'> wu-tests.ts`
|
||||
///<reference path="wu.d.ts" />
|
||||
declare var describe: any, it: any, mocha: any, assert: {
|
||||
iterable:any;
|
||||
eqSet<T>(expected:Set<T>, actual: Iterable<T>): any;
|
||||
ok:any;
|
||||
equal<T>(x:T, y:T): any;
|
||||
eqArray<T>(x:T[], y:Iterable<T>): any;
|
||||
deepEqual<T>(x:T, y:T): any;
|
||||
}
|
||||
|
||||
// Helper for asserting that the given thing is iterable.
|
||||
assert.iterable = thing => {
|
||||
assert.ok(wu(thing));
|
||||
};
|
||||
|
||||
// Helper for asserting that all the elements yielded from the |actual|
|
||||
// iterator are in the |expected| set.
|
||||
assert.eqSet = (expected, actual) => {
|
||||
assert.iterable(actual);
|
||||
for (var x of actual) {
|
||||
assert.ok(expected.has(x));
|
||||
expected.delete(x);
|
||||
}
|
||||
};
|
||||
|
||||
// Helper for asserting that all the elements yielded from the |actual|
|
||||
// iterator are equal to and in the same order as the elements of the
|
||||
// |expected| array.
|
||||
assert.eqArray = (expected, actual) => {
|
||||
assert.iterable(actual);
|
||||
assert.deepEqual(expected, [...actual]);
|
||||
};
|
||||
|
||||
mocha.setup('bdd');
|
||||
describe("wu.asyncEach", () => {
|
||||
it("should iterate over each item", () => {
|
||||
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
let n = 0;
|
||||
|
||||
return wu(arr)
|
||||
.asyncEach(x => {
|
||||
n++;
|
||||
const start = Date.now();
|
||||
while (Date.now() - start <= 3) {
|
||||
// Kill time.
|
||||
}
|
||||
}, 3)
|
||||
.then(() => {
|
||||
assert.equal(n, arr.length);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("wu.chain", () => {
|
||||
it("should concatenate iterables", () => {
|
||||
assert.eqArray([1, 2, 3, 4, 5, 6],
|
||||
wu.chain([1, 2], [3, 4], [5, 6]));
|
||||
});
|
||||
});
|
||||
describe("wu.chunk", () => {
|
||||
it("should chunk items into tuples", () => {
|
||||
assert.eqArray([[1,2,3], [4,5,6]],
|
||||
wu.chunk(3, [1,2,3,4,5,6]));
|
||||
});
|
||||
});
|
||||
describe("wu.concatMap", () => {
|
||||
it("should map the function over the iterable and concatenate results", () => {
|
||||
assert.eqArray([1, 1, 2, 4, 3, 9],
|
||||
wu.concatMap(x => [x, x * x], [1, 2, 3]));
|
||||
});
|
||||
});
|
||||
describe("wu.count", () => {
|
||||
it("should keep incrementing", () => {
|
||||
const count = wu.count();
|
||||
assert.equal(count.next().value, 0);
|
||||
assert.equal(count.next().value, 1);
|
||||
assert.equal(count.next().value, 2);
|
||||
assert.equal(count.next().value, 3);
|
||||
assert.equal(count.next().value, 4);
|
||||
assert.equal(count.next().value, 5);
|
||||
});
|
||||
|
||||
it("should start at the provided number", () => {
|
||||
const count = wu.count(5);
|
||||
assert.equal(count.next().value, 5);
|
||||
assert.equal(count.next().value, 6);
|
||||
assert.equal(count.next().value, 7);
|
||||
});
|
||||
|
||||
it("should increment by the provided step", () => {
|
||||
const count = wu.count(0, 2);
|
||||
assert.equal(count.next().value, 0);
|
||||
assert.equal(count.next().value, 2);
|
||||
assert.equal(count.next().value, 4);
|
||||
});
|
||||
});
|
||||
describe("wu.curryable", () => {
|
||||
it("should wait until its given enough arguments", () => {
|
||||
var f = wu.curryable((a, b) => a + b);
|
||||
|
||||
var f0 = f()()()()();
|
||||
assert.equal(typeof f0, "function");
|
||||
|
||||
var f1 = f(1);
|
||||
assert.equal(typeof f1, "function");
|
||||
assert.equal(f1(2), 3);
|
||||
});
|
||||
|
||||
it("should just call the function when given enough arguments", () => {
|
||||
var f = wu.curryable((a, b) => a + b);
|
||||
assert.equal(f(1, 2), 3);
|
||||
});
|
||||
|
||||
it("should expect the number of arguments we tell it to", () => {
|
||||
var f = wu.curryable((...args) => 5, 5);
|
||||
assert.equal(typeof f(1, 2, 3, 4), "function");
|
||||
assert.equal(f(1, 2, 3, 4, 5), 5);
|
||||
});
|
||||
});
|
||||
describe("wu.cycle", () => {
|
||||
it("should keep yielding items from the original iterable", () => {
|
||||
let i = 0;
|
||||
const arr = [1, 2, 3];
|
||||
for (let x of wu.cycle(arr)) {
|
||||
assert.equal(x, arr[i % 3]);
|
||||
if (i++ > 9) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("wu.drop", () => {
|
||||
it("should drop the number of items specified", () => {
|
||||
const count = wu.count().drop(5);
|
||||
assert.equal(count.next().value, 5);
|
||||
});
|
||||
});
|
||||
describe("wu.dropWhile", () => {
|
||||
it("should drop items while the predicate is true", () => {
|
||||
const count = wu.dropWhile(x => x < 5, wu.count());
|
||||
assert.equal(count.next().value, 5);
|
||||
});
|
||||
});
|
||||
describe("wu.entries", () => {
|
||||
it("should iterate over entries", () => {
|
||||
const expected = new Map([["foo", 1], ["bar", 2], ["baz", 3]]);
|
||||
for (let [k, v] of wu.entries({ foo: 1, bar: 2, baz: 3 })) {
|
||||
assert.equal(expected.get(k), v);
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("wu.enumerate", () => {
|
||||
it("should yield items with their index", () => {
|
||||
assert.eqArray([["a", 0], ["b", 1], ["c", 2]],
|
||||
wu.enumerate("abc"));
|
||||
});
|
||||
});
|
||||
describe("wu.every", () => {
|
||||
it("should return true when the predicate succeeds for all items", () => {
|
||||
assert.equal(true, wu.every(x => typeof x === "number", [1, 2, 3]));
|
||||
});
|
||||
|
||||
it("should return false when the predicate fails for any item", () => {
|
||||
assert.equal(false, wu.every(x => typeof x === "number", [1, 2, "3"]));
|
||||
});
|
||||
});
|
||||
describe("wu.filter", () => {
|
||||
it("should filter based on the predicate", () => {
|
||||
assert.eqArray(["a", "b", "c"],
|
||||
wu.filter(x => typeof x === "string",
|
||||
[1, "a", true, "b", {}, "c"]));
|
||||
});
|
||||
});
|
||||
describe("wu.find", () => {
|
||||
it("should return the first item that matches the predicate", () => {
|
||||
assert.deepEqual({ name: "rza" },
|
||||
wu.find(x => !!x.name.match(/.za$/),
|
||||
[{ name: "odb" },
|
||||
{ name: "method man" },
|
||||
{ name: "rza" },
|
||||
{ name: "gza" }]));
|
||||
});
|
||||
|
||||
it("should return undefined if no items match the predicate", () => {
|
||||
assert.equal(undefined,
|
||||
wu.find(x => (<any>x) === "raekwon",
|
||||
[{ name: "odb" },
|
||||
{ name: "method man" },
|
||||
{ name: "rza" },
|
||||
{ name: "gza" }]));
|
||||
});
|
||||
});
|
||||
describe("wu.flatten", () => {
|
||||
it("should flatten iterables", () => {
|
||||
assert.eqArray(["I", "like", "LISP"],
|
||||
wu(["I", ["like", ["LISP"]]]).flatten());
|
||||
});
|
||||
|
||||
it("should shallowly flatten iterables", () => {
|
||||
assert.eqArray([1, 2, 3, [[4]]],
|
||||
wu.flatten(true, [1, [2], [3, [[4]]]]));
|
||||
});
|
||||
});
|
||||
describe("wu.forEach", () => {
|
||||
it("should iterate over every item", () => {
|
||||
const items = [];
|
||||
wu.forEach(x => items.push(x), [1,2,3]);
|
||||
assert.eqArray([1,2,3], items);
|
||||
});
|
||||
});
|
||||
describe("wu.has", () => {
|
||||
it("should return true if the item is in the iterable", () => {
|
||||
assert.ok(wu.has(3, [1,2,3]));
|
||||
});
|
||||
|
||||
it("should return false if the item is not in the iterable", () => {
|
||||
assert.ok(!wu.has(<any>"36 chambers", [1,2,3]));
|
||||
});
|
||||
});
|
||||
describe("wu.invoke", () => {
|
||||
it("should yield the method invokation on each item", () => {
|
||||
function Greeter(name) {
|
||||
this.name = name
|
||||
}
|
||||
Greeter.prototype.greet = function (tail) {
|
||||
return "hello " + this.name + tail;
|
||||
};
|
||||
assert.eqArray(["hello world!", "hello test!"],
|
||||
wu.invoke("greet", "!",
|
||||
[new Greeter("world"), new Greeter("test")]));
|
||||
});
|
||||
});
|
||||
describe("wu.keys", () => {
|
||||
it("should iterate over keys", () => {
|
||||
assert.eqSet(new Set(["foo", "bar", "baz"]),
|
||||
wu.keys({ foo: 1, bar: 2, baz: 3 }));
|
||||
});
|
||||
});
|
||||
describe("wu.map", () => {
|
||||
it("should map the function over the iterable", () => {
|
||||
assert.eqArray([1, 4, 9],
|
||||
wu.map(x => x * x, [1, 2, 3]));
|
||||
});
|
||||
});
|
||||
describe("wu.pluck", () => {
|
||||
it("should access the named property of each item in the iterable", () => {
|
||||
assert.eqArray([1, 2, 3],
|
||||
wu.pluck("i", [{ i: 1 }, { i: 2 }, { i: 3 }]));
|
||||
});
|
||||
});
|
||||
describe("wu.reduce", () => {
|
||||
it("should reduce the iterable with the function", () => {
|
||||
assert.equal(6, wu([1,2,3]).reduce((x, y) => x + y));
|
||||
});
|
||||
|
||||
it("should accept an initial state for the reducer function", () => {
|
||||
assert.equal(16, wu.reduce((x, y) => x + y, 10, [1,2,3]));
|
||||
});
|
||||
});
|
||||
describe("wu.reductions", () => {
|
||||
it("should yield the intermediate reductions of the iterable", () => {
|
||||
assert.eqArray([1, 3, 6],
|
||||
wu.reductions((x, y) => x + y, undefined, [1, 2, 3]));
|
||||
});
|
||||
});
|
||||
describe("wu.reject", () => {
|
||||
it("should yield items for which the predicate is false", () => {
|
||||
assert.eqArray([1, true, {}],
|
||||
wu.reject(x => typeof x === "string",
|
||||
[1, "a", true, "b", {}, "c"]));
|
||||
});
|
||||
});
|
||||
describe("wu.repeat", () => {
|
||||
it("should keep yielding its item", () => {
|
||||
const repeat = wu.repeat(3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
});
|
||||
|
||||
it("should repeat n times", () => {
|
||||
const repeat = wu.repeat(3, 2);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, 3);
|
||||
assert.equal(repeat.next().value, undefined);
|
||||
assert.equal(repeat.next().done, true);
|
||||
});
|
||||
});
|
||||
describe("wu.slice", () => {
|
||||
it("should slice the front of iterables", () => {
|
||||
assert.eqArray([3, 4, 5],
|
||||
wu.slice(3, undefined, [0, 1, 2, 3, 4, 5]));
|
||||
});
|
||||
|
||||
it("should slice the end of iterables", () => {
|
||||
assert.eqArray([0, 1, 2],
|
||||
wu.slice(undefined,
|
||||
3,
|
||||
[0, 1, 2, 3, 4, 5]));
|
||||
});
|
||||
});
|
||||
describe("wu.some", () => {
|
||||
it("should return true if any item matches the predicate", () => {
|
||||
assert.ok(wu.some(x => x % 2 === 0, [1,2,3]));
|
||||
});
|
||||
|
||||
it("should return false if no items match the predicate", () => {
|
||||
assert.ok(!wu.some(x => x % 5 === 0, [1,2,3]));
|
||||
});
|
||||
});
|
||||
describe("wu.spreadMap", () => {
|
||||
it("should map the function over the iterable with spread arguments", () => {
|
||||
assert.eqArray([32, 9, 1000],
|
||||
wu.spreadMap(Math.pow, [[2, 5], [3, 2], [10, 3]]));
|
||||
});
|
||||
});
|
||||
describe("wu.take", () => {
|
||||
it("should yield as many items as requested", () => {
|
||||
assert.eqArray([0, 1, 2, 3, 4],
|
||||
wu.take(5, wu.count()));
|
||||
});
|
||||
});
|
||||
describe("wu.takeWhile", () => {
|
||||
it("should keep yielding items from the iterable until the predicate is false", () => {
|
||||
assert.eqArray([0, 1, 2, 3, 4],
|
||||
wu.takeWhile(x => x < 5, wu.count()));
|
||||
});
|
||||
});
|
||||
describe("wu.tap", () => {
|
||||
it("should perform side effects and yield the original item", () => {
|
||||
let i = 0;
|
||||
assert.eqArray([1, 2, 3],
|
||||
wu.tap(x => i++, [1, 2, 3]));
|
||||
assert.equal(i, 3);
|
||||
});
|
||||
});
|
||||
describe("wu.tee", () => {
|
||||
it("should clone iterables", () => {
|
||||
const factorials = wu(wu.count(1)).reductions((a, b) => a * b);
|
||||
const [i1, i2] = wu(factorials).tee();
|
||||
|
||||
assert.equal(i1.next().value, 1);
|
||||
assert.equal(i1.next().value, 2);
|
||||
assert.equal(i1.next().value, 6);
|
||||
assert.equal(i1.next().value, 24);
|
||||
|
||||
assert.equal(i2.next().value, 1);
|
||||
assert.equal(i2.next().value, 2);
|
||||
assert.equal(i2.next().value, 6);
|
||||
assert.equal(i2.next().value, 24);
|
||||
});
|
||||
});
|
||||
describe("wu.unique", () => {
|
||||
it("should yield only the unique items from the iterable", () => {
|
||||
assert.eqArray([1, 2, 3],
|
||||
wu.unique([1,1,2,2,1,1,3,3]));
|
||||
});
|
||||
});
|
||||
describe("wu.unzip", () => {
|
||||
it("should create iterables from zipped items", () => {
|
||||
const pairs = [
|
||||
["one", 1],
|
||||
["two", 2],
|
||||
["three", 3]
|
||||
];
|
||||
const [i1, i2] = wu(pairs).unzip();
|
||||
assert.eqArray(["one", "two", "three"], [...i1]);
|
||||
assert.eqArray([1, 2, 3], [...i2]);
|
||||
});
|
||||
});
|
||||
describe("wu.values", () => {
|
||||
it("should iterate over values", () => {
|
||||
assert.eqSet(new Set([1, 2, 3]),
|
||||
wu.values({ foo: 1, bar: 2, baz: 3 }));
|
||||
});
|
||||
});
|
||||
describe("wu.zip", () => {
|
||||
it("should zip two iterables together", () => {
|
||||
assert.eqArray([["a", 1], ["b", 2], ["c", 3]],
|
||||
wu.zip("abc", [1, 2, 3]));
|
||||
});
|
||||
|
||||
it("should stop with the shorter iterable", () => {
|
||||
assert.eqArray([["a", 1], ["b", 2], ["c", 3]],
|
||||
wu.zip("abc", wu.count(1)));
|
||||
});
|
||||
});
|
||||
describe("wu.zipLongest", () => {
|
||||
it("should stop with the longer iterable", () => {
|
||||
const arr1 = [];
|
||||
arr1[1] = 2;
|
||||
const arr2 = [];
|
||||
arr2[1] = 3;
|
||||
assert.eqArray([["a", 1], arr1, arr2],
|
||||
wu.zipLongest("a", [1, 2, 3]));
|
||||
});
|
||||
});
|
||||
describe("wu.zipWith", () => {
|
||||
it("should spread map over the zipped iterables", () => {
|
||||
const add3 = (a, b, c) => a + b + c;
|
||||
assert.eqArray([12, 15, 18],
|
||||
wu.zipWith(add3,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
--target ES6
|
||||
Vendored
+117
@@ -0,0 +1,117 @@
|
||||
// Type definitions for wu.js v2.1.0
|
||||
// Project: https://fitzgen.github.io/wu.js/
|
||||
// Definitions by: phiresky <https://github.com/phiresky/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module Wu {
|
||||
type Consumer<T> = (t: T) => void;
|
||||
type Filter<T> = (t: T) => boolean;
|
||||
|
||||
export interface WuStatic {
|
||||
<T>(iterable: Iterable<T>): WuIterable<T>;
|
||||
// only static
|
||||
chain<T>(...iters: Iterable<T>[]): WuIterable<T>;
|
||||
count(start?: number, step?: number): WuIterable<number>;
|
||||
curryable<T>(fun: (...x: any[]) => T, expected?: number): any;
|
||||
entries<T>(obj: { [i: string]: T }): WuIterable<[string, T]>;
|
||||
keys<T>(obj: { [i: string]: T }): WuIterable<string>;
|
||||
values<T>(obj: { [i: string]: T }): WuIterable<T>;
|
||||
repeat<T>(obj: T, times?: number): WuIterable<T>;
|
||||
// also copied to WuInterface
|
||||
asyncEach<T>(fn: Consumer<T>, maxBlock?: number, timeout?: number): void;
|
||||
drop<T>(n: number, iter: Iterable<T>): WuIterable<T>;
|
||||
dropWhile<T>(fn: Filter<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
cycle<T>(iter: Iterable<T>): Iterable<T>;
|
||||
chunk<T>(n: number, iter: Iterable<T>): WuIterable<T[]>;
|
||||
concatMap<T, U>(fn: (t: T) => Iterable<U>, iter: Iterable<T>): WuIterable<U>;
|
||||
dropWhile<T>(fn: Filter<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
enumerate<T>(iter: Iterable<T>): Iterable<[number, T]>;
|
||||
every<T>(fn: Filter<T>, iter: Iterable<T>): boolean;
|
||||
filter<T>(fn: Filter<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
find<T>(fn: Filter<T>, iter: Iterable<T>): T;
|
||||
flatten(iter: Iterable<any>): WuIterable<any>;
|
||||
flatten(shallow: boolean, iter: Iterable<any>): WuIterable<any>;
|
||||
forEach<T>(fn: Consumer<T>, iter: Iterable<T>): void;
|
||||
has<T>(t: T, iter: Iterable<T>): boolean;
|
||||
// invoke<T, U>(name:string, ...t:T[], iter: Iterable<(t:T)=>U>): WuIterable<U>;
|
||||
invoke: any;
|
||||
map<T, U>(fn: (t: T) => U, iter: Iterable<T>): WuIterable<U>;
|
||||
// pluck<T>(attribute:string, iter: Iterable<{[attribute]: T}>): WuIterable<T>;
|
||||
pluck(attribute: string, iter: Iterable<any>): WuIterable<any>;
|
||||
reduce<T>(fn: (a: T, b: T) => T, iter: Iterable<T>): T;
|
||||
reduce<T>(fn: (a: T, b: T) => T, initial: T, iter: Iterable<T>): T;
|
||||
reduce<T, U>(fn: (a: U, b: T) => U, iter: Iterable<T>): U;
|
||||
reduce<T, U>(fn: (a: U, b: T) => U, initial: U, iter: Iterable<T>): U;
|
||||
reductions<T>(fn: (a: T, b: T) => T, iter: Iterable<T>): WuIterable<T>;
|
||||
reductions<T>(fn: (a: T, b: T) => T, initial: T, iter: Iterable<T>): WuIterable<T>;
|
||||
reductions<T, U>(fn: (a: U, b: T) => U, iter: Iterable<T>): WuIterable<U>;
|
||||
reductions<T, U>(fn: (a: U, b: T) => U, initial: U, iter: Iterable<T>): WuIterable<U>;
|
||||
reject<T>(fn: Filter<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
slice<T>(iter: Iterable<T>): WuIterable<T>;
|
||||
slice<T>(start: number, iter: Iterable<T>): WuIterable<T>;
|
||||
slice<T>(start: number, stop: number, iter: Iterable<T>): WuIterable<T>;
|
||||
some<T>(fn: Filter<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
spreadMap<T>(fn: (...x: any[]) => T, iter: Iterable<any[]>): WuIterable<T>;
|
||||
take<T>(n: number, iter: Iterable<T>): WuIterable<T>;
|
||||
takeWhile<T>(fn: Filter<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
tap<T>(fn: Consumer<T>, iter: Iterable<T>): WuIterable<T>;
|
||||
unique<T>(iter: Iterable<T>): WuIterable<T>;
|
||||
zip<T, U>(iter2: Iterable<T>, iter: Iterable<U>): WuIterable<[T, U]>;
|
||||
zipLongest<T, U>(iter2: Iterable<T>, iter: Iterable<U>): WuIterable<[T, U]>;
|
||||
zipWith: any;
|
||||
unzip: any;
|
||||
tee<T>(iter: Iterable<T>): WuIterable<T>[];
|
||||
tee<T>(n: number, iter: Iterable<T>): WuIterable<T>[];
|
||||
}
|
||||
export interface WuIterable<T> extends IterableIterator<T> {
|
||||
// generated from section "copied to WuIterable" above via
|
||||
// sed -r 's/(, )?iter: Iterable<\w+>//' |
|
||||
// sed -r 's/^(\s+\w+)<T>/\1/' |
|
||||
// sed -r 's/^(\s+\w+)<T, /\1</'
|
||||
asyncEach<T>(fn: Consumer<T>, maxBlock?: number, timeout?: number): any;
|
||||
drop(n: number): WuIterable<T>;
|
||||
dropWhile(fn: Filter<T>): WuIterable<T>;
|
||||
cycle(): Iterable<T>;
|
||||
chunk(n: number): WuIterable<T[]>;
|
||||
concatMap<U>(fn: (t: T) => Iterable<U>): WuIterable<U>;
|
||||
dropWhile(fn: Filter<T>): WuIterable<T>;
|
||||
enumerate(): Iterable<[number, T]>;
|
||||
every(fn: Filter<T>): boolean;
|
||||
filter(fn: Filter<T>): WuIterable<T>;
|
||||
find(fn: Filter<T>): T;
|
||||
flatten(): WuIterable<any>;
|
||||
flatten(shallow: boolean): WuIterable<any>;
|
||||
forEach(fn: Consumer<T>): void;
|
||||
has(t: T): boolean;
|
||||
// invoke<T, U>(name:string, ...t:T[], iter: Iterable<(t:T)=>U>): WuIterable<U>;
|
||||
invoke: any;
|
||||
map<U>(fn: (t: T) => U): WuIterable<U>;
|
||||
// pluck<T>(attribute:string, iter: Iterable<{[attribute]: T}>): WuIterable<T>;
|
||||
pluck(attribute: string): WuIterable<any>;
|
||||
reduce(fn: (a: T, b: T) => T): T;
|
||||
reduce(fn: (a: T, b: T) => T, initial: T): T;
|
||||
reduce<U>(fn: (a: U, b: T) => U): U;
|
||||
reduce<U>(fn: (a: U, b: T) => U, initial: U): U;
|
||||
reductions(fn: (a: T, b: T) => T): WuIterable<T>;
|
||||
reductions(fn: (a: T, b: T) => T, initial: T): WuIterable<T>;
|
||||
reductions<U>(fn: (a: U, b: T) => U): WuIterable<U>;
|
||||
reductions<U>(fn: (a: U, b: T) => U, initial: U): WuIterable<U>;
|
||||
reject(fn: Filter<T>): WuIterable<T>;
|
||||
slice(): WuIterable<T>;
|
||||
slice(start: number): WuIterable<T>;
|
||||
slice(start: number, stop: number): WuIterable<T>;
|
||||
some(fn: Filter<T>): WuIterable<T>;
|
||||
spreadMap(fn: (...x: any[]) => T, iter: Iterable<any[]>): WuIterable<T>;
|
||||
take(n: number): WuIterable<T>;
|
||||
takeWhile(fn: Filter<T>): WuIterable<T>;
|
||||
tap(fn: Consumer<T>): WuIterable<T>;
|
||||
unique(): WuIterable<T>;
|
||||
zip<U>(iter2: Iterable<T>): WuIterable<[T, U]>;
|
||||
zipLongest<U>(iter2: Iterable<T>): WuIterable<[T, U]>;
|
||||
zipWith: any;
|
||||
unzip: any;
|
||||
tee(): WuIterable<T>[];
|
||||
tee(n: number): WuIterable<T>[];
|
||||
}
|
||||
}
|
||||
declare var wu: Wu.WuStatic;
|
||||
@@ -0,0 +1 @@
|
||||
--target ES6
|
||||
Reference in New Issue
Block a user