Class: CdnUrl
Defined in: builder/cdn-url.ts:95
Immutable, chainable facade over the functional core. Optional import — everything it does is possible with parseCdnUrl, serializeCdnUrl and plain array operations.
Every mutator returns a new instance; the original is never changed.
Example
CdnUrl.parse(src).without(resize).with(preview(800, 600)).hrefSee
https://uploadcare.com/docs/cdn-operations/
Constructors
Constructor
new CdnUrl(init): CdnUrl;Defined in: builder/cdn-url.ts:98
Parameters
| Parameter | Type |
|---|---|
init | | ParsedCdnUrl | CdnUrlInput |
Returns
CdnUrl
Accessors
href
Get Signature
get href(): string;Defined in: builder/cdn-url.ts:125
The serialized URL string.
Returns
string
operations
Get Signature
get operations(): CdnOperation[];Defined in: builder/cdn-url.ts:120
A defensive copy of the operation chain (empty for group root urls).
Returns
Methods
base()
base(cdnBase): CdnUrl;Defined in: builder/cdn-url.ts:233
Rebases the url onto another domain (trailing slash tolerated).
Parameters
| Parameter | Type |
|---|---|
cdnBase | string |
Returns
CdnUrl
filename()
filename(filename): CdnUrl;Defined in: builder/cdn-url.ts:222
Sets or clears (null) the trailing filename.
Parameters
| Parameter | Type |
|---|---|
filename | string | null |
Returns
CdnUrl
Throws
TypeError on group root and proxy urls.
get()
get(ref): CdnOperation | null;Defined in: builder/cdn-url.ts:200
First matching operation (name, object or creator ref), or null.
Parameters
| Parameter | Type |
|---|---|
ref | OperationRef |
Returns
CdnOperation | null
getAll()
getAll(ref): CdnOperation[];Defined in: builder/cdn-url.ts:213
Every matching operation, in chain order — the stackable-aware companion to CdnUrl.get. Returns a fresh array; empty when nothing matches.
Parameters
| Parameter | Type |
|---|---|
ref | OperationRef |
Returns
Example
CdnUrl.parse(url).getAll(overlay) // → [{ name: 'overlay', … }, …]has()
has(ref): boolean;Defined in: builder/cdn-url.ts:195
Whether a matching operation is present (name, object or creator ref).
Parameters
| Parameter | Type |
|---|---|
ref | OperationRef |
Returns
boolean
replace()
replace(operation): CdnUrl;Defined in: builder/cdn-url.ts:171
Replaces the first matching operation in place, or appends it. Matching follows operationMatches, so counted operations are swapped rather than duplicated (thumbs~5 → thumbs~3).
Only the first match is touched. For a stackable operation that legitimately repeats (overlay, text, …) use CdnUrl.replaceAll instead.
Parameters
| Parameter | Type |
|---|---|
operation | CdnOperation |
Returns
CdnUrl
Example
CdnUrl.parse(url).replace(resize({ width: 500 })).hrefreplaceAll()
replaceAll(operation): CdnUrl;Defined in: builder/cdn-url.ts:188
Collapses every matching operation into a single one, kept at the position of the first match; appends when nothing matches. The way to force a stackable operation to occur exactly once.
Parameters
| Parameter | Type |
|---|---|
operation | CdnOperation |
Returns
CdnUrl
Example
// two overlays in, one overlay out
CdnUrl.parse(url).replaceAll(overlay(uuid, { size: ['50p', '50p'] })).hreftoJSON()
toJSON(): ParsedCdnUrl;Defined in: builder/cdn-url.ts:135
The underlying ParsedCdnUrl, discriminated by kind.
Returns
toString()
toString(): string;Defined in: builder/cdn-url.ts:130
Alias of CdnUrl.href for string coercion.
Returns
string
updateOperations()
updateOperations(update): CdnUrl;Defined in: builder/cdn-url.ts:261
The primitive every other operation mutator is sugar over: rewrites the whole chain through a callback. Reach for it when position matters and CdnUrl.replace / CdnUrl.replaceAll do not fit — replacing the nth stackable operation, inserting at an index, reordering, or matching on parameters rather than name.
The callback receives a defensive copy, so mutating it in place is safe; whatever it returns becomes the new chain.
Parameters
| Parameter | Type |
|---|---|
update | (current) => readonly CdnOperation[] |
Returns
CdnUrl
Throws
TypeError on group root urls, which cannot carry operations.
See
https://uploadcare.com/docs/transformations/image/
Example
// replace the second overlay, leaving the others untouched
let seen = -1
url.updateOperations((ops) =>
ops.map((op) => (operationMatches(op, overlay) && ++seen === 1 ? next : op))
)with()
with(...operations): CdnUrl;Defined in: builder/cdn-url.ts:146
Appends operations to the chain.
Parameters
| Parameter | Type |
|---|---|
...operations | CdnOperation[] |
Returns
CdnUrl
Throws
TypeError on group root urls, which cannot carry operations.
without()
without(ref): CdnUrl;Defined in: builder/cdn-url.ts:154
Removes every occurrence of an operation. Accepts the operation name, an operation object, or the creator itself: url.without(resize).
Parameters
| Parameter | Type |
|---|---|
ref | OperationRef |
Returns
CdnUrl
parse()
static parse(url): CdnUrl;Defined in: builder/cdn-url.ts:107
Parses an existing CDN URL.
Parameters
| Parameter | Type |
|---|---|
url | string |
Returns
CdnUrl
Throws
TypeError when the URL cannot be interpreted as a CDN URL.