import Vue from 'vue'; /** * Get value of an object property/path even if it's nested */ export function getValueByPath(obj: any, path: any) { const value = path.split('.').reduce((o: any, i: any) => o[i], obj); return value; } /** * Extension of indexOf method by equality function if specified */ export function indexOf(array: any, obj: any, fn: any) { if (!array) { return -1; } if (!fn || typeof fn !== 'function') { return array.indexOf(obj); } for (let i = 0; i < array.length; i++) { if (fn(array[i], obj)) { return i; } } return -1; } export function removeElement(el: any) { if (typeof el.remove !== 'undefined') { el.remove(); } else { el.parentNode.removeChild(el); } } Vue.filter('truncate', (value: string, limit: number = 40) => { return value && value.length > limit ? value.substring(0, limit) + '...' : value; });