From 85d79334079ef8ea19c93a46e7f568942b1d3ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Le=C5=9Bniak?= Date: Sat, 9 Jan 2021 18:35:07 +0000 Subject: [PATCH 1/6] Convert highlight helper to Typescript --- .../common/helpers/{highlight.js => highlight.ts} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename js/src/common/helpers/{highlight.js => highlight.ts} (68%) diff --git a/js/src/common/helpers/highlight.js b/js/src/common/helpers/highlight.ts similarity index 68% rename from js/src/common/helpers/highlight.js rename to js/src/common/helpers/highlight.ts index 0674bed0b0..9ed6652ae0 100644 --- a/js/src/common/helpers/highlight.js +++ b/js/src/common/helpers/highlight.ts @@ -4,21 +4,21 @@ import { truncate } from '../utils/string'; * The `highlight` helper searches for a word phrase in a string, and wraps * matches with the 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} string The string to highlight. + * @param {string|RegExp} phrase The word or words to highlight. + * @param {number} [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): Object | string { if (!phrase && !length) return string; // Convert the word phrase into a global regular expression (if it isn't // already) so we can search the string for matched. - const regexp = phrase instanceof RegExp ? phrase : new RegExp(phrase, 'gi'); + const regexp: RegExp = phrase instanceof RegExp ? phrase : new RegExp(phrase, 'gi'); - let highlighted = string; - let start = 0; + let highlighted: string = string; + let start: number = 0; // If a length was given, the truncate the string surrounding the first match. if (length) { From b860727348dc470771d240c2e994e7a19249fd6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Le=C5=9Bniak?= Date: Sun, 10 Jan 2021 09:55:04 +0000 Subject: [PATCH 2/6] Remove types from jsdoc --- js/src/common/helpers/highlight.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/js/src/common/helpers/highlight.ts b/js/src/common/helpers/highlight.ts index 9ed6652ae0..2c78c21b54 100644 --- a/js/src/common/helpers/highlight.ts +++ b/js/src/common/helpers/highlight.ts @@ -3,12 +3,6 @@ import { truncate } from '../utils/string'; /** * The `highlight` helper searches for a word phrase in a string, and wraps * matches with the tag. - * - * @param {string} string The string to highlight. - * @param {string|RegExp} phrase The word or words to highlight. - * @param {number} [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: string, phrase: string | RegExp, length: number): Object | string { if (!phrase && !length) return string; From d39b9ab450e9731867f6e145d52ee798a4017af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Le=C5=9Bniak?= Date: Sun, 10 Jan 2021 10:29:13 +0000 Subject: [PATCH 3/6] Revert back arguments' descriptions but remove types from JSDoc --- js/src/common/helpers/highlight.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/src/common/helpers/highlight.ts b/js/src/common/helpers/highlight.ts index 2c78c21b54..39da27aaf5 100644 --- a/js/src/common/helpers/highlight.ts +++ b/js/src/common/helpers/highlight.ts @@ -3,6 +3,11 @@ import { truncate } from '../utils/string'; /** * The `highlight` helper searches for a word phrase in a string, and wraps * matches with the tag. + * + * @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. */ export default function highlight(string: string, phrase: string | RegExp, length: number): Object | string { if (!phrase && !length) return string; From 89ae968b2ac01e060c47f00809b7cdca5ff222d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Le=C5=9Bniak?= Date: Sun, 10 Jan 2021 13:37:43 +0000 Subject: [PATCH 4/6] Change extension, return type and remove unnecessary types --- js/src/common/helpers/{highlight.ts => highlight.tsx} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename js/src/common/helpers/{highlight.ts => highlight.tsx} (84%) diff --git a/js/src/common/helpers/highlight.ts b/js/src/common/helpers/highlight.tsx similarity index 84% rename from js/src/common/helpers/highlight.ts rename to js/src/common/helpers/highlight.tsx index 39da27aaf5..c9d989ba39 100644 --- a/js/src/common/helpers/highlight.ts +++ b/js/src/common/helpers/highlight.tsx @@ -1,3 +1,4 @@ +import * as Mithril from 'mithril'; import { truncate } from '../utils/string'; /** @@ -9,15 +10,15 @@ import { truncate } from '../utils/string'; * @param [length] The number of characters to truncate the string to. * The string will be truncated surrounding the first match. */ -export default function highlight(string: string, phrase: string | RegExp, length: number): Object | string { +export default function highlight(string: string, phrase: string | RegExp, length: number): Mithril.Vnode | string { if (!phrase && !length) return string; // Convert the word phrase into a global regular expression (if it isn't // already) so we can search the string for matched. - const regexp: RegExp = phrase instanceof RegExp ? phrase : new RegExp(phrase, 'gi'); + const regexp = phrase instanceof RegExp ? phrase : new RegExp(phrase, 'gi'); - let highlighted: string = string; - let start: number = 0; + let highlighted = string; + let start = 0; // If a length was given, the truncate the string surrounding the first match. if (length) { From 5a59e4a916b5c13518c38059da6289f3bb78fac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Le=C5=9Bniak?= Date: Sun, 10 Jan 2021 14:49:30 +0000 Subject: [PATCH 5/6] Make lenth parameter optional --- js/src/common/helpers/highlight.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/common/helpers/highlight.tsx b/js/src/common/helpers/highlight.tsx index c9d989ba39..aa06ffb18c 100644 --- a/js/src/common/helpers/highlight.tsx +++ b/js/src/common/helpers/highlight.tsx @@ -10,7 +10,7 @@ import { truncate } from '../utils/string'; * @param [length] The number of characters to truncate the string to. * The string will be truncated surrounding the first match. */ -export default function highlight(string: string, phrase: string | RegExp, length: number): Mithril.Vnode | string { +export default function highlight(string: string, phrase: string | RegExp, length?: number): Mithril.Vnode | string { if (!phrase && !length) return string; // Convert the word phrase into a global regular expression (if it isn't From abcce978fc951b5266bb000d17f0eb4bd79db05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Le=C5=9Bniak?= Date: Wed, 20 Jan 2021 13:46:12 +0100 Subject: [PATCH 6/6] Change return type --- js/src/common/helpers/highlight.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/common/helpers/highlight.tsx b/js/src/common/helpers/highlight.tsx index aa06ffb18c..42236a32df 100644 --- a/js/src/common/helpers/highlight.tsx +++ b/js/src/common/helpers/highlight.tsx @@ -10,7 +10,7 @@ import { truncate } from '../utils/string'; * @param [length] The number of characters to truncate the string to. * The string will be truncated surrounding the first match. */ -export default function highlight(string: string, phrase: string | RegExp, length?: number): Mithril.Vnode | string { +export default function highlight(string: string, phrase: string | RegExp, length?: number): Mithril.Vnode | string { if (!phrase && !length) return string; // Convert the word phrase into a global regular expression (if it isn't