Skip to content

Function: parseOperations() ​

ts
function parseOperations(modifiers): CdnOperation[];

Defined in: parse.ts:324

Parses a bare modifiers string (e.g. the cdnUrlModifiers value stored alongside a uuid) into operations. Lenient like parseCdnUrl; round-trips with serializeOperations.

Modifiers reach callers in whatever shape their own inputs arrive in — a stored -/…/ value, a hand-written config string, a DOM attribute — so the leading - marker, surrounding slashes and surrounding whitespace are all optional. Operations within a chain are still separated by -, which keeps resize/300x/-/blur/10 unambiguous. Consequently almost any slash-shaped string parses: this does not diagnose a malformed chain, it accepts one.

The leniency is deliberately local. Inside a URL a segment that is not - is a filename or an error, so parseCdnUrl and the per-kind parsers stay strict about the marker.

Parameters ​

ParameterType
modifiersstring

Returns ​

CdnOperation[]

Throws ​

TypeError when an operation name is missing ('-', '-/-/x').

See ​

https://uploadcare.com/docs/cdn-operations/

Example ​

ts
parseOperations('-/crop/640x480/center/-/preview/')
// → [{ name: 'crop', params: ['640x480', 'center'] }, { name: 'preview', params: [] }]

parseOperations('resize/300x') // → [{ name: 'resize', params: ['300x'] }]