ParseTokenOptions
computeCalcExpression?: boolean;
computeShorthand?: boolean;
computeTransform?: boolean;
cwd?: string;
expandIfSyntax?: boolean;
expandNestingRules?: boolean;
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;
parseColor?: boolean;
pass?: number;
removeCharset?: 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[];
}
Hierarchy (View Summary)
- ParserOptions
- ParseTokenOptions
Index
Properties
Properties
Optionalcompute Calc Expression
Compute css math functions
Optionalcompute Shorthand
Compute shorthand properties
Optionalcompute Transform
Compute css transform functions
Optional Internalcwd
Current working directory
Optionalexpand If Syntax
Experimental, convert css if() function into legacy syntax.
Optionalexpand Nesting Rules
Expand nested rules
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
Optionalparse Color
Parse color tokens
Optionalpass
Define minification passes.
Optionalremove Charset
Remove at-rule charset
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[]
Parse token options