Files
tiptap/packages/core/src/commands/forEach.ts
Philipp Kühn 8e29b5f854 improve types
2021-06-04 22:58:50 +02:00

25 lines
546 B
TypeScript

import { CommandProps, 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: CommandProps & {
index: number,
},
) => boolean,
) => ReturnType,
}
}
}
export const forEach: RawCommands['forEach'] = (items, fn) => props => {
return items.every((item, index) => fn(item, { ...props, index }))
}