mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-19 22:41:42 +01:00
feat(module)!: migrate to reka-ui (#2448)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { isEqual } from 'ohash'
|
||||
|
||||
export function pick<Data extends object, Keys extends keyof Data>(data: Data, keys: Keys[]): Pick<Data, Keys> {
|
||||
const result = {} as Pick<Data, Keys>
|
||||
|
||||
@@ -60,6 +62,22 @@ export function looseToNumber(val: any): any {
|
||||
return Number.isNaN(n) ? val : n
|
||||
}
|
||||
|
||||
export function escapeRegExp(string: string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, match => `\\${match}`)
|
||||
export function compare<T>(value?: T, currentValue?: T, comparator?: string | ((a: T, b: T) => boolean)) {
|
||||
if (value === undefined || currentValue === undefined) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
return value === currentValue
|
||||
}
|
||||
|
||||
if (typeof comparator === 'function') {
|
||||
return comparator(value, currentValue)
|
||||
}
|
||||
|
||||
if (typeof comparator === 'string') {
|
||||
return get(value!, comparator) === get(currentValue!, comparator)
|
||||
}
|
||||
|
||||
return isEqual(value, currentValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user