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
This commit is contained in:
Tim Schraepen
2017-01-19 22:28:26 +01:00
committed by Mohamed Hegazy
parent 25420083bd
commit 9c0b54dc30
4 changed files with 186 additions and 0 deletions

45
vkbeautify/index.d.ts vendored Normal file
View File

@@ -0,0 +1,45 @@
// Type definitions for vkbeautify 0.99
// Project: https://github.com/aabluedragon/vkbeautify
// Definitions by: Tim Schraepen <https://github.com/sch3lp/>
// 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;

21
vkbeautify/tsconfig.json Normal file
View File

@@ -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"
]
}

1
vkbeautify/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "../tslint.json" }

View File

@@ -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);
}