Section » lookup
lookup(index) → object or null
lookup(line, column) → object or null
Ask the document Hey what's at column X in line Y in my eno file?. The lookup always returns an element for valid indices
(the document/section in case of an empty line/space), only indices outside the range of the document return null
. Note that
all arguments are zero-indexed, i.e. the first lines and columns are numbered 0
, not 1
.
enocolor: blue
# notes
javascriptconst document = eno.parse(input);
document.lookup(3); // 'o'
// returns { element: [object Field name="color" value="blue"], zone: 'name' }
document.lookup(7); // 'b'
// returns { element: [object Field name="color" value="blue"], zone: 'value' }
document.lookup(0, 3); // 'o'
// returns { element: [object Field name="color" value="blue"], zone: 'name' }
document.lookup(0, 7); // 'b'
// returns { element: [object Field name="color" value="blue"], zone: 'value' }
document.lookup(13); // '#'
// returns { element: [object Section name="notes" elements=0], zone: 'sectionOperator' }
document.lookup(19); // 's'
// returns { element: [object Section name="notes" elements=0], zone: 'name' }
document.lookup(2, 0); // '#'
// returns { element: [object Section name="notes" elements=0], zone: 'sectionOperator' }
document.lookup(2, 6); // 's'
// returns { element: [object Section name="notes" elements=0], zone: 'name' }
Parameters
indexA one-dimensional index to look up (0-indexed, i.e. the first position is 0, not 1)- only applies when it's the only given argument.
lineThe line to look up (0-indexed, i.e. the first line is 0, not 1) - only applies when you supply a column
as well.
The column to look up (0-indexed, i.e. the first column is 0, not 1) - only applies when you supply a line
as well.
Return value
For all valid indices within the document returns an object with two properties:
zone
: A string denoting the token at the index, here's the full list:
'[empty-lines-and-spaces-between-tokens]'
=> element
'[inside-blocks]'
=> content
'[inside-comments]'
=> comment
'[name]'
=> name
'[template]'
=> value
'[value]'
=> value
':'
=> nameOperator
'-'
=> itemOperator
'='
=> entryOperator
'--'
=> blockOperator
'>'
=> commentOperator
'`'
=> escapeBeginOperator
'`'
=> escapeEndOperator
'|'
=> newlineContinuationOperator
'\'
=> lineContinuationOperator
'#'
=> sectionOperator
'<'
=> copyOperator
'<<'
=> deepCopyOperator
element
: An Section
, Fieldset
, Field
.. . For empty lines you get the containing section.
When an index outside the document is supplied, null
is returned.