@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
48 lines (46 loc) • 1.65 kB
JavaScript
import { PrismicError } from "../errors.js";
//#region src/lib/validateAssetMetadata.ts
/**
* Max length for asset notes accepted by the API.
*/
const ASSET_NOTES_MAX_LENGTH = 500;
/**
* Max length for asset credits accepted by the API.
*/
const ASSET_CREDITS_MAX_LENGTH = 500;
/**
* Max length for asset alt text accepted by the API.
*/
const ASSET_ALT_MAX_LENGTH = 500;
/**
* Min length for asset tags accepted by the API.
*/
const ASSET_TAG_MIN_LENGTH = 3;
/**
* Max length for asset tags accepted by the API.
*/
const ASSET_TAG_MAX_LENGTH = 20;
/**
* Validates an asset's metadata, throwing an error if any of the metadata are
* invalid.
*
* @param assetMetadata - The asset metadata to validate.
*
* @internal
*/
const validateAssetMetadata = ({ notes, credits, alt, tags }) => {
const errors = [];
if (notes && notes.length > ASSET_NOTES_MAX_LENGTH) errors.push(`\`notes\` must be at most ${ASSET_NOTES_MAX_LENGTH} characters`);
if (credits && credits.length > ASSET_CREDITS_MAX_LENGTH) errors.push(`\`credits\` must be at most ${ASSET_CREDITS_MAX_LENGTH} characters`);
if (alt && alt.length > ASSET_ALT_MAX_LENGTH) errors.push(`\`alt\` must be at most ${ASSET_ALT_MAX_LENGTH} characters`);
if (tags && tags.length && tags.some((tag) => tag.length < ASSET_TAG_MIN_LENGTH || tag.length > ASSET_TAG_MAX_LENGTH)) errors.push(`tags must be at least 3 characters long and 20 characters at most`);
if (errors.length) throw new PrismicError(`Errors validating asset metadata: ${errors.join(", ")}`, void 0, {
notes,
credits,
alt,
tags
});
};
//#endregion
export { validateAssetMetadata };
//# sourceMappingURL=validateAssetMetadata.js.map