Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add typings #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions cssdom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
declare interface CssDomCharset {
readonly type: 'charset';
readonly value: string;
}

declare interface CssDomImport {
readonly type: 'import';
readonly value: string;
}

declare interface CssDomRule {
readonly type: 'rule';
readonly selectors: readonly string[];
readonly declarations: {
readonly [ key: string ]: string;
};
}

declare interface CssDomKeyframes {
readonly type: 'keyframes';
readonly vendor: string|void;
readonly value: string;
readonly rules: readonly CssDomRule[];
}

declare interface CssDomDocument {
readonly type: 'document';
readonly vendor: string|void;
readonly value: string;
readonly rules: readonly CssDomRule[];
}

declare interface CssDomMedia {
readonly type: 'media';
readonly value: string;
readonly rules: readonly CssDomRule[];
}

declare interface CssDomSupports {
readonly type: 'supports';
readonly value: string;
readonly rules: readonly CssDomRule[];
}

declare interface CssDomComment {
readonly type: 'comment';
readonly value: string;
}

declare type CssDomNode = CssDomCharset|CssDomImport|CssDomRule|CssDomKeyframes|CssDomDocument|CssDomMedia|CssDomSupports|CssDomComment;

declare interface CssDomCss {
readonly [ key: string ]: string;
}

declare interface CssDomChange {
readonly [ key: string ]: string|( ( value: string, rule: CssDomRule ) => string );
}

declare interface CssDomBeautifyOptions {
readonly indent?: string;
readonly separateRule?: boolean;
}

declare class CssDom {
public dom: CssDomNode[];
public constructor( str: string );
public css( dom: CssDomNode, css: CssDomChange ): void;
public selector( selector: string, css?: void ): readonly CssDomRule[];
public selector( selector: string, css: CssDomChange ): void;
public property( property: string, css?: void ): readonly CssDomRule[];
public property( property: string, css: CssDomChange ): void;
public unshift( dom: CssDomNode|readonly CssDomNode[] ): void;
public push( dom: CssDomNode|readonly CssDomNode[] ): void;
public validateDom( dom: CssDomNode|readonly CssDomNode[] ): readonly CssDomNode[];
public stringify(): string;
public beautify( options?: CssDomBeautifyOptions ): string;
}

export = CssDom;
export as namespace CssDom;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.23",
"description": "Serialize css structure and stringify css dom, simplified change css code by program, and also support uglify and beautify",
"main": "cssdom.js",
"typings": "cssdom.d.ts",
"scripts": {
"test": "mocha --recursive"
},
Expand Down