= {}, encoding?: 'uri'): string {
- let match;
+ let match: RegExpMatchArray | null = null;
while ((match = text.match(/\{\{([^}]+)\}\}/))) {
const argument = match[1].trim();
@@ -829,7 +829,7 @@ export class CoreTextUtilsProvider {
/**
* Replace @@PLUGINFILE@@ wildcards with the real URL in a text.
*
- * @param Text to treat.
+ * @param text to treat.
* @param files Files to extract the pluginfile URL from. They need to have the URL in a url or fileurl attribute.
* @return Treated text.
*/
@@ -847,8 +847,10 @@ export class CoreTextUtilsProvider {
/**
* Restore original draftfile URLs.
*
- * @param text Text to treat, including pluginfile URLs.
- * @param replaceMap Map of the replacements that were done.
+ * @param siteUrl Site URL.
+ * @param treatedText Treated text with replacements.
+ * @param originalText Original text.
+ * @param files List of files to search and replace.
* @return Treated text.
*/
restoreDraftfileUrls(siteUrl: string, treatedText: string, originalText: string, files: CoreWSFile[]): string {
@@ -1053,7 +1055,6 @@ export class CoreTextUtilsProvider {
*
* @param title Title of the new state.
* @param content Content of the text to be expanded.
- * @param component Component to link the embedded files to.
* @param options Options.
* @return Promise resolved when the modal is displayed.
*/
diff --git a/src/core/services/utils/time.ts b/src/core/services/utils/time.ts
index bbc4a3e19..e664bb5b8 100644
--- a/src/core/services/utils/time.ts
+++ b/src/core/services/utils/time.ts
@@ -170,7 +170,7 @@ export class CoreTimeUtilsProvider {
/**
* Converts a number of seconds into a short human readable format: minutes and seconds, in fromat: 3' 27''.
*
- * @param seconds Seconds
+ * @param duration Seconds
* @return Short human readable text.
* @deprecated since app 4.0. Use CoreTime.formatTimeShort instead.
*/
diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts
index 282a1c4fc..15ef3c685 100644
--- a/src/core/services/utils/url.ts
+++ b/src/core/services/utils/url.ts
@@ -544,7 +544,7 @@ export class CoreUrlUtilsProvider {
url = url.replace(/\/webservice\/pluginfile\.php\//, '/pluginfile.php/');
// Make sure the URL doesn't contain the token.
- url.replace(/([?&])token=[^&]*&?/, '$1');
+ url = url.replace(/([?&])token=[^&]*&?/, '$1');
return url;
}
diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts
index d593de260..58431922a 100644
--- a/src/core/services/utils/utils.ts
+++ b/src/core/services/utils/utils.ts
@@ -486,7 +486,7 @@ export class CoreUtilsProvider {
* @param ...args All the params sent after checkAll will be passed to isEnabledFn.
* @return Promise resolved with the list of enabled sites.
*/
- filterEnabledSites(
+ async filterEnabledSites
(
siteIds: string[],
isEnabledFn: (siteId, ...args: P) => boolean | Promise,
checkAll?: boolean,
@@ -507,16 +507,14 @@ export class CoreUtilsProvider {
}
}
- return this.allPromises(promises).catch(() => {
- // Ignore errors.
- }).then(() => {
- if (!checkAll) {
- // Checking 1 was enough, so it will either return all the sites or none.
- return enabledSites.length ? siteIds : [];
- } else {
- return enabledSites;
- }
- });
+ await CoreUtils.ignoreErrors(this.allPromises(promises));
+
+ if (!checkAll) {
+ // Checking 1 was enough, so it will either return all the sites or none.
+ return enabledSites.length ? siteIds : [];
+ } else {
+ return enabledSites;
+ }
}
/**
@@ -639,21 +637,21 @@ export class CoreUtilsProvider {
*
* @return Promise resolved with the list of countries.
*/
- getCountryList(): Promise> {
+ async getCountryList(): Promise> {
// Get the keys of the countries.
- return this.getCountryKeysList().then((keys) => {
- // Now get the code and the translated name.
- const countries = {};
+ const keys = await this.getCountryKeysList();
- keys.forEach((key) => {
- if (key.indexOf('assets.countries.') === 0) {
- const code = key.replace('assets.countries.', '');
- countries[code] = Translate.instant(key);
- }
- });
+ // Now get the code and the translated name.
+ const countries: Record = {};
- return countries;
+ keys.forEach((key) => {
+ if (key.indexOf('assets.countries.') === 0) {
+ const code = key.replace('assets.countries.', '');
+ countries[code] = Translate.instant(key);
+ }
});
+
+ return countries;
}
/**
@@ -661,18 +659,14 @@ export class CoreUtilsProvider {
*
* @return Promise resolved with the list of countries.
*/
- getCountryListSorted(): Promise {
+ async getCountryListSorted(): Promise {
// Get the keys of the countries.
- return this.getCountryList().then((countries) => {
- // Sort translations.
- const sortedCountries: { code: string; name: string }[] = [];
+ const countries = await this.getCountryList();
- Object.keys(countries).sort((a, b) => countries[a].localeCompare(countries[b])).forEach((key) => {
- sortedCountries.push({ code: key, name: countries[key] });
- });
-
- return sortedCountries;
- });
+ // Sort translations.
+ return Object.keys(countries)
+ .sort((a, b) => countries[a].localeCompare(countries[b]))
+ .map((code) => ({ code, name: countries[code] }));
}
/**
@@ -680,11 +674,13 @@ export class CoreUtilsProvider {
*
* @return Promise resolved with the countries list. Rejected if not translated.
*/
- protected getCountryKeysList(): Promise {
+ protected async getCountryKeysList(): Promise {
// It's possible that the current language isn't translated, so try with default language first.
const defaultLang = CoreLang.getDefaultLanguage();
- return this.getCountryKeysListForLanguage(defaultLang).catch(() => {
+ try {
+ return await this.getCountryKeysListForLanguage(defaultLang);
+ } catch {
// Not translated, try to use the fallback language.
const fallbackLang = CoreLang.getFallbackLanguage();
@@ -693,8 +689,8 @@ export class CoreUtilsProvider {
throw new Error('Countries not found.');
}
- return this.getCountryKeysListForLanguage(fallbackLang);
- });
+ return await this.getCountryKeysListForLanguage(fallbackLang);
+ }
}
/**
@@ -732,17 +728,19 @@ export class CoreUtilsProvider {
* @param url The URL of the file.
* @return Promise resolved with the mimetype.
*/
- getMimeTypeFromUrl(url: string): Promise {
+ async getMimeTypeFromUrl(url: string): Promise {
// First check if it can be guessed from the URL.
const extension = CoreMimetypeUtils.guessExtensionFromUrl(url);
- const mimetype = extension && CoreMimetypeUtils.getMimeType(extension);
+ let mimetype = extension && CoreMimetypeUtils.getMimeType(extension);
if (mimetype) {
- return Promise.resolve(mimetype);
+ return mimetype;
}
// Can't be guessed, get the remote mimetype.
- return CoreWS.getRemoteFileMimeType(url).then(mimetype => mimetype || '');
+ mimetype = await CoreWS.getRemoteFileMimeType(url);
+
+ return mimetype || '';
}
/**
@@ -772,7 +770,7 @@ export class CoreUtilsProvider {
/**
* Check if an unknown value is a FileEntry.
*
- * @param value Value to check.
+ * @param file Object to check.
* @return Type guard indicating if the file is a FileEntry.
*/
valueIsFileEntry(file: unknown): file is FileEntry {
@@ -1029,7 +1027,7 @@ export class CoreUtilsProvider {
this.iabInstance = InAppBrowser.create(url, '_blank', options);
if (CorePlatform.isMobile()) {
- let loadStopSubscription;
+ let loadStopSubscription: Subscription | undefined;
const loadStartUrls: string[] = [];
// Trigger global events when a url is loaded or the window is closed. This is to make it work like in Ionic 1.
@@ -1720,7 +1718,7 @@ export class CoreUtilsProvider {
* Ignore errors from a promise.
*
* @param promise Promise to ignore errors.
- * @param fallbackResult Value to return if the promise is rejected.
+ * @param fallback Value to return if the promise is rejected.
* @return Promise with ignored errors, resolving to the fallback result if provided.
*/
async ignoreErrors(promise: Promise): Promise;