index.js 551 B

1234567891011121314151617
  1. //
  2. // Less Functions
  3. //
  4. // NOTE: Unlike the native JS `indexOf`, this function actually returns `0` if the value is not
  5. // found in the list/map, since Less lists are 1-indexed.
  6. functions.add('index', function ({ value: list }, { value: searchValue }) {
  7. const index = list.findIndex(({ value: item } = {}) => {
  8. // Check if the current item is an array, (in case the current list is actually a map).
  9. if (Array.isArray(item))
  10. return (item[0].value === searchValue)
  11. return (item === searchValue)
  12. })
  13. return new tree.Dimension(index + 1)
  14. })