// Preserves Values. import type { Bytes } from './bytes'; import type { DoubleFloat, SingleFloat } from './float'; import type { Annotated } from './annotated'; import type { Set, Dictionary } from './dictionary'; export type DefaultPointer = object; export type Value = | Atom | Compound | T | Annotated; export type Atom = | boolean | SingleFloat | DoubleFloat | number | string | Bytes | symbol; export type Compound = | (Array> | [Value]) & { label: Value } // ^ expanded from definition of Record<> in record.ts, // because if we use Record, Tuple>, T>, // TypeScript currently complains about circular use of Value, // and if we use Record, it accepts it but collapses // Value to any. | Array> | Set | Dictionary, T>; declare global { interface Object { asPreservesText(): string; } } Object.defineProperty(Object.prototype, 'asPreservesText', { enumerable: false, writable: true, value: function(): string { return '#!' + JSON.stringify(this); } }); Boolean.prototype.asPreservesText = function (): string { return this ? '#t' : '#f'; }; Number.prototype.asPreservesText = function (): string { return '' + this; }; String.prototype.asPreservesText = function (): string { return JSON.stringify(this); }; Symbol.prototype.asPreservesText = function (): string { // TODO: escaping return this.description ?? '||'; };