Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#1 from borisyankov/master
Browse files Browse the repository at this point in the history
Update to latest
  • Loading branch information
clavecoder committed Apr 5, 2013
2 parents df95007 + ef6f401 commit cb89689
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 1 deletion.
28 changes: 27 additions & 1 deletion durandal/durandal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ declare module "durandal/plugins/router" {
/**
* Works the same as mapRoute except that routes are automatically added to the visibleRoutes array.
*/
export var mapNav: (url: string, moduleId: string, name: string) => routeInfo;
export var mapNav: (url: string, moduleId?: string, name?: string) => routeInfo;
/**
* You can pass a single routeInfo to this function, or you can pass the basic configuration parameters. url is your url pattern, moduleId is the module path this pattern will map to, name is used as the document title and visible determines whether or not to include it in the router's visibleRoutes array for easy navigation UI binding.
*/
Expand All @@ -441,6 +441,32 @@ declare module "durandal/plugins/router" {
export var activate: (defaultRoute: string) => JQueryPromise;
}

declare module "durandal/widget" {
/**
* Use this function to create a widget through code. The element should reference a dom element that the widget will be created on. The settings can be either a string or an object. If it's a string, it should specify the widget kind. If it's an object, it represents settings that will be passed along to the widget. This object should have a kind property used to identify the widget kind to create. Optionally, you can specify a bindingContext of which you want the widget's binding context to be created as a child.
*/
export function create(element: any, settings: any, bindingContext?: any);
/**
* By default, you can create widgets in html by using the widget binding extension. Calling registerKind allows you to easily create a custom binding handler for your widget kind. Without calling registerKind you might declare a widget binding for an expander control with
*/
export function registerKind(kind: string);
/**
* Use this to re-map a widget kind identifier to a new viewId or moduleId representing the 'skin' and 'behavior' respectively.
*/
export function mapKind(kind: string, viewId?: string, moduleId?: string);
/**
* Developers implementing widgets may wish to use this function to acquire the resolved template parts for a widget. Pass a single dom element or an array of elements and get back an object keyed by part name whose values are the dom elements corresponding to each part in that scope.
*/
export function getParts(elements: any): any;
/**
* (overrridable) Replace this to re-interpret the kind id as a module path. By default it does a lookup for any custom maps added through mapKind and then falls back to the path "durandal/widgets/{kind}/controller".
*/
export function convertKindToModuleId(kind): string;
/**
* (overridable) Replace this to re-interpret the kind id as a view id. The default does a lookup for any custom maps added through mapKind and then falls back to the path "durandal/widgets/{kind}/view".
*/
export function convertKindToViewId(kind): string;
}

interface IEventSubscription
{
Expand Down
132 changes: 132 additions & 0 deletions jszip/jszip-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path='jszip.d.ts' />

var SEVERITY = {
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
FATAL: 4
}

function testJSZip() {

var newJszip = new JSZip();

newJszip.file("test.txt", "test string");
newJszip.file("test/test.txt", "test string");

var serializedZip = newJszip.generate({compression: "DEFLATE", type:"base64"});

newJszip = new JSZip();
newJszip.load(serializedZip, {base64: true, checkCRC32: true});

if(newJszip.file("test.txt").data === "test string") {
log(SEVERITY.INFO, "all ok");
} else {
log(SEVERITY.ERROR, "no matching file found");
}
if(newJszip.file("test/test.txt").data === "test string") {
log(SEVERITY.INFO, "all ok");
} else {
log(SEVERITY.ERROR, "no matching file found");
}

var folder = newJszip.folder("test");
if(folder.file("test.txt").data == "test string") {
log(SEVERITY.INFO, "all ok");
}
else {
log(SEVERITY.ERROR, "wrong file");
}

var folders = newJszip.folder(new RegExp("^test"));

if(folders.length == 1) {
log(SEVERITY.INFO, "all ok");
if(folders[0].options.dir == true) {
log(SEVERITY.INFO, "all ok");
}
else {
log(SEVERITY.ERROR, "wrong file");
}
} else {
log(SEVERITY.ERROR, "wrong number of folder");
}

var files = newJszip.file(new RegExp("^test"));
if(files.length == 2) {
log(SEVERITY.INFO, "all ok");
if(files[0].data == "test string" && files[1].data == "test string") {
log(SEVERITY.INFO, "all ok");
}
else {
log(SEVERITY.ERROR, "wrong data in files");
}
}
else {
log(SEVERITY.ERROR, "wrong number of files");
}

var filterFiles = newJszip.filter((relativePath: string, file: jszip.JSZipFile) => {
if(file.data == "test string") {
return true;
}
return false;
});

if(filterFiles.length == 2) {
log(SEVERITY.INFO, "all ok");
}
else {
log(SEVERITY.ERROR, "wrong number of files");
}

newJszip.remove("test/test.txt");

filterFiles = newJszip.filter((relativePath: string, file: jszip.JSZipFile) => {
if(file.data == "test string") {
return true;
}
return false;
});

if(filterFiles.length == 1) {
log(SEVERITY.INFO, "all ok");
}
else {
log(SEVERITY.ERROR, "wrong number of files");
}

log(SEVERITY.INFO, newJszip.crc32("Test"));
log(SEVERITY.INFO, newJszip.utf8encode("Test"));
log(SEVERITY.INFO, newJszip.utf8decode("Test"));
newJszip.clone();
}

function log(severity:number, message: any) {
var log = "";
switch(severity) {
case 0:
log += "[DEBUG] ";
break;
case 1:
log += "[INFO] ";
break;
case 2:
log += "[WARN] ";
break;
case 3:
log += "[ERROR] ";
break;
case 4:
log += "[FATAL] ";
break;
default:
log += "[INFO]"
break;
}
console.log(log += message);
}

testJSZip();
183 changes: 183 additions & 0 deletions jszip/jszip.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Type definitions for JSZip
// Project: http://stuk.github.com/jszip/
// Definitions by: mzeiher <https://github.com/mzeiher>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

module jszip {
export interface JSZip {
/**
* Get a file from the archive
*
* @param path {string} relative path to file
*
* @return {JSZipFile} file matching path, null if no file found
*/
file(path: string): JSZipFile;

/**
* Get files matching a RegExp from archive
*
* @param path {RegExp} RegExp to match
*
* @return {JSZipFile[]} return all matching files or an empty array
*/
file(path: RegExp): JSZipFile[];

/**
* Add a file to the archive
*
* @param path {string} relative path to file
* @param content {any} content of the file
* @param options {JSZipOptions} optional information about the file
*
* @return {JSZip} JSZip object
*/
file(path: string, content: any, options?: JSZipOptions): JSZip;

/**
* Return an new JSZip instance with the given folder as root
*
* @param name {string} name of the folder
*
* @return {JSZip} new JSZip object with the given folder as root or null
*/
folder(name: string): JSZip;

/**
* Returns new JSZip instances with the matching folders as root
*
* @param name {RegExp} RegExp to match
*
* @return {JSZipFile[]} new array of JSZipFile objects which match the RegExp
*/
folder(name: RegExp): JSZipFile[];

/**
* Removes the file or folder from the archive
*
* @param path {string} relative path of file or folder
*
* @return {JSZip} returns the JSZip instance
*/
remove(path: string): JSZip;

/**
* Generates a new archive
*
* @param options {JSZipGeneratorOptions} optional options for the generator
*
* @return {any} the serialized archive
*/
generate(options?: JSZipGeneratorOptions): any;

/**
* Deserialize zip file
*
* @param data {any} serialized zip file
* @param options {JSZipOptions} options for deserializing
*
* @return {JSZip} returns the JSZip instance
*/
load(data: any, options: JSZipOptions): JSZip;

/**
* Get all files wchich match the given filter function
*
* @param {function} filter function
*
* @return {JSZipFile[]} array of matched elements
*/
filter(predicate: (relativePath: string, file: JSZipFile) => bool): JSZipFile[];

/**
* Calculate crc32 of given string
*
* @param data {string} string to calculate crc32 from
* @param crc {number} optional: initializer for crc calc
*
* @return {number} calculated crc32 number
*/
crc32(data: string, crc?: number): number;

/**
* Clone JSSZip instance
*
* return {JSZip} cloned instsance
*/
clone(): JSZip;

/**
* UTF8 encode a string
*
* @param data {string} string to encode
*/
utf8encode(data: string): string;

/**
* UTF8 decode a string
*
* @param data {string} string to decode
*/
utf8decode(data: string): string;

}

export interface JSZipSupport {
arraybuffer: bool;
uint8array: bool;
blob: bool;
}

export interface JSZipGeneratorOptions {
base64?: bool; //deprecated
compression: string; //DEFLATE or STORE
type: string; //base64 (default), string, uint8array, blob
}

export interface JSZipOptions {
base64: bool;
checkCRC32: bool;
}

export interface JSZipFile {
name: string;
data: any;
options: JSZipFileOptions;

asText(): string;
asBinary(): any;
asArrayBuffer(): ArrayBuffer;
asUint8Array(): Uint8Array;
}

export interface JSZipFileOptions {
base64: bool;
binary: bool;
dir: bool;
date: Date;
}

export interface JSZipBase64 {
}
}

declare var JSZip: {
/**
* Create JSZip instance
* If no parameters given an empty zip archive will be created
*
* @param data {any} serialized zip archive
* @param options {JSZipOptions} description of the serialized zip archive
*/
new(data?: any, options?: jszip.JSZipOptions): jszip.JSZip;

prototype: jszip.JSZip;
support : jszip.JSZipSupport;
}

declare var JSZipBase64: {
encode(input: string, utf8?: any): string;
decode(input: string, utf8?: any): string;

prototype: jszip.JSZipBase64;
}
24 changes: 24 additions & 0 deletions mocha/mocha.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
declare var describe : {
(description: string, spec: () => void): void;
only(description: string, spec: () => void): void;
skip(description: string, spec: () => void): void;
timeout(ms: number);
}

declare var it: {
(expectation: string, assertion?: () => void): void;
(expectation: string, assertion?: (done: () => void) => void): void;
only(expectation: string, assertion?: () => void): void;
only(expectation: string, assertion?: (done: () => void) => void): void;
skip(expectation: string, assertion?: () => void): void;
skip(expectation: string, assertion?: (done: () => void) => void): void;
timeout(ms: number);
};

declare function beforeEach(action: () => void): void;

declare function beforeEach(action: (done: () => void) => void): void;

declare function afterEach(action: () => void): void;

declare function afterEach(action: (done: () => void) => void): void;

0 comments on commit cb89689

Please sign in to comment.