mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-21 15:11:59 +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",
|
"name": "ui",
|
||||||
"version": "6.4.63",
|
"version": "6.4.64",
|
||||||
"license": "BUSL-1.1",
|
"license": "BUSL-1.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@9.15.5",
|
"packageManager": "pnpm@9.15.5",
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,23 @@ export const trailingSlash = 'always'
|
||||||
|
|
||||||
if (typeof Promise.withResolvers === 'undefined') {
|
if (typeof Promise.withResolvers === 'undefined') {
|
||||||
Promise.withResolvers = function <T> () {
|
Promise.withResolvers = function <T> () {
|
||||||
let resolve: (value: T | PromiseLike<T>) => void
|
let resolve!: (value: T | PromiseLike<T>) => void
|
||||||
let reject: (reason?: unknown) => void
|
let reject!: (reason?: unknown) => void
|
||||||
const promise = new Promise<T>((_resolve, _reject) => {
|
const promise = new Promise<T>((_resolve, _reject) => {
|
||||||
resolve = _resolve
|
resolve = _resolve
|
||||||
reject = _reject
|
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