MCPcopy Create free account
hub / github.com/ampproject/amphtml / parseLinkerParamValue

Function parseLinkerParamValue

extensions/amp-analytics/0.1/linker.js:64–88  ·  view source on GitHub ↗

* Parse the linker param value to version checksum and serializedParams * @param {string} value * @return {?Object}

(value)

Source from the content-addressed store, hash-verified

62 * @return {?Object}
63 */
64function parseLinkerParamValue(value) {
65 const parts = value.split(DELIMITER);
66 const isEven = parts.length % 2 == 0;
67
68 if (parts.length < 4 || !isEven) {
69 // Format <version>*<checksum>*<key1>*<value1>
70 // Note: linker makes sure there's at least one pair of non empty key value
71 // Make sure there is at least three delimiters.
72 user().error(TAG, `Invalid linker_param value ${value}`);
73 return null;
74 }
75
76 const version = Number(parts.shift());
77 if (version !== VALID_VERSION) {
78 user().error(TAG, `Invalid version number ${version}`);
79 return null;
80 }
81
82 const checksum = parts.shift();
83 const serializedIds = parts.join(DELIMITER);
84 return {
85 checksum,
86 serializedIds,
87 };
88}
89
90/**
91 * Check if the checksum is valid with time offset tolerance.

Callers 1

parseLinkerFunction · 0.70

Calls 2

userFunction · 0.90
errorMethod · 0.45

Tested by

no test coverage detected