mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-01-12 02:21:49 +00:00
fix: polyfill grupby
This commit is contained in:
parent
2cd4764cbd
commit
e435e09b6d
2 changed files with 15 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ui",
|
||||
"version": "6.4.63",
|
||||
"version": "6.4.64",
|
||||
"license": "BUSL-1.1",
|
||||
"private": true,
|
||||
"packageManager": "pnpm@9.15.5",
|
||||
|
|
|
|||
|
|
@ -6,12 +6,23 @@ export const trailingSlash = 'always'
|
|||
|
||||
if (typeof Promise.withResolvers === 'undefined') {
|
||||
Promise.withResolvers = function <T> () {
|
||||
let resolve: (value: T | PromiseLike<T>) => void
|
||||
let reject: (reason?: unknown) => void
|
||||
let resolve!: (value: T | PromiseLike<T>) => void
|
||||
let reject!: (reason?: unknown) => void
|
||||
const promise = new Promise<T>((_resolve, _reject) => {
|
||||
resolve = _resolve
|
||||
reject = _reject
|
||||
})
|
||||
return { promise, resolve: resolve!, reject: reject! }
|
||||
return { promise, resolve, reject }
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof Object.groupBy === 'undefined') {
|
||||
Object.groupBy = <T, K extends string | number | symbol>(arr: T[], callback: (item: T, index: number) => K) => {
|
||||
return [...arr].reduce<Partial<Record<K, T[]>>>((acc: Partial<Record<K, T[]>>, currentValue, index) => {
|
||||
const key = callback(currentValue, index)
|
||||
acc[key] ??= []
|
||||
acc[key]!.push(currentValue)
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue