Move text stuff to text.ts

This commit is contained in:
Tony Garnock-Jones 2021-03-04 22:42:40 +01:00
parent 5412f8b9d0
commit 4022b76650
2 changed files with 28 additions and 27 deletions

View File

@ -20,3 +20,31 @@ export function preserves(pieces: TemplateStringsArray, ...values: Value<any>[])
});
return result.join('');
}
declare global {
interface Object { asPreservesText(): string; }
}
Object.defineProperty(Object.prototype, 'asPreservesText', {
enumerable: false,
writable: true,
value: function(): string { return '#!' + 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 ?? '||';
};

View File

@ -30,30 +30,3 @@ export type Compound<T extends object = DefaultPointer> =
| Array<Value<T>>
| Set<T>
| Dictionary<Value<T>, 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 ?? '||';
};