From 9c0b54dc305023a0d7db1e33feec8d5b9e89ed1c Mon Sep 17 00:00:00 2001 From: Tim Schraepen Date: Thu, 19 Jan 2017 22:28:26 +0100 Subject: [PATCH] Introduced Types for the vkBeautify npm package (#13948) * contribution of types for vkbeautify, a prettyprinting lib * added docs to methods * now linting * fixed lint suggestions * added original project * fixed export according to review * added --allowSyntheticDefaultImports to allow export = instead of export default * namespace unnecessary --- vkbeautify/index.d.ts | 45 +++++++++++++ vkbeautify/tsconfig.json | 21 ++++++ vkbeautify/tslint.json | 1 + vkbeautify/vkbeautify-tests.ts | 119 +++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 vkbeautify/index.d.ts create mode 100644 vkbeautify/tsconfig.json create mode 100644 vkbeautify/tslint.json create mode 100644 vkbeautify/vkbeautify-tests.ts diff --git a/vkbeautify/index.d.ts b/vkbeautify/index.d.ts new file mode 100644 index 0000000000..259fc3e058 --- /dev/null +++ b/vkbeautify/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for vkbeautify 0.99 +// Project: https://github.com/aabluedragon/vkbeautify +// Definitions by: Tim Schraepen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// Original project: https://github.com/vkiryukhin/vkBeautify + +// beautifying +/** + * Pretty print an xml string with the given number of whitespace, or with a given indentation pattern + */ +export function xml(text: string, amountOfWhitespaces?: number | string): string; + +/** + * Pretty print a json string with the given number of whitespace, or with a given indentation pattern + */ +export function json(text: string, amountOfWhitespaces?: number | string): string; + +/** + * Pretty print a css string with the given number of whitespace, or with a given indentation pattern + */ +export function css(text: string, amountOfWhitespaces?: number | string): string; + +/** + * Pretty print an sql string with the given number of whitespace, or with a given indentation pattern + */ +export function sql(text: string, amountOfWhitespaces?: number | string): string; + +// minifying +/** + * Minifiy an xml string, and preserve or remove comments (default) + */ +export function xmlmin(text: string, preserveComments?: boolean): string; +/** + * Minifiy a json string + */ +export function jsonmin(text: string): string; +/** + * Minifiy a css string, and preserve or remove comments (default) + */ +export function cssmin(text: string, preserveComments?: boolean): string; +/** + * Minifiy an sql string + */ +export function sqlmin(text: string): string; \ No newline at end of file diff --git a/vkbeautify/tsconfig.json b/vkbeautify/tsconfig.json new file mode 100644 index 0000000000..91709c37ae --- /dev/null +++ b/vkbeautify/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": true + }, + "files": [ + "index.d.ts", + "vkbeautify-tests.ts" + ] +} \ No newline at end of file diff --git a/vkbeautify/tslint.json b/vkbeautify/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/vkbeautify/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/vkbeautify/vkbeautify-tests.ts b/vkbeautify/vkbeautify-tests.ts new file mode 100644 index 0000000000..bc91ffad01 --- /dev/null +++ b/vkbeautify/vkbeautify-tests.ts @@ -0,0 +1,119 @@ +import VKBeautify from 'vkbeautify'; + +/* + * Beautifying + * + * vkbeautify.xml(text [,indent_pattern]); + * vkbeautify.json(text [,indent_pattern]); + * vkbeautify.css(text [,indent_pattern]); + * vkbeautify.sql(text [,indent_pattern]); + * + * @text - String; text to beatufy; + * @indent_pattern - Integer | String; + * Integer: number of white spaces; + * String: character string to visualize indentation ( can also be a set of white spaces ) + */ + +let exampleContent = "here-be-xml-json-css-or-sql-content-that-is-about-to-get-formatted"; + +//xml +function xmlWithDefault() { + VKBeautify.xml(exampleContent); +} + +function xmlWithNumberOfSpaces() { + VKBeautify.xml(exampleContent, 3); +} + +function xmlWithStringPattern() { + VKBeautify.xml(exampleContent, ' '); +} + +//json +function jsonWithDefault() { + VKBeautify.json(exampleContent); +} + +function jsonWithNumberOfSpaces() { + VKBeautify.json(exampleContent, 3); +} + +function jsonWithStringPattern() { + VKBeautify.json(exampleContent, ' '); +} + +//css +function cssWithDefault() { + VKBeautify.css(exampleContent); +} + +function cssWithNumberOfSpaces() { + VKBeautify.css(exampleContent, 3); +} + +function cssWithStringPattern() { + VKBeautify.css(exampleContent, ' '); +} + +//sql +function sqlWithDefault() { + VKBeautify.sql(exampleContent); +} + +function sqlWithNumberOfSpaces() { + VKBeautify.sql(exampleContent, 3); +} + +function sqlWithStringPattern() { + VKBeautify.sql(exampleContent, ' '); +} + + +/* + * Minifying + * + * vkbeautify.xmlmin(text [,preserve_comments]); + * vkbeautify.jsonmin(text); + * vkbeautify.cssmin(text [,preserve_comments]); + * vkbeautify.sqlmin(text); + * + * @text - String; text to minify; + * @preserve_comments - Bool; [optional]; + * Set this flag to true to prevent removing comments from @text ( minxml and mincss functions only. ) + */ + +//xml +function xmlminWithDefault() { + VKBeautify.xmlmin(exampleContent); +} + +function xmlminWitPreserveComments() { + VKBeautify.xmlmin(exampleContent, true); +} + +function xmlminAndRemoveComments() { + VKBeautify.xmlmin(exampleContent, false); +} + +//json +function jsonmin() { + VKBeautify.jsonmin(exampleContent); +} + +//css +function cssminWithDefault() { + VKBeautify.cssmin(exampleContent); +} + +function cssminWitPreserveComments() { + VKBeautify.cssmin(exampleContent, true); +} + +function cssminAndRemoveComments() { + VKBeautify.cssmin(exampleContent, false); +} + +//sql +function sqlmin() { + VKBeautify.sqlmin(exampleContent); +} \ No newline at end of file