1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-15 23:18:52 +02:00
cheatsheets/_parcel/behaviors/searchable-item.js
2020-06-14 22:21:27 +10:00

14 lines
365 B
JavaScript

import onmount from 'onmount'
import permutate from '../helpers/permutate'
/**
* Sets search indices (`data-search-index` attribute)
*/
onmount('[data-js-searchable-item]', function () {
const data = JSON.parse(this.getAttribute('data-js-searchable-item') || '{}')
const words = permutate(data)
this.setAttribute('data-search-index', words.join(' '))
})