UNPKG

tupleson

Version:

A hackable JSON serializer/deserializer

13 lines (11 loc) 363 B
import { TsonType } from "../syncTypes.js"; export const tsonRegExp: TsonType<RegExp, string> = { deserialize: (str) => { const body = str.slice(1, str.lastIndexOf("/")); const flags = str.slice(str.lastIndexOf("/") + 1); return new RegExp(body, flags); }, key: "RegExp", serialize: (value) => "" + value, test: (value) => value instanceof RegExp, };