wip(ssr): escape helpers

This commit is contained in:
Evan You
2020-01-26 17:35:21 -05:00
parent 4e40d0d7c8
commit 066ba82c7f
10 changed files with 81 additions and 23 deletions

View File

@@ -98,3 +98,12 @@ export const capitalize = cacheStringFunction(
// compare whether a value has changed, accounting for NaN.
export const hasChanged = (value: any, oldValue: any): boolean =>
value !== oldValue && (value === value || oldValue === oldValue)
// for converting {{ interpolation }} values to displayed strings.
export function toDisplayString(val: unknown): string {
return val == null
? ''
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
? JSON.stringify(val, null, 2)
: String(val)
}