core
The functional core: parse and serialize CDN URLs, the string-level API, and the shared types. Imported as @uploadcare/cdn-url.
Named core rather than the default index so its reference pages do not collide with the reference landing page (reference/index.md).
Interfaces
| Interface | Description |
|---|---|
| CdnOperation | A single CDN URL directive: -/name/param1/param2/. |
| FileUrlInput | Input shape for building a file url with serializeCdnUrl. |
| GroupId | File group id: uuid~count. |
| GroupUrlInput | Input shape for building a group root or group element url. |
| NamedOperationCreator | Brand carried by every operation creator: the CDN directive name it produces. Lets creators themselves act as OperationRefs — url.without(resize) instead of url.without('resize'). |
| ParsedArchiveUrl | A group archive URL: /:uuid~N/archive/:format/(:filename). Archives hold the original files, so it carries no operations. |
| ParsedFileUrl | A single-file CDN URL: /:uuid/(:conversion/)(-/op/.../)(:filename). |
| ParsedGroupElementUrl | A group element URL: /:uuid~N/nth/i/(-/op/.../)(:filename). |
| ParsedGroupUrl | A group root URL: /:uuid~N/. Group roots cannot carry operations or a filename — process individual files via ParsedGroupElementUrl. |
| ParsedProxyUrl | A delivery proxy URL: /(-/op/.../):sourceUrl. The embedded source keeps its own query string and fragment, so the shape has no search/hash. |
| ProxyUrlInput | Input shape for building a delivery proxy url. |
| TinyFileUrl | A single-file CDN url cut into the strings tinyBuild joins back together. Only cdnBase and uuid are required; the rest default to empty, so a bare url is { cdnBase, uuid }. The field names match ParsedFileUrl, with modifiers standing in for its operations. |
Type Aliases
| Type Alias | Description |
|---|---|
| CdnUrlInput | Input for serializeCdnUrl — discriminated by which addressing field is present (uuid, group or sourceUrl). Every ParsedCdnUrl is a valid input, which is what makes parse → edit → serialize round-trips work. |
| CdnUrlKind | Discriminant of ParsedCdnUrl. |
| ConversionKind | Conversion path prefixes that attach directly after the uuid with a plain / (no -/ separator): /:uuid/video/..., /:uuid/document/..., /:uuid/gif2video/.... |
| CropAlignment | Alignment keywords accepted where a crop offset may be given. |
| DomainKind | CDN domain classification. |
| ModifiersChain | A -/name/params/ directive chain, nominally typed: a plain string at run time, but assignable only from a value this module produced — modifiers(), normalizeModifiers, joinModifiers() or tinyParse. |
| OperationLiteral | Operations as typed string literals, for callers whose only need is to write a modifiers chain they author themselves. |
| OperationRef | Anything that identifies an operation: its name as a string, an operation object, or the creator function itself. |
| ParsedCdnUrl | A CDN URL decomposed into a plain serializable shape, discriminated by CdnUrlKind. Produced by parseCdnUrl, consumed by serializeCdnUrl. |
Variables
| Variable | Description |
|---|---|
| LEGACY_CDN_BASE | The legacy shared CDN base. It serves any project's files unprefixed, which is why it is the only safe fallback — but new projects should deliver from their own prefixed host — see prefixedCdnBase — rather than reach for this. |
| PREFIX_CDN_BASE | The zone a project prefix is prepended to: <prefix>.ucarecd.net, which is what cdn-base!prefixedCdnBase computes. Not a typo for ucarecdn.com — it is the separate zone that serves per-project prefixed hostnames, and it only answers with a prefix, never bare. |
Functions
| Function | Description |
|---|---|
| detectDomainKind | Classifies a CDN host: - legacy — ucarecdn.com (and its environment subdomains) - prefixed — project-prefixed *.ucarecd.net - proxy — delivery proxy *.ucr.io - custom — anything else (user CNAME) |
| isArchiveUrl | Whether a string is a group archive URL, without parsing it or throwing. |
| isFileUrl | Whether a string is a single-file CDN URL, without parsing it or throwing. Pair with parseFileUrl when the input is untrusted. |
| isGroupElementUrl | Whether a string is a group element URL, without parsing it or throwing. |
| isGroupUrl | Whether a string is a group root URL, without parsing it or throwing. |
| isProxyUrl | Whether a string is a delivery proxy URL, without parsing it or throwing. Distinct from isProxyEndpoint, which only inspects the host. |
| isUploadcareDomain | Whether the host is operated by Uploadcare (not a custom CNAME). |
| joinModifiers | Concatenates chains — the branded stand-in for `${a}${b}`, which would widen back to string. Order is preserved, so this is how you append to a chain you already have. |
| modifiers | Joins typed operation literals into a ModifiersChain — the whole runtime cost of this module. |
| normalizeModifiers | Normalizes a modifiers string of any shape into a ModifiersChain — the string-level counterpart of parseOperations, and the way a value that did not come from modifiers() becomes a chain. |
| operationBaseName | Resolves an OperationRef to its directive name with any counted suffix stripped — thumbs~5 and thumbs~3 both reduce to thumbs. |
| operationMatches | Whether an operation matches a ref, comparing base names so that counted suffixes line up in both directions: thumbs~5 matches the thumbs ref, the thumbs operation matches a thumbs~5 ref, and thumbs~5 matches thumbs~3. |
| operationNameOf | Resolves an OperationRef to the operation name it identifies. |
| parseArchiveUrl | Parses a group archive URL (/:uuid~N/archive/:format/(:filename)), the read-side counterpart of archiveUrl. |
| parseCdnUrl | Parses any Uploadcare CDN URL — file, group, group element, conversion result or proxified remote source — into a ParsedCdnUrl discriminated by kind. |
| parseFileUrl | Parses a single-file URL, including conversion results. Narrower than parseCdnUrl: importing this alone keeps the group and proxy parsers out of your bundle, and the result is already narrowed to ParsedFileUrl without a kind check. |
| parseGroupElementUrl | Parses a group element URL (/:uuid~N/nth/i/). Narrower than parseCdnUrl, and distinct from parseGroupUrl, which handles the group root. |
| parseGroupUrl | Parses a group root URL (/:uuid~N/). Group roots carry no operations and no filename, which is why the returned shape has neither. |
| parseOperations | Parses a bare modifiers string (e.g. the cdnUrlModifiers value stored alongside a uuid) into operations. Lenient like parseCdnUrl; round-trips with serializeOperations. |
| parseProxyUrl | Parses a delivery proxy URL. Narrower than parseCdnUrl: importing this alone leaves the file and group parsers out of your bundle. |
| serializeCdnUrl | Builds a CDN URL string from a CdnUrlInput, discriminated by which addressing field is present: sourceUrl (proxy), group (group root or, with nth, a group element) or uuid (file). The counterpart of parseCdnUrl: serializeCdnUrl(parseCdnUrl(url)) === url. |
| serializeFileUrl | Builds a url for a single stored file — the write-side counterpart of parseFileUrl. |
| serializeGroupUrl | Builds a group root url, a group element url when nth is given, or the group's archive url when archive is — the write-side counterpart of parseGroupUrl, parseGroupElementUrl and parseArchiveUrl. |
| serializeOperations | Serializes operations into the -/name/params/ directive chain ('' when the list is empty). |
| serializeProxyUrl | Builds a delivery proxy url for a remote source — the write-side counterpart of parseProxyUrl. The source url is embedded verbatim and trails the operations, so it carries its own query string. |
| tinyBuild | Joins TinyFileUrl back into a url — the tiny counterpart of serializeFileUrl. Every field but cdnBase and uuid is optional, so this builds a url from scratch as readily as it rebuilds a parsed one. A trailing slash on cdnBase is trimmed, matching serializeFileUrl; nothing else is normalized. |
| tinyParse | Cuts a single-file CDN url into TinyFileUrl, every field filled ('' when absent) — the tiny counterpart of parseFileUrl. Never throws and never validates: unknown operations and internal @-prefixed directives survive verbatim, and a secure-delivery token is kept in search. |
| unsafeOperation | Escape hatch for an operation OperationLiteral cannot express — an overlay with a uuid, a text with arbitrary content, or a directive newer than this package. |