UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

24 lines 858 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ISO8601DateStruct = void 0; const superstruct_1 = require("@metamask/superstruct"); const luxon_1 = require("luxon"); /** * Regex to match the offset part of an ISO 8601 date. */ const offsetRegex = /Z|([+-]\d{2}:?\d{2})$/u; /** * Refines a string as an ISO 8601 date. */ exports.ISO8601DateStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'ISO 8601 date', (value) => { const parsedDate = luxon_1.DateTime.fromISO(value); if (!parsedDate.isValid) { return 'Not a valid ISO 8601 date'; } if (!offsetRegex.test(value)) { // Luxon doesn't have a reliable way to check if timezone info was not provided return 'ISO 8601 date must have timezone information'; } return true; }); //# sourceMappingURL=time.cjs.map