UNPKG

1.94 kBTypeScriptView Raw
1import type { StringifyOptions, DataUri, Plugin as PluginFn } from './types';
2import type {
3 BuiltinsWithOptionalParams,
4 BuiltinsWithRequiredParams,
5} from '../plugins/plugins-types';
6
7type CustomPlugin = {
8 name: string;
9 fn: PluginFn<void>;
10};
11
12type PluginConfig =
13 | keyof BuiltinsWithOptionalParams
14 | {
15 [Name in keyof BuiltinsWithOptionalParams]: {
16 name: Name;
17 params?: BuiltinsWithOptionalParams[Name];
18 };
19 }[keyof BuiltinsWithOptionalParams]
20 | {
21 [Name in keyof BuiltinsWithRequiredParams]: {
22 name: Name;
23 params: BuiltinsWithRequiredParams[Name];
24 };
25 }[keyof BuiltinsWithRequiredParams]
26 | CustomPlugin;
27
28export type Config = {
29 /** Can be used by plugins, for example prefixids */
30 path?: string;
31 /** Pass over SVGs multiple times to ensure all optimizations are applied. */
32 multipass?: boolean;
33 /** Precision of floating point numbers. Will be passed to each plugin that supports this param. */
34 floatPrecision?: number;
35 /**
36 * Plugins configuration
37 * ['preset-default'] is default
38 * Can also specify any builtin plugin
39 * ['sortAttrs', { name: 'prefixIds', params: { prefix: 'my-prefix' } }]
40 * Or custom
41 * [{ name: 'myPlugin', fn: () => ({}) }]
42 */
43 plugins?: PluginConfig[];
44 /** Options for rendering optimized SVG from AST. */
45 js2svg?: StringifyOptions;
46 /** Output as Data URI string. */
47 datauri?: DataUri;
48};
49
50type Output = {
51 data: string;
52};
53
54/** The core of SVGO */
55export declare function optimize(input: string, config?: Config): Output;
56
57/**
58 * If you write a tool on top of svgo you might need a way to load svgo config.
59 *
60 * You can also specify relative or absolute path and customize current working directory.
61 */
62export declare function loadConfig(
63 configFile: string,
64 cwd?: string,
65): Promise<Config>;
66export declare function loadConfig(
67 configFile?: null,
68 cwd?: string,
69): Promise<Config | null>;