fix tslint and added exports to global and module modifying types

This commit is contained in:
Peter van der Woude
2018-06-25 22:47:44 +10:00
parent 7573138186
commit 1b47d8f276
6 changed files with 32 additions and 100 deletions

View File

@@ -3,15 +3,18 @@
// Definitions by: Peter van der Woude <https://github.com/pandawood>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare global {
const cssjs: CssJsConstructor
}
/**
* Thid doesn't get used in the way I intended
*/
export function cssjs() : CssJs
export interface CssJsConstructor {
new (): CssJs;
}
export const cssjs : CssJsConstructor;
export default cssjs;
export interface CssJs {
/**
* Parses given css string, and returns css object
* keys as selectors and values are css rules

View File

@@ -0,0 +1,5 @@
function addNamespace(cssString: string): string {
const parser = new cssjs();
const parsed = parser.applyNamespacing(cssString, "#id1");
return parser.getCSSForEditor(parsed);
}

View File

@@ -0,0 +1,9 @@
import cssjsParser = require("jotform-css.js");
function addNamespace(cssString: string): string {
const parser = new cssjsParser.cssjs();
let parsed = parser.parseCSS(cssString);
parsed = parser.applyNamespacing(parsed, "#id1");
const css = parser.getCSSForEditor(parsed);
return css;
}

View File

@@ -1,17 +1,6 @@
let cssjsGlobal = require("jotform-css.js/css.js")
import { CssJs } from "./index"
// not all interface methods tested here, below is a sample of code that I've actually used
class TestParser {
public parse(cssString: string): string {
const parser = new cssjsGlobal.cssjs() as CssJs
let parsed = parser.parseCSS(cssString)
parsed = parser.applyNamespacing(parsed, "#id1")
let css = parser.getCSSForEditor(parsed)
return css
}
// DefinitelyTyped scripts are forcing me to have this, I don't need or want this file
function addNamespace2(cssString: string): string {
const parser = new cssjs();
const parsed = parser.applyNamespacing(cssString, "#id1");
return parser.getCSSForEditor(parsed);
}
let parsingTest = new TestParser()
let css = parsingTest.parse(".foo { background-color: red }")

View File

@@ -18,6 +18,8 @@
},
"files": [
"index.d.ts",
"jotform-css.js-tests.ts"
"jotform-css.js-tests.ts",
"jotform-css.js-global-tests.ts",
"jotform-css.js-module-tests.ts"
]
}

View File

@@ -1,79 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": true,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": true,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
"extends": "dtslint/dt.json"
}