Skip to content

Commit 3db256e

Browse files
authored
Merge pull request #87 from hyperz111/types
feat: add types
2 parents f40cc81 + aee18e2 commit 3db256e

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed

async.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { async as _async } from './index.js'
2+
3+
declare const async: typeof _async
4+
5+
export = async

index.d.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export {
2+
CssInJs,
3+
ObjectifyOptions,
4+
sync,
5+
async,
6+
objectify,
7+
parse,
8+
default
9+
} from './index.js'

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 objectify(root: Root, options?: ObjectifyOptions): CssInJs
47+
48+
export {
49+
CssInJs,
50+
ObjectifyOptions,
51+
sync,
52+
async,
53+
objectify,
54+
parse,
55+
postcssJs as default
56+
}
57+
}
58+
59+
export = postcssJs

objectifier.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ObjectifyOptions, objectifiy } from './index.js'
2+
3+
declare namespace objectifier {
4+
export { ObjectifyOptions, objectifiy as default }
5+
}
6+
7+
export = objectifier

parser.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { parse } from './index.js'
2+
3+
declare const parser: typeof parse
4+
5+
export = parser

process-result.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { CssInJs } from './index.js'
2+
import { LazyResult } from 'postcss'
3+
import NoWorkResult from 'postcss/lib/no-work-result'
4+
5+
declare function processResult(result: LazyResult | NoWorkResult): CssInJs
6+
7+
export = processResult

sync.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { sync as _sync } from './index.js'
2+
3+
declare const sync: typeof _sync
4+
5+
export = sync

0 commit comments

Comments
 (0)