Skip to content

Commit 8fec609

Browse files
committed
add index.d.ts
1 parent f40cc81 commit 8fec609

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

index.d.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// From DefinitelyTyped by Adam Thompson-Sharpe (https://github.com/MysteryBlokHed) with some modifications.
2+
import { AcceptedPlugin, Root } from 'postcss'
3+
4+
declare namespace postcssJs {
5+
/** CSS-in-JS object */
6+
type CssInJs = Record<string, any>
7+
8+
/**
9+
* Create a PostCSS processor with a simple API
10+
* @param plugins Synchronous plugins to use with PostCSS
11+
* @returns A processor function that accepts (idk) and returns a CSS-in-JS object
12+
*/
13+
function sync(
14+
plugins?: readonly AcceptedPlugin[]
15+
): (input: CssInJs) => CssInJs
16+
function sync(...plugins: AcceptedPlugin[]): (input: CssInJs) => CssInJs
17+
18+
/**
19+
* Create a PostCSS processor with a simple API, allowing asynchronous plugins
20+
* @param plugins Plugins to use with PostCSS
21+
* @returns A processor function that accepts (idk) and returns a CSS-in-JS object
22+
*/
23+
function async(
24+
plugins?: readonly AcceptedPlugin[]
25+
): (input: CssInJs) => Promise<CssInJs>
26+
function async(
27+
...plugins: AcceptedPlugin[]
28+
): (input: CssInJs) => Promise<CssInJs>
29+
30+
/**
31+
* Parse a CSS-in-JS object into a PostCSS `Root`
32+
* @param obj The CSS-in-JS to parse
33+
* @returns A PostCSS `Root`
34+
*/
35+
function parse(obj: CssInJs): Root
36+
37+
interface ObjectifyOptions {
38+
stringifyImportant?: boolean | undefined
39+
}
40+
41+
/**
42+
* Convert a PostCSS `Root` into a CSS-in-JS object
43+
* @param root The root to convert
44+
* @returns CSS-in-JS object
45+
*/
46+
function objectifiy(root: Root, options?: ObjectifyOptions): CssInJs
47+
48+
export {
49+
CssInJs,
50+
ObjectifyOptions,
51+
sync,
52+
async,
53+
objectifiy,
54+
parse,
55+
postcssJs as default
56+
}
57+
}
58+
59+
export = postcssJs

0 commit comments

Comments
 (0)