MCPcopy Create free account
hub / github.com/cryptii/cryptii / extractValues

Method extractValues

src/Form.js:263–284  ·  view source on GitHub ↗

* Extracts field values serialized by Form.serializeValues and * returns them as an object. * @param {mixed} data Serialized data * @throws {Error} If serialized data is not an object. * @throws {Error} If one of the field names is not assigned. * @return {object} Extracted na

(data)

Source from the content-addressed store, hash-verified

261 * @return {object} Extracted named values
262 */
263 extractValues (data) {
264 if (typeof data !== 'object') {
265 throw new Error(
266 'Serialized form values is expected to be an object mapping ' +
267 'field names to their respective serialized values. ' +
268 `Received value type '${typeof data}'.`)
269 }
270 const namedValues = {}
271 for (const name in data) {
272 if (typeof name !== 'string') {
273 throw new Error(
274 'Field name is expected to be a string. ' +
275 `Received type '${typeof name}'.`)
276 }
277 const field = this.getField(name)
278 if (field === null) {
279 throw new Error(`There is no field assigned to the name '${name}'.`)
280 }
281 namedValues[name] = field.extractValue(data[name])
282 }
283 return namedValues
284 }
285
286 /**
287 * Calculates the default priority for the next field to be added.

Callers 1

extractMethod · 0.95

Calls 2

getFieldMethod · 0.95
extractValueMethod · 0.45

Tested by

no test coverage detected