From cb3a8060f4603b0fc59191a12a76776370339075 Mon Sep 17 00:00:00 2001 From: Judah Gabriel Himango Date: Tue, 5 Nov 2013 14:39:49 -0600 Subject: [PATCH 1/4] NProgress typings --- README.md | 3 +- nprogress/NProgress-tests.ts | 30 +++++++++++ nprogress/NProgress.d.ts | 99 ++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 nprogress/NProgress-tests.ts create mode 100644 nprogress/NProgress.d.ts diff --git a/README.md b/README.md index d7a430d66..3f071bad1 100755 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ List of Definitions * [Knockout.ES5](https://github.com/SteveSanderson/knockout-es5) (by [Sebastián Galiano](https://github.com/sgaliano)) * [Knockout.Mapper](https://github.com/LucasLorentz/knockout.mapper) (by [Brandon Meyer](https://github.com/BMeyerKC)) * [Knockout.Mapping](https://github.com/SteveSanderson/knockout.mapping) (by [Boris Yankov](https://github.com/borisyankov)) -* [Knockout.Postbox](https://github.com/rniemeyer/knockout-postbox) (by [Judah Gabriel](https://github.com/JudahGabriel)) +* [Knockout.Postbox](https://github.com/rniemeyer/knockout-postbox) (by [Judah Gabriel Himango](https://github.com/JudahGabriel)) * [Knockout.Validation](https://github.com/ericmbarnard/Knockout-Validation) (by [Dan Ludwig](https://github.com/danludwig)) * [Knockout.Viewmodel](http://coderenaissance.github.com/knockout.viewmodel/) (by [Oisin Grehan](https://github.com/oising)) * [ko.editables](http://romanych.github.com/ko.editables/) (by [Oisin Grehan](https://github.com/oising)) @@ -172,6 +172,7 @@ List of Definitions * [node-ffi](https://github.com/rbranson/node-ffi) (by [Paul Loyd](https://github.com/loyd)) * [node_zeromq](https://github.com/JustinTulloss/zeromq.node) (by [Dave McKeown](https://github.com/davemckeown)) * [node-sqlserver](https://github.com/WindowsAzure/node-sqlserver) (by [Boris Yankov](https://github.com/borisyankov)) +* [NProgress](https://github.com/rstacruz/nprogress) (by [Judah Gabriel Himango](https://github.com/judahgabriel)) * [Numeral.js](https://github.com/adamwdraper/Numeral-js) (by [Vincent Bortone](https://github.com/vbortone/)) * [OpenLayers] (https://github.com/openlayers/openlayers) (by [Ilya Bolkhovsky](https://github.com/bolhovsky/)) * [Parallel.js](https://github.com/adambom/parallel.js) (by [Josh Baldwin](https://github.com/jbaldwin)) diff --git a/nprogress/NProgress-tests.ts b/nprogress/NProgress-tests.ts new file mode 100644 index 000000000..24613e0be --- /dev/null +++ b/nprogress/NProgress-tests.ts @@ -0,0 +1,30 @@ +function test_basics() { + NProgress.start(); + NProgress.inc(); + NProgress.done(); + NProgress.set(0.5); + + var status = NProgress.status; + var version = NProgress.version; +} + +function test_configuration() { + NProgress.configure({ + speed: 0.3 + }); + + NProgress.configure({ + trickle: false + }); + + NProgress.configure({ + ease: 'ease', + minimum: 0.09, + showSpinner: false, + speed: 420, + template: "
blah
", + trickle: false, + trickleRate: 0.42, + trickleSpeed: 42 + }); +} \ No newline at end of file diff --git a/nprogress/NProgress.d.ts b/nprogress/NProgress.d.ts new file mode 100644 index 000000000..d9c42b635 --- /dev/null +++ b/nprogress/NProgress.d.ts @@ -0,0 +1,99 @@ +// Type definitions for NProgress +// Project: https://github.com/rstacruz/nprogress +// Definitions by: Judah Gabriel Himango +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface NProgressStatic { + /** + * Shows the progress bar and begins trickling progress. + */ + start(); + + /** + * Finishes loading by transitioning it to 100%, then fading out. + * @param {boolean} forceShow Forces the progress bar to show, even if it's not being shown. (The default behavior is that .done() will not do anything if .start() isn't called.) + */ + done(forceShow?: boolean); + + /** + * Increments the progress bar with a random amount. This will never get to 100%: use it for every image load (or similar). + */ + inc(); + + /** + * Removes the progress indicator. + */ + remove(); + + /** + * Sets the progress percentage. + * @param {number} progressPercent A number between 0.0 and 1.0 that represents the progress percentage. + */ + set(progressPercent: number); + + /** + * Configures the progress indicator. + * @param {NProgressConfigureOptions} options An object containing the configuration options. + */ + configure(options: NProgressConfigureOptions); + + /** + * Gets the NProgress version. + */ + version: string; + + /** + * Gets the status. If started, it will be the last progress number set. + */ + status: any; + + /** + * Gets whether progress has been started. + */ + isStarted(): boolean; +} + +interface NProgressConfigureOptions { + + /** + * The minimum progress percentage. Default is 0.08. + */ + minimum?: number; + + /** + * How much to increase per trickle. Example: .02. Default is true. + */ + trickleRate?: number; + + /** + * How often to trickle, in milliseconds. Default is 800. + */ + trickleSpeed?: number; + + /** + * Whether to show the spinner. Defaults to true. Default is true. + */ + showSpinner?: boolean; + + /** + * Whether to enable trickling the progress. Default is true. + */ + trickle?: boolean; + + /** + * The CSS easing animation to use. Default is 'ease'. + */ + ease?: string; + + /** + * The animation speed in milliseconds. Default is 200. + */ + speed?: number; + + /** + * The HTML markup inserted for the progress indicator. To keep the progress bar working, keep an element with role='bar' in there. + */ + template?: string; +} + +declare var NProgress: NProgressStatic; \ No newline at end of file From b7171d19694bd2019b420f37230317607eb8365d Mon Sep 17 00:00:00 2001 From: Judah Gabriel Himango Date: Tue, 5 Nov 2013 22:46:31 -0600 Subject: [PATCH 2/4] Typed return vals --- nprogress/NProgress.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nprogress/NProgress.d.ts b/nprogress/NProgress.d.ts index d9c42b635..8cca1d3ea 100644 --- a/nprogress/NProgress.d.ts +++ b/nprogress/NProgress.d.ts @@ -7,7 +7,7 @@ interface NProgressStatic { /** * Shows the progress bar and begins trickling progress. */ - start(); + start(): NProgressStatic; /** * Finishes loading by transitioning it to 100%, then fading out. @@ -18,24 +18,24 @@ interface NProgressStatic { /** * Increments the progress bar with a random amount. This will never get to 100%: use it for every image load (or similar). */ - inc(); + inc(): NProgressStatic; /** * Removes the progress indicator. */ - remove(); + remove(): void; /** * Sets the progress percentage. * @param {number} progressPercent A number between 0.0 and 1.0 that represents the progress percentage. */ - set(progressPercent: number); + set(progressPercent: number): NProgressStatic; /** * Configures the progress indicator. * @param {NProgressConfigureOptions} options An object containing the configuration options. */ - configure(options: NProgressConfigureOptions); + configure(options: NProgressConfigureOptions): NProgressStatic; /** * Gets the NProgress version. From a717bb62fc91ab37a3b91045b2be0b5682f3b0e6 Mon Sep 17 00:00:00 2001 From: Judah Gabriel Himango Date: Tue, 5 Nov 2013 22:51:23 -0600 Subject: [PATCH 3/4] Docs for return values --- nprogress/NProgress.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nprogress/NProgress.d.ts b/nprogress/NProgress.d.ts index 8cca1d3ea..a86558aae 100644 --- a/nprogress/NProgress.d.ts +++ b/nprogress/NProgress.d.ts @@ -6,17 +6,20 @@ interface NProgressStatic { /** * Shows the progress bar and begins trickling progress. + * @returns {NProgressConfigureOptions} The current NProgress object, useful for chaining. */ start(): NProgressStatic; /** * Finishes loading by transitioning it to 100%, then fading out. * @param {boolean} forceShow Forces the progress bar to show, even if it's not being shown. (The default behavior is that .done() will not do anything if .start() isn't called.) + * @returns {NProgressConfigureOptions} The current NProgress object, useful for chaining. */ - done(forceShow?: boolean); + done(forceShow?: boolean): NProgressStatic; /** * Increments the progress bar with a random amount. This will never get to 100%: use it for every image load (or similar). + * @returns {NProgressConfigureOptions} The current NProgress object, useful for chaining. */ inc(): NProgressStatic; @@ -28,12 +31,14 @@ interface NProgressStatic { /** * Sets the progress percentage. * @param {number} progressPercent A number between 0.0 and 1.0 that represents the progress percentage. + * @returns {NProgressConfigureOptions} The current NProgress object, useful for chaining. */ set(progressPercent: number): NProgressStatic; /** * Configures the progress indicator. * @param {NProgressConfigureOptions} options An object containing the configuration options. + * @returns {NProgressConfigureOptions} The current NProgress object, useful for chaining. */ configure(options: NProgressConfigureOptions): NProgressStatic; @@ -49,6 +54,7 @@ interface NProgressStatic { /** * Gets whether progress has been started. + * @returns {boolean} Whether the progress has started. */ isStarted(): boolean; } From f537f00e01dac071ac4f9f801351e23759afa5c2 Mon Sep 17 00:00:00 2001 From: basarat Date: Wed, 6 Nov 2013 21:14:15 +1100 Subject: [PATCH 4/4] test fix --- nprogress/NProgress-tests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nprogress/NProgress-tests.ts b/nprogress/NProgress-tests.ts index 24613e0be..d7ad68b39 100644 --- a/nprogress/NProgress-tests.ts +++ b/nprogress/NProgress-tests.ts @@ -1,3 +1,5 @@ +/// + function test_basics() { NProgress.start(); NProgress.inc();