Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@sanity/asset-utils

Package Overview
Dependencies
Maintainers
98
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/asset-utils

<!-- This file is AUTO-GENERATED, edit _README.template.md or tweak scripts/generateDocs.ts -->

latest
Source
npmnpm
Version
2.3.0
Version published
Weekly downloads
258K
8.12%
Maintainers
98
Weekly downloads
 
Created

What is @sanity/asset-utils?

@sanity/asset-utils is a utility library for working with Sanity assets. It provides functions to build URLs for images and files stored in Sanity's content lake, as well as to extract metadata and perform other common tasks related to asset management.

What are @sanity/asset-utils's main functionalities?

Building Image URLs

This feature allows you to build URLs for images stored in Sanity. You need to provide the project ID, dataset, and the source object containing the asset ID.

const { buildImageUrl } = require('@sanity/asset-utils');
const imageUrl = buildImageUrl({ projectId: 'yourProjectId', dataset: 'yourDataset', source: { assetId: 'image-abc123-200x200-png' } });
console.log(imageUrl);

Extracting Metadata

This feature allows you to extract metadata from an asset ID. The metadata includes information such as the asset type, ID, extension, and dimensions.

const { getAsset } = require('@sanity/asset-utils');
const asset = getAsset('image-abc123-200x200-png');
console.log(asset);

Building File URLs

This feature allows you to build URLs for files stored in Sanity. Similar to building image URLs, you need to provide the project ID, dataset, and the source object containing the asset ID.

const { buildFileUrl } = require('@sanity/asset-utils');
const fileUrl = buildFileUrl({ projectId: 'yourProjectId', dataset: 'yourDataset', source: { assetId: 'file-abc123-pdf' } });
console.log(fileUrl);

Other packages similar to @sanity/asset-utils

Keywords

sanity

FAQs

Package last updated on 28 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts