import _ from 'lodash' ; import { nanoid } from 'nanoid' ; import { SerializedHighlights } from 'store/ducks/settings' ; /**
 * RegExp used to identify a valid highlight pattern.
 */ const PatternRegExp = /^[\w-]+$/ ; /**
 * Highlight class.
 */ export default class Highlight implements Serializable < SerializedHighlight > { param pattern param highlights return public static validate ( pattern , highlights ) { return PatternRegExp . test ( pattern ) && ! _ . includes ( _ . map ( highlights , 'pattern' ) , pattern . toLowerCase ( ) ) ; } private id : string ; private pattern : string ; class param pattern param color constructor ( pattern , private color ) { this . id = nanoid ( ) ; this . pattern = pattern . toLowerCase ( ) ; } return public serialize ( ) { return { color : this . color , id : this . id , pattern : this . pattern , } ; } } /**
 * Serialized highlight.
 */ export type SerializedHighlight = { color : HighlightColors ; id : string ; pattern : string ; } ; /**
 * Highlight color.
 */ export type HighlightColor = { background : string ; color : string ; } ; /**
 * Highlight colors.
 */ export enum HighlightColors { Yellow = 'Yellow' , Blue = 'Blue' , Green = 'Green' , Red = 'Red' }