feat: add forEach command

This commit is contained in:
Philipp Kühn
2021-06-04 22:25:53 +02:00
parent 78e2a6e775
commit 783ce4e3ac
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { Command, RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands<ReturnType> {
forEach: {
/**
* Loop through an array of items.
*/
forEach: <T>(
items: T[],
fn: (
item: T,
props: Parameters<Command>[0] & {
index: number,
},
) => boolean,
) => ReturnType,
}
}
}
export const forEach: RawCommands['forEach'] = (items, fn) => props => {
return items.every((item, index) => fn(item, { ...props, index }))
}