diff --git a/types/kss/index.d.ts b/types/kss/index.d.ts new file mode 100644 index 0000000000..0937ba408e --- /dev/null +++ b/types/kss/index.d.ts @@ -0,0 +1,149 @@ +// Type definitions for KSS 3.0.0-beta +// Project: https://github.com/kss-node/kss-node +// Definitions by: Gilad Gray +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** Builds a styleguide given the proper options. */ +declare function kss(options?: kss.IKssOptions): Promise; +declare namespace kss { + interface IFile { + /** bath to source directory */ + base: string; + /** file contents */ + contents: string; + /** full path to file */ + path: string; + } + + interface ISource { + /** The name of the file. */ + filename: string; + /** The full path of the file. */ + path: string; + /** The line number where the KSS comment is found. */ + line: number; + } + + interface IOptions { + /** + * Whether to automatically format Markdown using [marked](https://github.com/chjj/marked). + * Enabled by default. + * @default true + */ + markdown?: boolean; + /** + * Use a regex or string (e.g. `*.less|*.css`) to only parse files matching this value. + * @default *.css|*.less|*.sass|*.scss|*.styl|*.stylus + */ + mask?: string | RegExp; + /** + * kss-node makes the header available separately from the description. To make kss-node + * behave like the Ruby KSS, disable this option and the title will remain a part of the + * description. Enabled by default. + * @default true. + */ + header?: boolean; + } + + interface IKssOptions extends IOptions { + builder?: any; + clone?: boolean; + custom?: any; + logErrorFunction?: (...msg: string[]) => void; + json?: boolean; + mask?: string | RegExp; + source: string[]; + verbose?: boolean; + } + + type CallbackFn = (error: Error | null, styleguide: KssStyleguide) => void; + + class KssStyleguide { + constructor(data?: object); + autoInit(autoInit: boolean): KssStyleguide; + customPropertyNames(): string[]; + customPropertyNames(names: string | string[]): KssStyleguide; + hasNumericReferences(): boolean; + init(): KssStyleguide; + referenceDelimiter(): string; + sections(): KssSection[]; + sections(query: string | RegExp): false | KssSection | KssSection[]; + sections(sections: KssSection | KssSection[]): KssStyleguide; + toJSON(): object; + } + + class KssSection { + constructor(data?: object); + custom(name: string): any; + custom(name: string, value: any): KssSection; + customPropertyNames(): string[]; + deprecated(): boolean; + deprecated(deprecated: boolean): KssSection; + depth(): number; + depth(depth: number): KssSection; + description(): string; + description(description: string): KssSection; + experimental(): boolean; + experimental(experimental: boolean): KssSection; + header(): string; + header(header: string): KssSection; + markup(): false | string; + markup(markup: string): KssSection; + modifiers(): KssModifier[]; + modifiers(query: number | string): false | KssModifier; + modifiers(modifiers: KssModifier | KssModifier[]): KssSection; + parameters(): KssParameter[]; + parameters(query: number | string): false | KssParameter; + parameters(parameters: KssParameter | KssParameter[]): KssSection; + reference(): string; + reference(reference: string): KssSection; + referenceNumber(): string; + referenceNumber(referenceNumber: string): KssSection; + referenceURI(): string; + referenceURI(referenceURI: string): KssSection; + source(): ISource; + source(source: ISource): KssSection; + sourceFileName(): string; + sourceLine(): string; + styleGuide(): KssStyleguide; + styleGuide(styleguide: KssStyleguide): KssSection; + toJSON(): object; + weight(): number; + weight(weight: number): KssSection; + } + + class KssModifier { + constructor(data?: object); + className(): string; + className(className: string): KssModifier; + description(): string; + description(description: string): KssModifier; + markup(): string; + markup(markup: string): KssModifier; + name(): string; + name(name: string): KssModifier; + section(): KssSection; + section(section: KssSection): KssModifier; + toJSON(): object; + } + + class KssParameter { + constructor(data?: object); + defaultValue(): string; + description(): string; + description(description: string): KssParameter; + name(): string; + name(name: string): KssParameter; + section(): KssSection; + section(section: KssSection): KssParameter; + toJSON(): object; + } + + /** Parse a string of documented CSS, or an array of file objects with their content. */ + function parse(input: string | IFile[], options: IOptions): KssStyleguide; + + /** Traverse a directory, parse its contents, and create a `KssStyleGuide`. */ + function traverse(directory: string | string[], options: IOptions): Promise; +} + +export = kss; diff --git a/types/kss/kss-tests.ts b/types/kss/kss-tests.ts new file mode 100644 index 0000000000..1ad03a785b --- /dev/null +++ b/types/kss/kss-tests.ts @@ -0,0 +1,10 @@ +import kss = require("kss"); + +kss.traverse("src", { markdown: false }) + .then((styleguide) => styleguide.sections()) + .then((sections) => sections.map((s) => s.toJSON())) + .then((json) => console.log(json)); + +const json = kss.parse("file contents", { header: false }).sections().map((s) => s.toJSON()); + +// both json vars should be the same type diff --git a/types/kss/tsconfig.json b/types/kss/tsconfig.json new file mode 100644 index 0000000000..4dcd9b1539 --- /dev/null +++ b/types/kss/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "kss-tests.ts" + ] +} diff --git a/types/kss/tslint.json b/types/kss/tslint.json new file mode 100644 index 0000000000..f9e30021f4 --- /dev/null +++ b/types/kss/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +}