Skip to content

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 ​

InterfaceDescription
CdnOperationA single CDN URL directive: -/name/param1/param2/.
FileUrlInputInput shape for building a file url with serializeCdnUrl.
GroupIdFile group id: uuid~count.
GroupUrlInputInput shape for building a group root or group element url.
NamedOperationCreatorBrand 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').
ParsedArchiveUrlA group archive URL: /:uuid~N/archive/:format/(:filename). Archives hold the original files, so it carries no operations.
ParsedFileUrlA single-file CDN URL: /:uuid/(:conversion/)(-/op/.../)(:filename).
ParsedGroupElementUrlA group element URL: /:uuid~N/nth/i/(-/op/.../)(:filename).
ParsedGroupUrlA group root URL: /:uuid~N/. Group roots cannot carry operations or a filename — process individual files via ParsedGroupElementUrl.
ParsedProxyUrlA delivery proxy URL: /(-/op/.../):sourceUrl. The embedded source keeps its own query string and fragment, so the shape has no search/hash.
ProxyUrlInputInput shape for building a delivery proxy url.
TinyFileUrlA 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 AliasDescription
CdnUrlInputInput 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.
CdnUrlKindDiscriminant of ParsedCdnUrl.
ConversionKindConversion path prefixes that attach directly after the uuid with a plain / (no -/ separator): /:uuid/video/..., /:uuid/document/..., /:uuid/gif2video/....
CropAlignmentAlignment keywords accepted where a crop offset may be given.
DomainKindCDN domain classification.
ModifiersChainA -/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.
OperationLiteralOperations as typed string literals, for callers whose only need is to write a modifiers chain they author themselves.
OperationRefAnything that identifies an operation: its name as a string, an operation object, or the creator function itself.
ParsedCdnUrlA CDN URL decomposed into a plain serializable shape, discriminated by CdnUrlKind. Produced by parseCdnUrl, consumed by serializeCdnUrl.

Variables ​

VariableDescription
LEGACY_CDN_BASEThe 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_BASEThe 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 ​

FunctionDescription
detectDomainKindClassifies 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)
isArchiveUrlWhether a string is a group archive URL, without parsing it or throwing.
isFileUrlWhether a string is a single-file CDN URL, without parsing it or throwing. Pair with parseFileUrl when the input is untrusted.
isGroupElementUrlWhether a string is a group element URL, without parsing it or throwing.
isGroupUrlWhether a string is a group root URL, without parsing it or throwing.
isProxyUrlWhether a string is a delivery proxy URL, without parsing it or throwing. Distinct from isProxyEndpoint, which only inspects the host.
isUploadcareDomainWhether the host is operated by Uploadcare (not a custom CNAME).
joinModifiersConcatenates 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.
modifiersJoins typed operation literals into a ModifiersChain — the whole runtime cost of this module.
normalizeModifiersNormalizes 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.
operationBaseNameResolves an OperationRef to its directive name with any counted suffix stripped — thumbs~5 and thumbs~3 both reduce to thumbs.
operationMatchesWhether 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.
operationNameOfResolves an OperationRef to the operation name it identifies.
parseArchiveUrlParses a group archive URL (/:uuid~N/archive/:format/(:filename)), the read-side counterpart of archiveUrl.
parseCdnUrlParses any Uploadcare CDN URL — file, group, group element, conversion result or proxified remote source — into a ParsedCdnUrl discriminated by kind.
parseFileUrlParses 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.
parseGroupElementUrlParses a group element URL (/:uuid~N/nth/i/). Narrower than parseCdnUrl, and distinct from parseGroupUrl, which handles the group root.
parseGroupUrlParses a group root URL (/:uuid~N/). Group roots carry no operations and no filename, which is why the returned shape has neither.
parseOperationsParses a bare modifiers string (e.g. the cdnUrlModifiers value stored alongside a uuid) into operations. Lenient like parseCdnUrl; round-trips with serializeOperations.
parseProxyUrlParses a delivery proxy URL. Narrower than parseCdnUrl: importing this alone leaves the file and group parsers out of your bundle.
serializeCdnUrlBuilds 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.
serializeFileUrlBuilds a url for a single stored file — the write-side counterpart of parseFileUrl.
serializeGroupUrlBuilds 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.
serializeOperationsSerializes operations into the -/name/params/ directive chain ('' when the list is empty).
serializeProxyUrlBuilds 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.
tinyBuildJoins 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.
tinyParseCuts 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.
unsafeOperationEscape hatch for an operation OperationLiteral cannot express — an overlay with a uuid, a text with arbitrary content, or a directive newer than this package.