Move text stuff to text.ts
This commit is contained in:
parent
5412f8b9d0
commit
4022b76650
|
@ -20,3 +20,31 @@ export function preserves(pieces: TemplateStringsArray, ...values: Value<any>[])
|
||||||
});
|
});
|
||||||
return result.join('');
|
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 ?? '||';
|
||||||
|
};
|
||||||
|
|
|
@ -30,30 +30,3 @@ export type Compound<T extends object = DefaultPointer> =
|
||||||
| Array<Value<T>>
|
| Array<Value<T>>
|
||||||
| Set<T>
|
| Set<T>
|
||||||
| Dictionary<Value<T>, 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 ?? '||';
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue