Search


Search something to see results

ParserOptions

Parser options

interface ParserOptions {
    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)

Index

Properties

computeCalcExpression?: boolean

Compute css math functions

computeShorthand?: boolean

Compute shorthand properties

computeTransform?: boolean

Compute css transform functions

cwd?: string

Current working directory

expandIfSyntax?: boolean

Experimental, convert css if() function into legacy syntax.

expandNestingRules?: boolean

Expand nested rules

inlineCssVariables?: boolean

Inline css variables

lenient?: boolean

Lenient validation. retain nodes that failed validation

load?: (
    url: string | { absolute: string; relative: string },
    currentDirectory: string,
    responseType?: boolean | ResponseType,
) => Promise<
    string
    | ArrayBuffer
    | ReadableStream<Uint8Array<ArrayBufferLike>>,
>

Custom URL and file loader.

minify?: boolean

Enable minification

module?:
    | boolean
    | ModuleCaseTransformEnum
    | ModuleScopeEnumOptions
    | ModuleOptions

CSS modules options

nestingRules?: boolean

Generate nested rules

parseColor?: boolean

Parse color tokens

pass?: number

Define minification passes.

removeCharset?: boolean

Remove at-rule charset

removeDuplicateDeclarations?: string | boolean | string[]

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);
removeEmpty?: boolean

Remove empty ast nodes

removePrefix?: boolean

Remove css prefix

resolve?: (
    url: string,
    currentUrl: string,
    currentWorkingDirectory?: string,
) => { absolute: string; relative: string }

Url and path resolver

resolveImport?: boolean

Resolve import

resolveUrls?: boolean

Resolve urls

signal?: AbortSignal

Abort signal

Example: abort after 10 seconds


const result = await parse(cssString, {
signal: AbortSignal.timeout(10000)
});
sourcemap?: boolean | "inline"

Include sourcemap in the ast. Sourcemap info is always generated

src?: string

Source file to be used for sourcemap

validation?: boolean | ValidationLevel

Enable CSS validation. Using ValidationLevel as value is deprecated and will be removed

see ValidationLevel

Node visitor VisitorNodeMap[]