UNPKG

contenido

Version:

Contenido is a library with a set of tools to help you create your own rich text editor on top of draft-js without thinking about how to handle things.

22 lines (15 loc) 482 B
import { convertToRaw } from '../../core'; // Custom Types import type { State } from '../../types'; const getEntityCount = (state: State, type: string) => { let count = 0; const contentState = state.getCurrentContent(); const entityValues = Object.values(convertToRaw(contentState).entityMap); if (entityValues.length > 0) { entityValues.forEach((entity) => { if (entity.type === type) count++; }); } return count; }; export default getEntityCount;