diff --git a/types/jotform-css.js/index.d.ts b/types/jotform-css.js/index.d.ts new file mode 100644 index 0000000000..e21dae2eb9 --- /dev/null +++ b/types/jotform-css.js/index.d.ts @@ -0,0 +1,122 @@ +// Type definitions for jotform-css.js v1.0.1 +// Project: https://github.com/jotform/css.js +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * intermediate object - needed as a result of the way the libary doesn't explicitly export anything + */ +export interface CssJsGlobal { + cssjs() : CssJs +} + +export interface CssJs { + + /** + * Parses given css string, and returns css object + * keys as selectors and values are css rules + * eliminates all css comments before parsing + * @param {string} css string to be parsed + * @returns {CssJs} css object + */ + parseCSS(css: string): CssJs + + /** + * parses given string containing css directives + * @param {string} rules, css directive string eg color:white; font-size:18px; + * @returns {any[]} an array of objects containing ruleName:ruleValue pairs + */ + parseRules(rules: string): any[] + + /** + * returns the rule having given directive + * @param {string} rules + * @param {string} directive + * @param {string} value + */ + findCorrespondingRule(rules: string, directive: string, value?: string): string | boolean + + /** + * Finds styles that have given selector, compress them and returns them + * @param cssObject + * @param {string} selector + * @param {boolean} contains + */ + findBySelector(cssObject: CssJs, selector: string, contains?: boolean) : CssJs + + /** + * deletes cssObjects having given selector, and returns new array + * @param {CssJs} cssObject + * @param {string} selector + * @returns {CssJs} + */ + deleteBySelector(cssObject: CssJs, selector: string): CssJs + + /** + * Compresses given cssObjectArray and tries to minimize selector redundence + * @param {CssJs} cssObject + * @returns {CssJs} + */ + compressCSS(cssObject: CssJs): CssJs + + /** + * @param {CssJs} css1 + * @param {CssJs} css2 + * @returns {boolean} diff css object contains changed values in css1 in regards to css2, false if same + */ + cssDiff(css1: CssJs, css2: CssJs): boolean + + /** + * @param {CssJs} cssObject target css object array + * @param {CssJs} newArray source array that will be pushed into cssObject parameter + * @param {boolean} reverse [optional], if given true, first parameter will be traversed on reversed order + effectively giving priority to the styles in newArray + */ + intelligentMerge(cssObject: CssJs, newArray: CssJs, reverse?: boolean) : void + + /** + * inserts new css objects into a bigger css object with same selectors grouped together + * @param {CssJs} cssObject array of bigger css object to be pushed into + * @param {CssJs} minimalObject single css object + * @param {boolean} reverse reverse [optional] default is false, if given, cssObject will be reversly traversed + resulting more priority in minimalObject's styles + */ + intelligentCSSPush(cssObject: CssJs, minimalObject: CssJs, reverse?: boolean) : void + + /** + * Filter outs rule objects whose type param equal to DELETED + * @param {string} rules array of rules + */ + compactRules(rules: string[]): string[] + + /** + * Computes string for ace editor using this.css or given cssBase optional parameter + * @param {CssJs} parsedCss + * @param depth + * @returns {string} + */ + getCSSForEditor(parsedCss: CssJs, depth?: number): string + + /** + * Given rules array, returns visually formatted css string to be used inside editor + * @param {string} rules + * @param {null} depth + * @returns {string} + */ + getCSSOfRules(rules: string, depth?: null): string + + /** + * Given css string or objectArray, parses it and then for every selector, + * prepends this.cssPreviewNamespace to prevent css collision issues + * @param {CssJs} parsedCss + * @param {string} prefix + * @returns {CssJs} object in which this css prepended + */ + applyNamespacing(parsedCss: CssJs | string, prefix: string): CssJs + + /** + * @param {string} css the original css string to be stripped out of comments + * @returns {string} cleaned CSS containing no css comments + */ + stripComments(css: string): string +} diff --git a/types/jotform-css.js/jotform-css.js-tests.ts b/types/jotform-css.js/jotform-css.js-tests.ts new file mode 100644 index 0000000000..80f4fd5b54 --- /dev/null +++ b/types/jotform-css.js/jotform-css.js-tests.ts @@ -0,0 +1,17 @@ +let cssjsGlobal = require("../../jotform-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(): string { + const parser = new cssjsGlobal.cssjs() as CssJs + + let parsed = parser.parseCSS(".foo { background-color: red }") + parsed = parser.applyNamespacing(parsed, "#id1") + let css = parser.getCSSForEditor(parsed) + return css + } +} + +let parsingTest = new TestParser() +let css = parsingTest.parse() diff --git a/types/jotform-css.js/tsconfig.json b/types/jotform-css.js/tsconfig.json new file mode 100644 index 0000000000..484cc299b5 --- /dev/null +++ b/types/jotform-css.js/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": ["node"], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jotform-css.js-tests.ts" + ] +} diff --git a/types/jotform-css.js/tslint.json b/types/jotform-css.js/tslint.json new file mode 100644 index 0000000000..44e1713d82 --- /dev/null +++ b/types/jotform-css.js/tslint.json @@ -0,0 +1,79 @@ +{ + "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 + } +}