Add a type for RTLCSS's default plugin export (#45682)

This is written to match the structure of the autoprefixer types.
This commit is contained in:
Natalie Weizenbaum 2020-06-24 04:13:55 -07:00 committed by GitHub
parent e0d0934a56
commit b6d034a729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 72 deletions

View File

@ -4,77 +4,90 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.3
export interface MapOptions {
scope: string;
ignoreCase: boolean;
greedy?: boolean;
import { Plugin } from 'postcss';
declare namespace rtlcss {
interface MapOptions {
scope: string;
ignoreCase: boolean;
greedy?: boolean;
}
interface StringMap {
name: string;
priority: number;
exclusive?: boolean;
search: string|string[];
replace: string|string[];
options: MapOptions;
}
interface ConfigOptions {
/**
* Applies to CSS rules containing no directional properties,
* it will update the selector by applying String Map.
*/
autoRename: boolean;
/**
* Ensures autoRename is applied only if pair exists.
*/
autoRenameStrict: boolean;
/**
* An object map of disabled plugins directives,
* where keys are plugin names and value are object
* hash of disabled directives. e.g. {'rtlcss':{'config':true}}.
*/
blacklist: object;
/**
* Removes directives comments from output CSS.
*/
clean: boolean;
/**
* Fallback value for String Map options.
*/
greedy: boolean;
/**
* Applies String Map to URLs. You can also target specific node types using an object literal.
* e.g. {'atrule': true, 'decl': false}.
*/
processUrls: boolean|object;
/**
* The default array of String Map.
*/
stringMap: StringMap[];
/**
* When enabled, flips background-position expressed in length units using calc.
*/
useCalc: boolean;
}
interface HookOptions {
/**
* The function to be called before processing the CSS.
*/
pre: () => void;
/**
* The function to be called after processing the CSS.
*/
post: () => void;
}
interface ExportedAPI {
/**
* Creates a new RTLCSS instance, process the input and return its result.
*/
process(
css: string, options?: object, plugins?: object|string[],
hooks?: HookOptions): string;
/**
* Creates a new instance of RTLCSS using the passed configuration object.
*/
configure(config: ConfigOptions): object;
}
type RtlCss = Plugin<ConfigOptions> & ExportedAPI;
}
export interface StringMap {
name: string;
priority: number;
exclusive?: boolean;
search: string|string[];
replace: string|string[];
options: MapOptions;
}
export interface ConfigOptions {
/**
* Applies to CSS rules containing no directional properties,
* it will update the selector by applying String Map.
*/
autoRename: boolean;
/**
* Ensures autoRename is applied only if pair exists.
*/
autoRenameStrict: boolean;
/**
* An object map of disabled plugins directives,
* where keys are plugin names and value are object
* hash of disabled directives. e.g. {'rtlcss':{'config':true}}.
*/
blacklist: object;
/**
* Removes directives comments from output CSS.
*/
clean: boolean;
/**
* Fallback value for String Map options.
*/
greedy: boolean;
/**
* Applies String Map to URLs. You can also target specific node types using an object literal.
* e.g. {'atrule': true, 'decl': false}.
*/
processUrls: boolean|object;
/**
* The default array of String Map.
*/
stringMap: StringMap[];
/**
* When enabled, flips background-position expressed in length units using calc.
*/
useCalc: boolean;
}
export interface HookOptions {
/**
* The function to be called before processing the CSS.
*/
pre: () => void;
/**
* The function to be called after processing the CSS.
*/
post: () => void;
}
/**
* Creates a new RTLCSS instance, process the input and return its result.
*/
export function process(css: string, options?: object, plugins?: object|string[], hooks?: HookOptions): string;
/**
* Creates a new instance of RTLCSS using the passed configuration object.
*/
export function configure(config: ConfigOptions): object;
declare const rtlcss: rtlcss.RtlCss;
export = rtlcss;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"postcss": "7.x.x"
}
}

View File

@ -1,4 +1,5 @@
import * as rtlcss from "rtlcss";
import { Transformer } from 'postcss';
rtlcss.process("body { direction:ltr; }");
@ -25,3 +26,5 @@ const config = {
};
rtlcss.configure(config);
const transformer: Transformer = rtlcss(config);