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