Skip to content
Draft
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
5 changes: 5 additions & 0 deletions async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { async as _async } from './index.js'

declare const async: typeof _async

export = async
9 changes: 9 additions & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
CssInJs,
ObjectifyOptions,
sync,
async,
objectify,
parse,
default
} from './index.js'
59 changes: 59 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// From DefinitelyTyped by Adam Thompson-Sharpe (https://github.com/MysteryBlokHed) with some modifications.
import { AcceptedPlugin, Root } from 'postcss'

declare namespace postcssJs {
/** CSS-in-JS object */
type CssInJs = Record<string, any>

/**
* Create a PostCSS processor with a simple API
* @param plugins Synchronous plugins to use with PostCSS
* @returns A processor function that accepts (idk) and returns a CSS-in-JS object
*/
function sync(
plugins?: readonly AcceptedPlugin[]
): (input: CssInJs) => CssInJs
function sync(...plugins: AcceptedPlugin[]): (input: CssInJs) => CssInJs

/**
* Create a PostCSS processor with a simple API, allowing asynchronous plugins
* @param plugins Plugins to use with PostCSS
* @returns A processor function that accepts (idk) and returns a CSS-in-JS object
*/
function async(
plugins?: readonly AcceptedPlugin[]
): (input: CssInJs) => Promise<CssInJs>
function async(
...plugins: AcceptedPlugin[]
): (input: CssInJs) => Promise<CssInJs>

/**
* Parse a CSS-in-JS object into a PostCSS `Root`
* @param obj The CSS-in-JS to parse
* @returns A PostCSS `Root`
*/
function parse(obj: CssInJs): Root

interface ObjectifyOptions {
stringifyImportant?: boolean | undefined
}

/**
* Convert a PostCSS `Root` into a CSS-in-JS object
* @param root The root to convert
* @returns CSS-in-JS object
*/
function objectify(root: Root, options?: ObjectifyOptions): CssInJs

export {
CssInJs,
ObjectifyOptions,
sync,
async,
objectify,
parse,
postcssJs as default
}
}

export = postcssJs
7 changes: 7 additions & 0 deletions objectifier.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ObjectifyOptions, objectifiy } from './index.js'

declare namespace objectifier {
export { ObjectifyOptions, objectifiy as default }
}

export = objectifier
5 changes: 5 additions & 0 deletions parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { parse } from './index.js'

declare const parser: typeof parse

export = parser
7 changes: 7 additions & 0 deletions process-result.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CssInJs } from './index.js'
import { LazyResult } from 'postcss'
import NoWorkResult from 'postcss/lib/no-work-result'

declare function processResult(result: LazyResult | NoWorkResult): CssInJs

export = processResult
5 changes: 5 additions & 0 deletions sync.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { sync as _sync } from './index.js'

declare const sync: typeof _sync

export = sync