@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
17 lines • 594 B
JavaScript
import { refine, string, type, assert as assertSuperstruct, StructError } from "@metamask/superstruct";
import { getErrorMessage } from "./errors.mjs";
export const uri = (opts = {}) => refine(string(), 'uri', (value) => {
try {
const url = new URL(value);
const UrlStruct = type(opts);
assertSuperstruct(url, UrlStruct);
return true;
}
catch (error) {
if (error instanceof StructError) {
return getErrorMessage(error);
}
return `Expected URL, got "${value.toString()}"`;
}
});
//# sourceMappingURL=uri.mjs.map