* Remove unused CSS * * @param userOptions - PurgeCSS options or path to the configuration file * @returns an array of object containing the filename and the associated CSS * * @example Using a configuration file named purgecss.config.js * ```ts * const purgeCSSResults = await n
(
userOptions: UserDefinedOptions | string | undefined,
)
| 808 | * ``` |
| 809 | */ |
| 810 | public async purge( |
| 811 | userOptions: UserDefinedOptions | string | undefined, |
| 812 | ): Promise<ResultPurge[]> { |
| 813 | this.options = |
| 814 | typeof userOptions !== "object" |
| 815 | ? await setOptions(userOptions) |
| 816 | : { |
| 817 | ...defaultOptions, |
| 818 | ...userOptions, |
| 819 | safelist: standardizeSafelist(userOptions.safelist), |
| 820 | }; |
| 821 | const { content, css, extractors, safelist } = this.options; |
| 822 | |
| 823 | if (this.options.variables) { |
| 824 | this.variablesStructure.safelist = safelist.variables || []; |
| 825 | } |
| 826 | |
| 827 | const fileFormatContents = content.filter( |
| 828 | (o) => typeof o === "string", |
| 829 | ) as string[]; |
| 830 | const rawFormatContents = content.filter( |
| 831 | (o) => typeof o === "object", |
| 832 | ) as RawContent[]; |
| 833 | |
| 834 | const cssFileSelectors = await this.extractSelectorsFromFiles( |
| 835 | fileFormatContents, |
| 836 | extractors, |
| 837 | ); |
| 838 | const cssRawSelectors = await this.extractSelectorsFromString( |
| 839 | rawFormatContents, |
| 840 | extractors, |
| 841 | ); |
| 842 | |
| 843 | return this.getPurgedCSS( |
| 844 | css, |
| 845 | mergeExtractorSelectors(cssFileSelectors, cssRawSelectors), |
| 846 | ); |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * Remove unused CSS variables |
no test coverage detected