( serializable: gdSerializable, methodName: string = 'serializeTo', options: ?SerializationOptions = undefined )
| 142 | * @param {*} options Optional serialization options (e.g. canonical mode) |
| 143 | */ |
| 144 | export function serializeToJSON( |
| 145 | serializable: gdSerializable, |
| 146 | methodName: string = 'serializeTo', |
| 147 | options: ?SerializationOptions = undefined |
| 148 | ): string { |
| 149 | return withSerializationOptions(options, () => { |
| 150 | const serializedElement = new gd.SerializerElement(); |
| 151 | serializable[methodName](serializedElement); |
| 152 | |
| 153 | // toJSON is 20% faster than gd.Serializer.toJSObject + JSON.stringify. |
| 154 | const json = gd.Serializer.toJSON(serializedElement); |
| 155 | serializedElement.delete(); |
| 156 | |
| 157 | return json; |
| 158 | }); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * POSIX / editor convention: text files end with a newline. Use when persisting `.json`. |
no test coverage detected