2022-01-26 13:15:35 +00:00
|
|
|
import type { GenericEmbedded } from './embedded';
|
2021-03-12 19:41:35 +00:00
|
|
|
import type { Value } from './values';
|
2021-01-07 16:41:46 +00:00
|
|
|
|
2022-01-26 13:15:35 +00:00
|
|
|
import { Annotated } from './annotated';
|
|
|
|
import { Bytes } from './bytes';
|
|
|
|
import { KeyedDictionary, KeyedSet } from './dictionary';
|
|
|
|
import { Writer, Writable, WriterOptions } from './writer';
|
|
|
|
|
|
|
|
export function stringify<T = GenericEmbedded>(x: any, options?: WriterOptions<T>): string {
|
|
|
|
return Writer.stringify(x as Writable<T>, options);
|
2021-01-07 16:41:46 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 19:59:52 +00:00
|
|
|
export function preserves<T>(pieces: TemplateStringsArray, ...values: Value<T>[]): string {
|
2021-01-07 16:41:46 +00:00
|
|
|
const result = [pieces[0]];
|
|
|
|
values.forEach((v, i) => {
|
|
|
|
result.push(stringify(v));
|
|
|
|
result.push(pieces[i + 1]);
|
|
|
|
});
|
|
|
|
return result.join('');
|
|
|
|
}
|
2021-03-04 21:42:40 +00:00
|
|
|
|
2022-01-26 13:15:35 +00:00
|
|
|
[Annotated, Bytes, KeyedDictionary, KeyedSet].forEach((C) => {
|
|
|
|
C.prototype.toString = function () { return stringify(this); };
|
2021-03-04 21:42:40 +00:00
|
|
|
});
|