From 389b49fc0e89bcdbdc0ca0ec8167099941e60501 Mon Sep 17 00:00:00 2001 From: WAEL BEN ZID Date: Fri, 18 Dec 2015 16:18:08 +0100 Subject: [PATCH 1/4] Definition for prettyjson package added --- prettyjson/prettyjson-tests.ts | 18 +++++++++++ prettyjson/prettyjson.d.ts | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 prettyjson/prettyjson-tests.ts create mode 100644 prettyjson/prettyjson.d.ts diff --git a/prettyjson/prettyjson-tests.ts b/prettyjson/prettyjson-tests.ts new file mode 100644 index 000000000..4df6b1fc8 --- /dev/null +++ b/prettyjson/prettyjson-tests.ts @@ -0,0 +1,18 @@ +/// + +var options: prettyjson.IOptions, + input: string, + output: string; + + +input = 'This is a string'; +output = prettyjson.render(input); + +output = prettyjson.render(input, {}, 4); + +output = prettyjson.render(['first string', ['nested 1', 'nested 2'], 'second string']); + +output = prettyjson.render({param1: 'first string', param2: 'second string'}); + +output = prettyjson.render({first_param: {subparam: 'first string', subparam2: 'another string'}, second_param: 'second string'}); + diff --git a/prettyjson/prettyjson.d.ts b/prettyjson/prettyjson.d.ts new file mode 100644 index 000000000..f1f0dbf23 --- /dev/null +++ b/prettyjson/prettyjson.d.ts @@ -0,0 +1,59 @@ +// Type definitions for prettyjson +// Project: https://github.com/rafeca/prettyjson +// Definitions by: Wael BEN ZID EL GUEBSI +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +declare module PrettyJSON { + + /** + * Defines prettyjson version + */ + export var version: string; + + /** + * Render pretty json. + * + * @param data {Object} Data to prettify. + * @param options {IOptions} Hash with different options to configure the renderer. + * @param indentation {number} Indentation size. + * + * @return {string} pretty serialized json data ready to display. + */ + export function render(data: Object, options?: IOptions, indentation?: number): string; + + /** + * Render pretty json from a string. + * + * @param data {string} Serialized JSON data to prettify. + * @param options {IOptions} Hash with different options to configure the renderer. + * @param indentation {number} Indentation size. + * + * @return {string} pretty serialized json data ready to display. + */ + export function renderString(data: string, options?: IOptions, indentation?: number): string; + + export interface IOptions { + + /** + * Define behavior for Array objects + */ + emptyArrayMsg ?: string; // default: (empty) + inlineArrays ?: boolean; + + /** + * Color definition + */ + noColor ?: boolean; + keysColor ?: string; + dashColor ?: string; + numberColor ?: string; + stringColor ?: string; + + defaultIndentation ?: number; + } +} + +declare module "prettyjson" { + export = PrettyJSON; +} From e3dea91f4300f526bbb4d1baa8b558598d69d751 Mon Sep 17 00:00:00 2001 From: WAEL BEN ZID Date: Tue, 22 Dec 2015 12:17:04 +0100 Subject: [PATCH 2/4] More tests added --- prettyjson/prettyjson-tests.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prettyjson/prettyjson-tests.ts b/prettyjson/prettyjson-tests.ts index 4df6b1fc8..9d7c43918 100644 --- a/prettyjson/prettyjson-tests.ts +++ b/prettyjson/prettyjson-tests.ts @@ -2,9 +2,13 @@ var options: prettyjson.IOptions, input: string, - output: string; + output: string, + version: string; +console.log("using prettyjson v" + prettyjson.version) +version = prettyjson.version; + input = 'This is a string'; output = prettyjson.render(input); @@ -16,3 +20,4 @@ output = prettyjson.render({param1: 'first string', param2: 'second string'}); output = prettyjson.render({first_param: {subparam: 'first string', subparam2: 'another string'}, second_param: 'second string'}); +prettyjson.renderString('{name: "Wael", nested: {list: ["a", "b"], int: 3}}') From a5f6fa793f206da5521580987d219493014810a1 Mon Sep 17 00:00:00 2001 From: WAEL BEN ZID Date: Tue, 22 Dec 2015 12:17:58 +0100 Subject: [PATCH 3/4] module declaration fixed --- prettyjson/prettyjson.d.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/prettyjson/prettyjson.d.ts b/prettyjson/prettyjson.d.ts index f1f0dbf23..b2a6399ac 100644 --- a/prettyjson/prettyjson.d.ts +++ b/prettyjson/prettyjson.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module PrettyJSON { +declare module prettyjson { /** * Defines prettyjson version @@ -14,13 +14,13 @@ declare module PrettyJSON { /** * Render pretty json. * - * @param data {Object} Data to prettify. + * @param data {any} Data to prettify. * @param options {IOptions} Hash with different options to configure the renderer. * @param indentation {number} Indentation size. * * @return {string} pretty serialized json data ready to display. */ - export function render(data: Object, options?: IOptions, indentation?: number): string; + export function render(data: any, options?: IOptions, indentation?: number): string; /** * Render pretty json from a string. @@ -53,7 +53,3 @@ declare module PrettyJSON { defaultIndentation ?: number; } } - -declare module "prettyjson" { - export = PrettyJSON; -} From b3109b5c64dc07a42fa00e191ba8a87e009a04b5 Mon Sep 17 00:00:00 2001 From: WAEL BEN ZID Date: Mon, 11 Jan 2016 09:09:46 +0100 Subject: [PATCH 4/4] Naming convention fixed --- prettyjson/prettyjson-tests.ts | 2 +- prettyjson/prettyjson.d.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/prettyjson/prettyjson-tests.ts b/prettyjson/prettyjson-tests.ts index 9d7c43918..80ecbbb0f 100644 --- a/prettyjson/prettyjson-tests.ts +++ b/prettyjson/prettyjson-tests.ts @@ -1,6 +1,6 @@ /// -var options: prettyjson.IOptions, +var options: prettyjson.RendererOptions, input: string, output: string, version: string; diff --git a/prettyjson/prettyjson.d.ts b/prettyjson/prettyjson.d.ts index b2a6399ac..cf2a69c19 100644 --- a/prettyjson/prettyjson.d.ts +++ b/prettyjson/prettyjson.d.ts @@ -20,7 +20,7 @@ declare module prettyjson { * * @return {string} pretty serialized json data ready to display. */ - export function render(data: any, options?: IOptions, indentation?: number): string; + export function render(data: any, options?: RendererOptions, indentation?: number): string; /** * Render pretty json from a string. @@ -31,9 +31,9 @@ declare module prettyjson { * * @return {string} pretty serialized json data ready to display. */ - export function renderString(data: string, options?: IOptions, indentation?: number): string; + export function renderString(data: string, options?: RendererOptions, indentation?: number): string; - export interface IOptions { + export interface RendererOptions { /** * Define behavior for Array objects