TransformOptions
beautify?: boolean;
computeCalcExpression?: boolean;
computeShorthand?: boolean;
computeTransform?: boolean;
convertColor?: any;
cwd?: string;
expandIfSyntax?: boolean;
expandNestingRules?: boolean;
indent?: string;
inlineCssVariables?: boolean;
lenient?: boolean;
load?: (
url: string | { absolute: string; relative: string },
currentDirectory: string,
responseType?: boolean | ResponseType,
) => Promise<
string
| ArrayBuffer
| ReadableStream<Uint8Array<ArrayBufferLike>>,
>;
minify?: boolean;
module?:
| boolean
| ModuleCaseTransformEnum
| ModuleScopeEnumOptions
| ModuleOptions;
nestingRules?: boolean;
newLine?: string;
output?: string;
parseColor?: boolean;
pass?: number;
preserveLicense?: boolean;
removeCharset?: boolean;
removeComments?: boolean;
removeDuplicateDeclarations?: string
| boolean
| string[];
removeEmpty?: boolean;
removePrefix?: boolean;
resolve?: (
url: string,
currentUrl: string,
currentWorkingDirectory?: string,
) => { absolute: string; relative: string };
resolveImport?: boolean;
resolveUrls?: boolean;
signal?: AbortSignal;
sourcemap?: boolean | "inline";
src?: string;
validation?: boolean | ValidationLevel;
visitor?: VisitorNodeMap | VisitorNodeMap[];
withParents?: boolean;
}
Hierarchy (View Summary)
- ParserOptions
- RenderOptions
- TransformOptions
Index
Properties
Properties
Optionalbeautify
Pretty print css
const result = await transform(css, {beautify: true});
Optionalcompute Calc Expression
Compute css math functions
Optionalcompute Shorthand
Compute shorthand properties
Optionalcompute Transform
Compute css transform functions
Optionalconvert Color
Convert color to the specified color space. 'true' will convert to HEX
Optional Internalcwd
Current working directory
Optionalexpand If Syntax
Experimental, convert css if() function into legacy syntax.
Optionalexpand Nesting Rules
Expand nested rules
Optionalindent
Indention string
Optionalinline Css Variables
Inline css variables
Optionallenient
Lenient validation. retain nodes that failed validation
Optionalload
url: string | { absolute: string; relative: string },
currentDirectory: string,
responseType?: boolean | ResponseType,
) => Promise<
string
| ArrayBuffer
| ReadableStream<Uint8Array<ArrayBufferLike>>,
>
Custom URL and file loader.
Optionalminify
Enable minification
Optionalmodule
CSS modules options
Optionalnesting Rules
Generate nested rules
Optionalnew Line
New line string
Optional Internaloutput
Output file. Used for url resolution
Optionalparse Color
Parse color tokens
Optionalpass
Define minification passes.
Optionalpreserve License
Preserve license comments. License comments are comments that start with '/*!'
Optionalremove Charset
Remove at-rule charset
Optionalremove Comments
Remove comments
Optionalremove Duplicate Declarations
Remove duplicate declarations from the same rule. if passed as a string array, duplicated declarations are removed, except for those in the array
import {transform} from '@tbela99/css-parser';
const css = `
.table {
width: 100%;
width: calc(100% + 40px);
margin-left: 20px;
margin-left: min(100% , 20px)
}
`;
const result = await transform(css, {
beautify: true,
validation: true,
removeDuplicateDeclarations: ['width']
}
);
console.log(result.code);
Optionalremove Empty
Remove empty ast nodes
Optionalremove Prefix
Remove css prefix
Optionalresolve
url: string,
currentUrl: string,
currentWorkingDirectory?: string,
) => { absolute: string; relative: string }
Url and path resolver
Optionalresolve Import
Resolve import
Optionalresolve Urls
Resolve urls
Optionalsignal
Abort signal
Example: abort after 10 seconds
const result = await parse(cssString, {
signal: AbortSignal.timeout(10000)
});
Optionalsourcemap
Include sourcemap in the ast. Sourcemap info is always generated
Optionalsrc
Source file to be used for sourcemap
Optionalvalidation
Enable CSS validation. Using ValidationLevel as value is deprecated and will be removed
see ValidationLevel
Optionalvisitor
Node visitor VisitorNodeMap[]
Optionalwith Parents
Render the node along with its parents
Transform options