<!-- This file is AUTO-GENERATED, edit _README.template.md or tweak scripts/generateDocs.ts -->
npm install @sanity/asset-utilsReusable utility functions for dealing with image and file assets in Sanity.
> [!IMPORTANT]
> This package does _not_ resolve any information from the Sanity APIs - it does no asynchronous operations and only has the information that you pass it. You cannot, for instance, get the LQIP, BlurHash, image palette and similar information without requesting it from the Sanity API.
``sh`
$ npm install @sanity/asset-utils
`js
// ESM / TypeScript
import {someUtilityFunction} from '@sanity/asset-utils'
// CommonJS
const {someUtilityFunction} = require('@sanity/asset-utils')
`
An HTML version is also available, which also includes interface definitions, constants and more.
- buildFilePath
- buildFileUrl
- buildImagePath
- buildImageUrl
- getAssetDocumentId
- getAssetUrlType
- getDefaultCrop
- getDefaultHotspot
- getExtension
- getFile
- getFileAsset
- getIdFromString
- getImage
- getImageAsset
- getImageDimensions
- getProject
- getUrlFilename
- getUrlPath
- getVanityStub
- isAssetFilename
- isAssetId
- isAssetIdStub
- isAssetObjectStub
- isAssetPathStub
- isAssetUrlStub
- isDefaultCrop
- isDefaultHotspot
- isFileAssetFilename
- isFileAssetId
- isFileSource
- isImageAssetFilename
- isImageAssetId
- isImageSource
- isInProgressUpload
- isReference
- isSanityAssetUrl
- isSanityFileAsset
- isSanityFileUrl
- isSanityImageAsset
- isSanityImageUrl
- isUnresolvableError
- isValidFilename
- parseAssetFilename
- parseAssetId
- parseAssetUrl
- parseFileAssetId
- parseFileAssetUrl
- parseImageAssetId
- parseImageAssetUrl
- tryGetAssetDocumentId
- tryGetAssetPath
- tryGetExtension
- tryGetFile
- tryGetFileAsset
- tryGetIdFromString
- tryGetImage
- tryGetImageAsset
- tryGetImageDimensions
- tryGetProject
- tryGetUrlFilename
- tryGetUrlPath
▸ buildFilePath(asset: SanityFileUrlParts | FileUrlBuilderOptions, options?: PathBuilderOptions): _string_
Builds the base file path from the minimal set of parts required to assemble it
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| asset | SanityFileUrlParts \| FileUrlBuilderOptions | An asset-like shape defining ID, dimensions and extension |options
| | PathBuilderOptions | (_Optional_) Project ID and dataset the file belongs to, along with other options |
Returns: _string_
_Defined in src/paths.ts:77_
▸ buildFileUrl(asset: FileUrlBuilderOptions, options?: PathBuilderOptions): _string_
Builds the base file URL from the minimal set of parts required to assemble it
| Name | Type | Description |
| --------- | ------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- |
| asset | FileUrlBuilderOptions | An asset-like shape defining ID and extension |options
| | PathBuilderOptions | (_Optional_) Project ID and dataset the file belongs to, along with other options |
Returns: _string_
_Defined in src/paths.ts:102_
▸ buildImagePath(asset: SanityImageUrlParts | ImageUrlBuilderOptions, options?: PathBuilderOptions): _string_
Builds the base image path from the minimal set of parts required to assemble it
| Name | Type | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| asset | SanityImageUrlParts \| ImageUrlBuilderOptions | An asset-like shape defining ID, dimensions and extension |options
| | PathBuilderOptions | (_Optional_) Project ID and dataset the image belongs to, along with other options |
Returns: _string_
_Defined in src/paths.ts:33_
▸ buildImageUrl(asset: SanityImageUrlParts | ImageUrlBuilderOptions, options?: PathBuilderOptions): _string_
Builds the base image URL from the minimal set of parts required to assemble it
| Name | Type | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| asset | SanityImageUrlParts \| ImageUrlBuilderOptions | An asset-like shape defining ID, dimensions and extension |options
| | PathBuilderOptions | (_Optional_) Project ID and dataset the image belongs to |
Returns: _string_
_Defined in src/paths.ts:61_
▸ getAssetDocumentId(src: unknown): _string_
Tries to resolve the asset document ID from any inferrable structure
| Name | Type | Description |
| ----- | ------- | ----------------------------------------------------------------- |
| src | unknown | Input source (image/file object, asset, reference, id, url, path) |
Returns: _string_
_Defined in src/resolve.ts:331_
▸ getAssetUrlType(url: string): _"image" | "file" | false_
Validates that a given URL is a Sanity asset URL, and returns the asset type if valid.
| Name | Type | Description |
| ----- | ------ | ------------------------------ |
| url | string | URL to extract asset type from |
Returns: _"image" | "file" | false_
_Defined in src/parse.ts:183_
▸ getDefaultCrop(): _SanityImageCrop_
Returns cloned version of the default crop (prevents accidental mutations)
Returns: _SanityImageCrop_
_Defined in src/hotspotCrop.ts:33_
▸ getDefaultHotspot(): _SanityImageHotspot_
Returns cloned version of the default hotspot (prevents accidental mutations)
Returns: _SanityImageHotspot_
_Defined in src/hotspotCrop.ts:41_
▸ getExtension(src: SanityAssetSource): _string_
Returns the file extension for a given asset
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| src | SanityAssetSource | Input source (file/image object, asset, reference, id, url, path) |
Returns: _string_
_Defined in src/resolve.ts:93_
▸ getFile(src: SanityFileSource, project?: SanityProjectDetails): _ResolvedSanityFile_
Tries to resolve an file object with as much information as possible, from any inferrable structure (id, url, path, file object etc)
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| src | SanityFileSource | Input source (file object, asset, reference, id, url, path) |project
| | SanityProjectDetails | (_Optional_) Project ID and dataset the file belongs to |
Returns: _ResolvedSanityFile_
_Defined in src/resolve.ts:233_
▸ getFileAsset(src: SanityFileSource, options?: PathBuilderOptions): _SanityFileAsset_
Tries to resolve a (partial) file asset document with as much information as possible, from any inferrable structure (id, url, path, file object etc)
| Name | Type | Description |
| --------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- |
| src | SanityFileSource | Input source (file object, asset, reference, id, url, path) |options
| | PathBuilderOptions | (_Optional_) Project ID and dataset the file belongs to, along with other options |
Returns: _SanityFileAsset_
_Defined in src/resolve.ts:274_
▸ getIdFromString(str: string): _string_
Tries to cooerce a string (ID, URL or path) to an image asset ID
| Name | Type | Description |
| ----- | ------ | ------------------------------ |
| str | string | Input string (ID, URL or path) |
Returns: _string_
_Defined in src/resolve.ts:380_
▸ getImage(src: SanityImageSource, project?: SanityProjectDetails): _ResolvedSanityImage_
Tries to resolve an image object with as much information as possible, from any inferrable structure (id, url, path, image object etc)
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| src | SanityImageSource | Input source (image object, asset, reference, id, url, path) |project
| | SanityProjectDetails | (_Optional_) Project ID and dataset the image belongs to |
Returns: _ResolvedSanityImage_
_Defined in src/resolve.ts:124_
▸ getImageAsset(src: SanityImageSource, project?: SanityProjectDetails): _SanityImageAsset_
Tries to resolve a (partial) image asset document with as much information as possible, from any inferrable structure (id, url, path, image object etc)
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| src | SanityImageSource | Input source (image object, asset, reference, id, url, path) |project
| | SanityProjectDetails | (_Optional_) Project ID and dataset the image belongs to |
Returns: _SanityImageAsset_
_Defined in src/resolve.ts:178_
▸ getImageDimensions(src: SanityImageSource): _SanityImageDimensions_
Returns the width, height and aspect ratio of a passed image asset, from any inferrable structure (id, url, path, asset document, image object etc)
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| src | SanityImageSource | Input source (image object, asset, reference, id, url, path) |
Returns: _SanityImageDimensions_
_Defined in src/resolve.ts:63_
▸ getProject(src: SanityImageSource): _SanityProjectDetails_
Resolves project ID and dataset the image belongs to, based on full URL or path
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | ----------------- |
| src | SanityImageSource | Image URL or path |
Returns: _SanityProjectDetails_
_Defined in src/resolve.ts:442_
▸ getUrlFilename(url: string): _string_
Strips the CDN URL, path and query params from a URL, eg: https://cdn.sanity.io/images/project/dataset/filename-200x200.jpg?foo=bar → filename-200x200.jpg
| Name | Type | Description |
| ----- | ------ | ------------------------ |
| url | string | URL to get filename from |
Returns: _string_
_Defined in src/paths.ts:189_
▸ getUrlPath(url: string): _string_
Strips the CDN URL and query params from a URL, eg: https://cdn.sanity.io/images/project/dataset/filename-200x200.jpg?foo=bar → images/project/dataset/filename-200x200.jpg
| Name | Type | Description |
| ----- | ------ | ------------------------- |
| url | string | URL to get path name from |
Returns: _string_
_Defined in src/paths.ts:159_
▸ getVanityStub(originalFilename: string | undefined, vanityFilename: string | undefined, options?: PathBuilderOptions): _string_
Get the "path stub" at the end of the path, if the user hasn't explicitly opted out of this behavior
| Name | Type | Description |
| ------------------ | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
| originalFilename | string \| undefined | The original filename of the asset |vanityFilename
| | string \| undefined | The vanity filename of the asset |options
| | PathBuilderOptions | (_Optional_) Options to control the behavior of the path builder |
Returns: _string_
_Defined in src/paths.ts:226_
▸ isAssetFilename(filename: string): _boolean_
Returns whether or not the passed filename is a valid file or image asset filename
| Name | Type | Description |
| ---------- | ------ | -------------------- |
| filename | string | Filename to validate |
Returns: _boolean_
_Defined in src/resolve.ts:492_
▸ isAssetId(documentId: string): _boolean_
Checks whether or not the given document ID is a valid Sanity asset document ID (file or image)
| Name | Type | Description |
| ------------ | ------ | -------------------- |
| documentId | string | Document ID to check |
Returns: _boolean_
_Defined in src/asserters.ts:121_
▸ isAssetIdStub(stub: unknown): _stub is SanityAssetIdStub_
Checks whether or not the given source is an asset ID stub (an object containing an _id property)
| Name | Type | Description |
| ------ | ------- | ---------------------- |
| stub | unknown | Possible asset id stub |
Returns: _stub is SanityAssetIdStub_
_Defined in src/asserters.ts:40_
▸ isAssetObjectStub(stub: unknown): _stub is SanityAssetObjectStub_
Checks whether or not the given source is an asset object stub
| Name | Type | Description |
| ------ | ------- | -------------------------- |
| stub | unknown | Possible asset object stub |
Returns: _stub is SanityAssetObjectStub_
_Defined in src/asserters.ts:132_
▸ isAssetPathStub(stub: unknown): _stub is SanityAssetPathStub_
Checks whether or not the given source is an asset path stub (an object containing a path property)
| Name | Type | Description |
| ------ | ------- | ------------------------ |
| stub | unknown | Possible asset path stub |
Returns: _stub is SanityAssetPathStub_
_Defined in src/asserters.ts:52_
▸ isAssetUrlStub(stub: unknown): _stub is SanityAssetUrlStub_
Checks whether or not the given source is an asset URL stub (an object containing a url property)
| Name | Type | Description |
| ------ | ------- | ----------------------- |
| stub | unknown | Possible asset url stub |
Returns: _stub is SanityAssetUrlStub_
_Defined in src/asserters.ts:64_
▸ isDefaultCrop(crop: SanityImageCrop): _boolean_
Returns whether or not the passed crop has the default values for a crop region
| Name | Type | Description |
| ------ | ------------------------------------------------------------------------------------------ | ----------------------------------------------------- |
| crop | SanityImageCrop | The crop to return whether or not is the default crop |
Returns: _boolean_
_Defined in src/hotspotCrop.ts:50_
▸ isDefaultHotspot(hotspot: SanityImageHotspot): _boolean_
Returns whether or not the passed hotspot has the default values for a hotspot region
| Name | Type | Description |
| --------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
| hotspot | SanityImageHotspot | The hotspot to return whether or not is the default hotspot |
Returns: _boolean_
_Defined in src/hotspotCrop.ts:71_
▸ isFileAssetFilename(filename: string): _boolean_
Returns whether or not the passed filename is a valid file asset filename
| Name | Type | Description |
| ---------- | ------ | -------------------- |
| filename | string | Filename to validate |
Returns: _boolean_
_Defined in src/resolve.ts:481_
▸ isFileAssetId(documentId: string): _boolean_
Checks whether or not the given document ID is a valid Sanity file asset document ID
| Name | Type | Description |
| ------------ | ------ | -------------------- |
| documentId | string | Document ID to check |
Returns: _boolean_
_Defined in src/asserters.ts:110_
▸ isFileSource(src: unknown): _src is SanityFileSource_
Return whether or not the passed source is a file source
| Name | Type | Description |
| ----- | ------- | --------------- |
| src | unknown | Source to check |
Returns: _src is SanityFileSource_
_Defined in src/resolve.ts:503_
▸ isImageAssetFilename(filename: string): _boolean_
Returns whether or not the passed filename is a valid image asset filename
| Name | Type | Description |
| ---------- | ------ | -------------------- |
| filename | string | Filename to validate |
Returns: _boolean_
_Defined in src/resolve.ts:470_
▸ isImageAssetId(documentId: string): _boolean_
Checks whether or not the given document ID is a valid Sanity image asset document ID
| Name | Type | Description |
| ------------ | ------ | -------------------- |
| documentId | string | Document ID to check |
Returns: _boolean_
_Defined in src/asserters.ts:99_
▸ isImageSource(src: unknown): _src is SanityImageSource_
Return whether or not the passed source is an image source
| Name | Type | Description |
| ----- | ------- | --------------- |
| src | unknown | Source to check |
Returns: _src is SanityImageSource_
_Defined in src/resolve.ts:515_
▸ isInProgressUpload(stub: unknown): _stub is SanityFileUploadStub | SanityImageUploadStub_
Checks whether or not the given source is an in-progress upload (has upload property but no asset property)
| Name | Type | Description |
| ------ | ------- | --------------------------- |
| stub | unknown | Possible in-progress upload |
Returns: _stub is SanityFileUploadStub | SanityImageUploadStub_
_Defined in src/asserters.ts:145_
▸ isReference(ref: unknown): _ref is SanityReference_
Checks whether or not the given source is a Sanity reference (an object containing \_ref string key)
| Name | Type | Description |
| ----- | ------- | ------------------ |
| ref | unknown | Possible reference |
Returns: _ref is SanityReference_
_Defined in src/asserters.ts:28_
▸ isSanityAssetUrl(url: string): _boolean_
Checks whether or not a given URL is a valid Sanity asset URL
| Name | Type | Description |
| ----- | ------ | ----------- |
| url | string | URL to test |
Returns: _boolean_
_Defined in src/urls.ts:10_
▸ isSanityFileAsset(src: unknown): _src is SanityFileAsset_
Checks whether or not the given source is a (partial) sanity file asset document. Only checks the _type property, all other properties _may_ be missing
| Name | Type | Description |
| ----- | ------- | --------------- |
| src | unknown | Source to check |
Returns: _src is SanityFileAsset_
_Defined in src/asserters.ts:76_
▸ isSanityFileUrl(url: string): _boolean_
Checks whether or not a given URL is a valid Sanity file asset URL
| Name | Type | Description |
| ----- | ------ | ----------- |
| url | string | URL to test |
Returns: _boolean_
_Defined in src/urls.ts:32_
▸ isSanityImageAsset(src: unknown): _src is SanityImageAsset_
Checks whether or not the given source is a (partial) sanity image asset document. Only checks the _type property, all other properties _may_ be missing
| Name | Type | Description |
| ----- | ------- | --------------- |
| src | unknown | Source to check |
Returns: _src is SanityImageAsset_
_Defined in src/asserters.ts:88_
▸ isSanityImageUrl(url: string): _boolean_
Checks whether or not a given URL is a valid Sanity image asset URL
| Name | Type | Description |
| ----- | ------ | ----------- |
| url | string | URL to test |
Returns: _boolean_
_Defined in src/urls.ts:21_
▸ isUnresolvableError(err: unknown): _err is UnresolvableError_
Checks whether or not an error instance is of type UnresolvableError
| Name | Type | Description |
| ----- | ------- | ------------------------------------------ |
| err | unknown | Error to check for unresolvable error type |
Returns: _err is UnresolvableError_
_Defined in src/errors.ts:29_
▸ isValidFilename(filename: string): _boolean_
Checks whether or not a given filename matches the expected Sanity asset filename pattern
| Name | Type | Description |
| ---------- | ------ | ------------------------------ |
| filename | string | Filename to check for validity |
Returns: _boolean_
_Defined in src/paths.ts:213_
▸ parseAssetFilename(filename: string): _SanityAssetIdParts_
Parses a Sanity asset filename into individual parts (type, id, extension, width, height)
| Name | Type | Description |
| ---------- | ------ | ---------------------------------- |
| filename | string | Filename to parse into named parts |
Returns: _SanityAssetIdParts_
_Defined in src/parse.ts:94_
▸ parseAssetId(documentId: string): _SanityAssetIdParts_
Parses a Sanity asset document ID into individual parts (type, id, extension, width/height etc)
| Name | Type | Description |
| ------------ | ------ | ------------------------------------- |
| documentId | string | Document ID to parse into named parts |
Returns: _SanityAssetIdParts_
_Defined in src/parse.ts:36_
▸ parseAssetUrl(url: string): _SanityAssetUrlParts_
Parses a full Sanity asset URL into individual parts (type, project ID, dataset, id, extension, width, height)
| Name | Type | Description |
| ----- | ------ | ---------------------------------- |
| url | string | Full URL to parse into named parts |
Returns: _SanityAssetUrlParts_
_Defined in src/parse.ts:118_
▸ parseFileAssetId(documentId: string): _SanityFileAssetIdParts_
Parses a Sanity file asset document ID into individual parts (type, id, extension)
| Name | Type | Description |
| ------------ | ------ | ------------------------------------------------ |
| documentId | string | File asset document ID to parse into named parts |
Returns: _SanityFileAssetIdParts_
_Defined in src/parse.ts:56_
▸ parseFileAssetUrl(url: string): _SanityFileUrlParts_
Parses a full Sanity file asset URL into individual parts (type, project ID, dataset, id, extension, width, height)
| Name | Type | Description |
| ----- | ------ | ---------------------------------- |
| url | string | Full URL to parse into named parts |
Returns: _SanityFileUrlParts_
_Defined in src/parse.ts:167_
▸ parseImageAssetId(documentId: string): _SanityImageAssetIdParts_
Parses a Sanity image asset document ID into individual parts (type, id, extension, width, height)
| Name | Type | Description |
| ------------ | ------ | ------------------------------------------------- |
| documentId | string | Image asset document ID to parse into named parts |
Returns: _SanityImageAssetIdParts_
_Defined in src/parse.ts:75_
▸ parseImageAssetUrl(url: string): _SanityImageUrlParts_
Parses a full Sanity image asset URL into individual parts (type, project ID, dataset, id, extension, width, height)
| Name | Type | Description |
| ----- | ------ | ---------------------------------- |
| url | string | Full URL to parse into named parts |
Returns: _SanityImageUrlParts_
_Defined in src/parse.ts:149_
▸ tryGetAssetDocumentId(src: unknown): _string | undefined_
Tries to resolve the asset document ID from any inferrable structure
| Name | Type | Description |
| ----- | ------- | ----------------------------------------------------------------- |
| src | unknown | Input source (image/file object, asset, reference, id, url, path) |
Returns: _string | undefined_
_Defined in src/resolve.ts:367_
▸ tryGetAssetPath(src: SanityAssetSource): _string | undefined_
Tries to get the asset path from a given asset source
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | -------------------------------------------- |
| src | SanityAssetSource | The source image to infer an asset path from |
Returns: _string | undefined_
_Defined in src/paths.ts:125_
▸ tryGetExtension(src: SanityAssetSource): _string | undefined_
Returns the file extension for a given asset
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| src | SanityAssetSource | Input source (file/image object, asset, reference, id, url, path) |
Returns: _string | undefined_
_Defined in src/resolve.ts:110_
▸ tryGetFile(src: SanityFileSource, project?: SanityProjectDetails): _ResolvedSanityFile | undefined_
Tries to resolve an file object with as much information as possible, from any inferrable structure (id, url, path, file object etc)
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| src | SanityFileSource | Input source (file object, asset, reference, id, url, path) |project
| | SanityProjectDetails | (_Optional_) Project ID and dataset the file belongs to |
Returns: _ResolvedSanityFile | undefined_
_Defined in src/resolve.ts:260_
▸ tryGetFileAsset(src: SanityFileSource, options?: PathBuilderOptions): _SanityFileAsset | undefined_
Tries to resolve a (partial) file asset document with as much information as possible, from any inferrable structure (id, url, path, file object etc)
| Name | Type | Description |
| --------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- |
| src | SanityFileSource | Input source (file object, asset, reference, id, url, path) |options
| | PathBuilderOptions | (_Optional_) Project ID and dataset the file belongs to, along with other options |
Returns: _SanityFileAsset | undefined_
_Defined in src/resolve.ts:319_
▸ tryGetIdFromString(str: string): _string | undefined_
Tries to cooerce a string (ID, URL or path) to an image asset ID
| Name | Type | Description |
| ----- | ------ | ------------------------------ |
| str | string | Input string (ID, URL or path) |
Returns: _string | undefined_
_Defined in src/resolve.ts:417_
▸ tryGetImage(src: SanityImageSource, project?: SanityProjectDetails): _ResolvedSanityImage | undefined_
Tries to resolve an image object with as much information as possible, from any inferrable structure (id, url, path, image object etc)
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| src | SanityImageSource | Input source (image object, asset, reference, id, url, path) |project
| | SanityProjectDetails | (_Optional_) Project ID and dataset the image belongs to |
Returns: _ResolvedSanityImage | undefined_
_Defined in src/resolve.ts:164_
▸ tryGetImageAsset(src: SanityImageSource, project?: SanityProjectDetails): _SanityImageAsset | undefined_
Tries to resolve a (partial) image asset document with as much information as possible, from any inferrable structure (id, url, path, image object etc)
| Name | Type | Description |
| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| src | SanityImageSource | Input source (image object, asset, reference, id, url, path) |project
| | SanityProjectDetails | (_Optional_) Project ID and dataset the image belongs to |
Returns: _SanityImageAsset | undefined_
_Defined in src/resolve.ts:219_
▸ tryGetImageDimensions(src: SanityImageSource): _SanityImageDimensions | undefined_
Returns the width, height and aspect ratio of a passed image asset, from any inferrable structure (id, url, path, asset document, image object etc)
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| src | SanityImageSource | Input source (image object, asset, reference, id, url, path) |
Returns: _SanityImageDimensions | undefined_
_Defined in src/resolve.ts:81_
▸ tryGetProject(src: SanityImageSource): _SanityProjectDetails | undefined_
Resolves project ID and dataset the image belongs to, based on full URL or path
| Name | Type | Description |
| ----- | ----------------------------------------------------------------------------------------- | ----------------- |
| src | SanityImageSource | Image URL or path |
Returns: _SanityProjectDetails | undefined_
_Defined in src/resolve.ts:461_
▸ tryGetUrlFilename(url: string): _string | undefined_
Strips the CDN URL, path and query params from a URL, eg: https://cdn.sanity.io/images/project/dataset/filename-200x200.jpg?foo=bar → filename-200x200.jpg
| Name | Type | Description |
| ----- | ------ | ------------------------ |
| url | string | URL to get filename from |
Returns: _string | undefined_
_Defined in src/paths.ts:204_
▸ tryGetUrlPath(url: string): _string | undefined_
Strips the CDN URL and query params from a URL, eg: https://cdn.sanity.io/images/project/dataset/filename-200x200.jpg?foo=bar → images/project/dataset/filename-200x200.jpg
| Name | Type | Description |
| ----- | ------ | ------------------------- |
| url` | string | URL to get path name from |
Returns: _string | undefined_
_Defined in src/paths.ts:177_
MIT-licensed. See LICENSE.