import { Task } from '../model/cards' ; export const isBlank = ( str ) => { return ! str || /^\s*$/ . test ( str ) ; } ; const checkboxRegex = /^\s?[-|+|*]\s?\[(.*)\](?:\s)?(.*)/gim ; const matchToTask = ( match , index ) : Task => { const done = match [ 1 ] . trim ( ) . toLowerCase ( ) === 'x' ; const content = match [ 2 ] . trim ( ) ; return { done , content , index } ; } ; export const extractTasks = ( description ) : Array < Task > => { let match ; const matches = [ ] ; do { match = checkboxRegex . exec ( description ) ; matches . push ( match ) ; } while ( match ) ; const tasks = matches . filter ( ( m ) => m != null ) . map ( matchToTask ) ; return tasks ; } ; export const escapeRegExp = ( content ) : string => { if ( ! content ) { return content ; } return content . replace ( /[.*+?^${}()|[\]\\]/g , '\\$&' ) ; } ; export default { isBlank } ;