1
0
mirror of https://github.com/flarum/core.git synced 2025-07-18 07:11:17 +02:00

Convert highlight helper to Typescript (#2532)

This commit is contained in:
daniellesniak
2021-01-23 22:43:40 +01:00
committed by GitHub
parent fbdc36dfbd
commit 912a0381c3

View File

@@ -1,16 +1,16 @@
import * as Mithril from 'mithril';
import { truncate } from '../utils/string';
/**
* The `highlight` helper searches for a word phrase in a string, and wraps
* matches with the <mark> tag.
*
* @param {String} string The string to highlight.
* @param {String|RegExp} phrase The word or words to highlight.
* @param {Integer} [length] The number of characters to truncate the string to.
* @param string The string to highlight.
* @param phrase The word or words to highlight.
* @param [length] The number of characters to truncate the string to.
* The string will be truncated surrounding the first match.
* @return {Object}
*/
export default function highlight(string, phrase, length) {
export default function highlight(string: string, phrase: string | RegExp, length?: number): Mithril.Vnode<any, any> | string {
if (!phrase && !length) return string;
// Convert the word phrase into a global regular expression (if it isn't