MCPcopy Create free account
hub / github.com/angular/angular / toJson

Method toJson

packages/core/src/transfer_state.ts:141–157  ·  view source on GitHub ↗

* Serialize the current state of the store to JSON.

()

Source from the content-addressed store, hash-verified

139 * Serialize the current state of the store to JSON.
140 */
141 toJson(): string {
142 // Call the onSerialize callbacks and put those values into the store.
143 for (const key in this.onSerializeCallbacks) {
144 if (Object.hasOwn(this.onSerializeCallbacks, key)) {
145 try {
146 this.store[key] = this.onSerializeCallbacks[key]();
147 } catch (e) {
148 console.warn('Exception in onSerialize callback: ', e);
149 }
150 }
151 }
152
153 // Escape script tag to avoid break out of <script> tag in serialized output.
154 // Encoding of `<` is the same behaviour as G3 script_builders.
155 // Encoding of `/` prevents crawlers from incorrectly indexing relative URLs in inline JSON.
156 return JSON.stringify(this.store).replace(/</g, '\\u003C').replace(/\//g, '\\u002F');
157 }
158}
159
160export function retrieveTransferredState(

Callers 4

serializeTransferStateFunction · 0.45

Calls 2

warnMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected