ParserSyncOptions
arena?: AstArena;
computeCalcExpression?: boolean;
computeShorthand?: boolean;
computeTransform?: boolean;
cwd?: string;
evaluateMixins?: boolean;
expandIfSyntax?: boolean;
expandNestingRules?: boolean;
inlineCssVariables?: boolean;
inputSourceMap?: string | SourceMapObject;
keepMixins?: boolean;
lenient?: boolean;
minify?: boolean;
minifyAST?: boolean;
module?:
| boolean
| ModuleSyncOptions
| ModuleCaseTransformEnum
| ModuleScopeEnumOptions;
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 };
resolveUrls?: boolean;
signal?: AbortSignal;
source?: SourceFile | null;
sourcemap?: boolean | "inline";
sourcesMap?: Map<number, SourceFile>;
src?: string;
validation?: boolean;
visitor?: any;
}
Hierarchy (View Summary)
Index
Properties
Properties
Optionalarena
Arena the ast nodes are allocated in. Created by the parser when omitted.
Nested parses (@import) allocate their nodes in the parent arena.
Optionalcompute Calc Expression
Compute css math functions
Optionalcompute Shorthand
Compute shorthand properties
Optionalcompute Transform
Compute css transform functions
Optional Internalcwd
Current working directory
Optionalevaluate Mixins
Evaluate css mixins and custom functions: the @apply rules are replaced by the body of the mixin they reference,
the private variables (@private, mixin arguments and the custom properties of the rule) are substituted.
the custom function calls (--fn(1px)) are replaced by the result of the function.
see https://drafts.csswg.org/css-mixins-1/
import {transform} from '@tbela99/css-parser';
const css = `
@mixin --only-descs(--arg) {
color: var(--arg);
& * { color: var(--arg, red); }
}
.foo {
@apply --only-descs(green);
}
`;
const result = await transform(css, {evaluateMixins: true, expandNestingRules: true});
console.log(result.code);
// .foo,.foo *{color:green}
Optionalexpand If Syntax
Experimental, convert css if() function into legacy syntax.
Optionalexpand Nesting Rules
Expand nested rules
Optionalinline Css Variables
Inline css variables
Optionalinput Source Map
Input source map
Optionalkeep Mixins
Keep the mixins and the custom functions once they are evaluated, see evaluateMixins. By default, the evaluated mixins and custom functions, and the mixins that are not referenced, are dropped and replaced with a comment
Optionallenient
Lenient validation. retain nodes that failed validation
Optionalminify
Enable minification
Optionalminify AST
enable ast 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 Urls
Resolve urls
Optionalsignal
Abort signal
Example: abort after 10 seconds
const result = await parse(cssString, {
signal: AbortSignal.timeout(10000)
});
Optional Internalsource
Source file to be used for sourcemap
Optionalsourcemap
Include sourcemap in the ast. Sourcemap info is always generated
Optional Internalsources Map
Source file to be used for sourcemap
Optionalsrc
Source file to be used for sourcemap
Optionalvalidation
Enable CSS validation
Optionalvisitor
Node visitor VisitorSyncNodeMap[]
Sync parseroptions