Skip to content

Commit

Permalink
chore(helpers): remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Jan 14, 2024
1 parent 1a802cf commit 07445bd
Showing 1 changed file with 1 addition and 68 deletions.
69 changes: 1 addition & 68 deletions packages/vuetify/src/util/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Utilities
import { camelize, capitalize, Comment, computed, Fragment, isVNode, reactive, toRefs, unref, watchEffect } from 'vue'
import { capitalize, Comment, computed, Fragment, isVNode, reactive, toRefs, unref, watchEffect } from 'vue'
import { IN_BROWSER } from '@/util/globals'

// Types
Expand All @@ -10,7 +10,6 @@ import type {
InjectionKey,
PropType,
Ref,
Slots,
ToRefs,
VNode,
VNodeArrayChildren,
Expand Down Expand Up @@ -398,14 +397,6 @@ export function defaultFilter (value: any, search: string | null, item: any) {
value.toString().toLocaleLowerCase().indexOf(search.toLocaleLowerCase()) !== -1
}

export function searchItems<T extends any = any> (items: T[], search: string): T[] {
if (!search) return items
search = search.toString().toLowerCase()
if (search.trim() === '') return items

return items.filter((item: any) => Object.keys(item).some(key => defaultFilter(getObjectValueByPath(item, key), search, item)))
}

export function debounce (fn: Function, delay: MaybeRef<number>) {
let timeoutId = 0 as any
const wrap = (...args: any[]) => {
Expand All @@ -430,22 +421,6 @@ export function throttle<T extends (...args: any[]) => any> (fn: T, limit: numbe
}
}

type Writable<T> = {
-readonly [P in keyof T]: T[P]
}

/**
* Filters slots to only those starting with `prefix`, removing the prefix
*/
export function getPrefixedSlots (prefix: string, slots: Slots): Slots {
return Object.keys(slots)
.filter(k => k.startsWith(prefix))
.reduce<Writable<Slots>>((obj, k) => {
obj[k.replace(prefix, '')] = slots[k]
return obj
}, {})
}

export function clamp (value: number, min = 0, max = 1) {
return Math.max(min, Math.min(max, value))
}
Expand Down Expand Up @@ -495,15 +470,6 @@ export function humanReadableFileSize (bytes: number, base: 1000 | 1024 = 1000):
return `${bytes.toFixed(1)} ${prefix[unit]}B`
}

export function camelizeObjectKeys (obj: Record<string, any> | null | undefined) {
if (!obj) return {}

return Object.keys(obj).reduce((o: any, key: string) => {
o[camelize(key)] = obj[key]
return o
}, {})
}

export function mergeDeep (
source: Record<string, any> = {},
target: Record<string, any> = {},
Expand Down Expand Up @@ -542,10 +508,6 @@ export function mergeDeep (
return out
}

export function fillArray<T> (length: number, obj: T) {
return Array(length).fill(obj)
}

export function flattenFragments (nodes: VNode[]): VNode[] {
return nodes.map(node => {
if (node.type === Fragment) {
Expand All @@ -556,11 +518,6 @@ export function flattenFragments (nodes: VNode[]): VNode[] {
}).flat()
}

export const randomHexColor = () => {
const n = (Math.random() * 0xfffff * 1000000).toString(16)
return '#' + n.slice(0, 6)
}

export function toKebabCase (str = '') {
if (toKebabCase.cache.has(str)) return toKebabCase.cache.get(str)!
const kebab = str
Expand All @@ -574,30 +531,6 @@ toKebabCase.cache = new Map<string, string>()

export type MaybeRef<T> = T | Ref<T>

export function findChildren (vnode?: VNodeChild): ComponentInternalInstance[] {
if (!vnode || typeof vnode !== 'object') {
return []
}

if (Array.isArray(vnode)) {
return vnode
.map(child => findChildren(child))
.filter(v => v)
.flat(1)
} else if (Array.isArray(vnode.children)) {
return vnode.children
.map(child => findChildren(child))
.filter(v => v)
.flat(1)
} else if (vnode.component) {
return [vnode.component, ...findChildren(vnode.component?.subTree)]
.filter(v => v)
.flat(1)
}

return []
}

export function findChildrenWithProvide (
key: InjectionKey<any> | symbol,
vnode?: VNodeChild,
Expand Down

0 comments on commit 07445bd

Please sign in to comment.