Fieldset » entry

entry(name) → value or null
entry(name, options) → object/value or null
entry(name, loader) → value or null
entry(name, loader, options) → object/value or null

Retrieve an entry's value from the fieldset, optionally supplying a loader to validate and/or transform the value, and/or an options object.

enoQ&A:
Meaning = 42
Green = Yes
Purpose =
javascriptconst document = eno.parse(input);
const qa = document.fieldset('Q&A');

qa.entry('Meaning');   // returns '42'
qa.entry('Purpose');   // returns null

qa.entry('Purpose', { required: true });   // throws an error
qa.entry('Purpose', { enforceElement: true });   // returns null
qa.entry('Beige', { enforceElement: true });   // throws an error

qa.entry('Green', ({ value }) => value.toUpperCase());   // returns 'YES'

qa.entry('Meaning', ({ value }) => {   // throws an error
  if(value === '42') {
    throw "That one's getting old!";
  }
  return value;
});

qa.entry('Meaning', { withElement: true });
  // returns { element: [object Field name="Meaning" value="42"], value: '42' }

Parameters

name

The name of the entry as a string.

loader

A function returning the transformed/validated value or throwing an error.The function is passed name and value inside a single object parameter.

options

enforceElement

Whether the entry must be present in the document (true or false, defaults to false)

enforceValue

Whether there must be a value or the entry is allowed to be empty (default to false)

required

Alias for enforceValue (this exists on many methods and depending on context refers to either element or value)

withElement

Whether to return an array with both the element and the value (defaults to false)

Return value

The entry's value, or null if empty.