UNPKG

better-auth

Version:

The most comprehensive authentication library for TypeScript.

24 lines (21 loc) 497 B
'use strict'; function safeJSONParse(data) { function reviver(_, value) { if (typeof value === "string") { const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/; if (iso8601Regex.test(value)) { const date = new Date(value); if (!isNaN(date.getTime())) { return date; } } } return value; } try { return JSON.parse(data, reviver); } catch { return null; } } exports.safeJSONParse = safeJSONParse;