From 20baa93ca79c14a6ad063669636d5edefd96b6c0 Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Tue, 23 Jun 2020 10:02:59 -0400 Subject: [PATCH] convert: common/utils/string --- js/src/common/utils/{string.js => string.ts} | 22 ++++---------------- 1 file changed, 4 insertions(+), 18 deletions(-) rename js/src/common/utils/{string.js => string.ts} (75%) diff --git a/js/src/common/utils/string.js b/js/src/common/utils/string.ts similarity index 75% rename from js/src/common/utils/string.js rename to js/src/common/utils/string.ts index 73623d8a2..be7bc92d1 100644 --- a/js/src/common/utils/string.js +++ b/js/src/common/utils/string.ts @@ -1,12 +1,7 @@ /** * Truncate a string to the given length, appending ellipses if necessary. - * - * @param {String} string - * @param {Number} length - * @param {Number} [start=0] - * @return {String} */ -export function truncate(string, length, start = 0) { +export function truncate(string: string, length: number, start: number = 0): string { return (start > 0 ? '...' : '') + string.substring(start, start + length) + (string.length > start + length ? '...' : ''); } @@ -17,11 +12,8 @@ export function truncate(string, length, start = 0) { * NOTE: This method does not use the comparably sophisticated transliteration * mechanism that is employed in the backend. Therefore, it should only be used * to *suggest* slugs that can be overridden by the user. - * - * @param {String} string - * @return {String} */ -export function slug(string) { +export function slug(string: string): string { return string .toLowerCase() .replace(/[^a-z0-9]/gi, '-') @@ -32,11 +24,8 @@ export function slug(string) { /** * Strip HTML tags and quotes out of the given string, replacing them with * meaningful punctuation. - * - * @param {String} string - * @return {String} */ -export function getPlainContent(string) { +export function getPlainContent(string: string): string { const html = string.replace(/(<\/p>|
)/g, '$1  ').replace(/]*>/gi, ' '); const dom = $('
').html(html); @@ -55,10 +44,7 @@ getPlainContent.removeSelectors = ['blockquote', 'script']; /** * Make a string's first character uppercase. - * - * @param {String} string - * @return {String} */ -export function ucfirst(string) { +export function ucfirst(string: string): string { return string.substr(0, 1).toUpperCase() + string.substr(1); }