mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-20 15:01:46 +01:00
feat(InputMenu): new component (#86)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { FuseResultMatch } from 'fuse.js'
|
||||
import type { FuseResult, FuseResultMatch } from 'fuse.js'
|
||||
|
||||
function truncateHTMLFromStart(html: string, maxLength: number) {
|
||||
let truncated = ''
|
||||
@@ -32,7 +32,7 @@ function truncateHTMLFromStart(html: string, maxLength: number) {
|
||||
return truncated
|
||||
}
|
||||
|
||||
export function highlight(item: { matches?: FuseResultMatch[] }, searchTerm: string, forceKey?: string, omitKeys?: string[]) {
|
||||
export function highlight<T>(item: T & { matches?: FuseResult<T>['matches'] }, searchTerm: string, forceKey?: string, omitKeys?: string[]) {
|
||||
const generateHighlightedText = (value: FuseResultMatch['value'], indices: FuseResultMatch['indices'] = []) => {
|
||||
value = value || ''
|
||||
let content = ''
|
||||
|
||||
@@ -19,6 +19,27 @@ export function omit<Data extends object, Keys extends keyof Data>(data: Data, k
|
||||
return result as Omit<Data, Keys>
|
||||
}
|
||||
|
||||
export function get(object: Record<string, any>, path: (string | number)[] | string, defaultValue?: any): any {
|
||||
if (typeof path === 'string') {
|
||||
path = path.split('.').map((key) => {
|
||||
const numKey = Number(key)
|
||||
return Number.isNaN(numKey) ? key : numKey
|
||||
})
|
||||
}
|
||||
|
||||
let result: any = object
|
||||
|
||||
for (const key of path) {
|
||||
if (result === undefined || result === null) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
result = result[key]
|
||||
}
|
||||
|
||||
return result !== undefined ? result : defaultValue
|
||||
}
|
||||
|
||||
export function looseToNumber(val: any): any {
|
||||
const n = Number.parseFloat(val)
|
||||
return Number.isNaN(n) ? val : n
|
||||
|
||||
Reference in New Issue
Block a user