MCPcopy
hub / github.com/ampproject/amphtml / validateExactlyOne

Function validateExactlyOne

3p/3p.js:241–248  ·  view source on GitHub ↗

* Throws an exception if data does not contains exactly one field * mentioned in the alternativeFields array. * @param {!Object} data * @param {!Array } alternativeFields

(data, alternativeFields)

Source from the content-addressed store, hash-verified

239 * @param {!Array<string>} alternativeFields
240 */
241function validateExactlyOne(data, alternativeFields) {
242 userAssert(
243 alternativeFields.filter((field) => data[field]).length === 1,
244 '%s must contain exactly one of attributes: %s.',
245 data.type,
246 alternativeFields.join(', ')
247 );
248}
249
250/**
251 * Throws a non-interrupting exception if data contains a field not supported

Callers 1

validateDataFunction · 0.85

Calls 2

userAssertFunction · 0.90
filterMethod · 0.45

Tested by

no test coverage detected