UNPKG

libmodulor

Version:

A TypeScript library to create platform-agnostic applications

29 lines (28 loc) 628 B
import { TString } from '../base/TString.js'; export class TJSONString extends TString { tName() { return 'JSONString'; } example() { return '{"key": "value"}'; } isPotentiallyLong() { return true; } validate() { const validation = super.validate(); if (!validation.isOK()) { return validation; } try { JSON.parse(this.raw); } catch (_err) { validation.add({ constraint: 'format', expected: 'JSON', }); } return validation; } }