src/utils/mappers.coffee |
|
|---|---|
Mappers are functions that extract or perform transformations on data
when used in combination with the Table Of ContentA mapper is a function that takes the element to map as argument. The function is generated through currying.
|
|
at |
|
Returns the value at the specified index in the element.
Optionally the
|
at = (index=0, mapper) -> (el) -> return undefined unless el? if mapper? then mapper el[index] else el[index] |
first |
|
Returns the first value in the element.
Optionally the
|
first = (mapper) -> (el) -> return undefined unless el? if mapper? then mapper el.first?() else el.first?() |
last |
|
Returns the last value in the element.
Optionally the
|
last = (mapper) -> (el) -> return undefined unless el? if mapper? then mapper el.last?() else el.last?() |
length |
|
Returns the length of the element if this element provides either
a property or a function named
|
length = -> (el) -> return undefined unless el? if typeof el.length is 'function' then el.length() else el.length |
property |
|
Returns the value of the property named
Optionally the
|
property = (key, mapper) -> (el) -> return undefined unless el? if mapper? then mapper el[key] else el[key] module.exports = { at, first, last, length, property, } |