mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
30 lines
897 B
JavaScript
Executable File
30 lines
897 B
JavaScript
Executable File
import Utility from "../Utility"
|
|
import GeneralSerializer from "./GeneralSerializer"
|
|
|
|
/**
|
|
* @typedef {import("../entity/IEntity").AnyValue} AnyValue
|
|
* @typedef {import("../entity/IEntity").AnyValueConstructor<*>} AnyValueConstructor
|
|
*/
|
|
|
|
/**
|
|
* @template {AnyValue} T
|
|
* @extends {GeneralSerializer<T>}
|
|
*/
|
|
export default class ToStringSerializer extends GeneralSerializer {
|
|
|
|
/** @param {AnyValueConstructor} entityType */
|
|
constructor(entityType) {
|
|
super(undefined, entityType)
|
|
}
|
|
|
|
/**
|
|
* @param {T} object
|
|
* @param {Boolean} insideString
|
|
*/
|
|
write(entity, object, insideString) {
|
|
return !insideString && object.constructor === String
|
|
? `"${Utility.escapeString(object.toString())}"` // String will have quotes if not inside a string already
|
|
: Utility.escapeString(object.toString())
|
|
}
|
|
}
|