MCPcopy Index your code
hub / github.com/ampproject/amphtml / parseFragment

Function parseFragment

3p/integration-lib.js:306–319  ·  view source on GitHub ↗
(fragment)

Source from the content-addressed store, hash-verified

304 * @visibleForTesting
305 */
306export function parseFragment(fragment) {
307 try {
308 let json = fragment.substr(1);
309 // Some browser, notably Firefox produce an encoded version of the fragment
310 // while most don't. Since we know how the string should start, this is easy
311 // to detect.
312 if (json.startsWith('{%22')) {
313 json = decodeURIComponent(json);
314 }
315 return /** @type {!JsonObject} */ (json ? parseJson(json) : {});
316 } catch (err) {
317 return null;
318 }
319}
320
321/**
322 * Not all types of embeds are allowed to be used with all tag names on the

Callers 1

Calls 1

parseJsonFunction · 0.90

Tested by

no test coverage detected