mirror of
https://github.com/flarum/framework.git
synced 2025-02-24 12:38:40 +08:00
Convert highlight helper to Typescript (#2532)
This commit is contained in:
parent
fbdc36dfbd
commit
912a0381c3
@ -1,16 +1,16 @@
|
|||||||
|
import * as Mithril from 'mithril';
|
||||||
import { truncate } from '../utils/string';
|
import { truncate } from '../utils/string';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `highlight` helper searches for a word phrase in a string, and wraps
|
* The `highlight` helper searches for a word phrase in a string, and wraps
|
||||||
* matches with the <mark> tag.
|
* matches with the <mark> tag.
|
||||||
*
|
*
|
||||||
* @param {String} string The string to highlight.
|
* @param string The string to highlight.
|
||||||
* @param {String|RegExp} phrase The word or words to highlight.
|
* @param phrase The word or words to highlight.
|
||||||
* @param {Integer} [length] The number of characters to truncate the string to.
|
* @param [length] The number of characters to truncate the string to.
|
||||||
* The string will be truncated surrounding the first match.
|
* 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;
|
if (!phrase && !length) return string;
|
||||||
|
|
||||||
// Convert the word phrase into a global regular expression (if it isn't
|
// Convert the word phrase into a global regular expression (if it isn't
|
Loading…
x
Reference in New Issue
Block a user