diff --git a/src/addons/qtype/ddmarker/classes/ddmarker.ts b/src/addons/qtype/ddmarker/classes/ddmarker.ts index 98d937316..49fddf82d 100644 --- a/src/addons/qtype/ddmarker/classes/ddmarker.ts +++ b/src/addons/qtype/ddmarker/classes/ddmarker.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CoreDomUtils } from '@services/utils/dom'; -import { CoreTextUtils } from '@services/utils/text'; +import { CoreText } from '@singletons/text'; import { CoreCoordinates, CoreDom } from '@singletons/dom'; import { CoreEventObserver } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; @@ -267,7 +267,7 @@ export class AddonQtypeDdMarkerQuestion { } // Check that a function to draw this shape exists. - const drawFunc = 'drawShape' + CoreTextUtils.ucFirst(shape); + const drawFunc = 'drawShape' + CoreText.capitalize(shape); if (!(this[drawFunc] instanceof Function)) { return; } diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index 24de44d23..d5c4f064c 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -33,6 +33,7 @@ import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-de import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreUrl } from '@singletons/url'; import { CoreTime } from '@singletons/time'; +import { CoreText } from '@singletons/text'; /** * Result of a resource download. @@ -232,7 +233,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, const lastDownloaded = await CoreCourseHelper.getModulePackageLastDownloaded(this.module, this.component); - this.downloadTimeReadable = CoreTextUtils.ucFirst(lastDownloaded.downloadTimeReadable); + this.downloadTimeReadable = CoreText.capitalize(lastDownloaded.downloadTimeReadable); } /** diff --git a/src/core/features/course/components/module-summary/module-summary.ts b/src/core/features/course/components/module-summary/module-summary.ts index 5b87b840c..edaae3b37 100644 --- a/src/core/features/course/components/module-summary/module-summary.ts +++ b/src/core/features/course/components/module-summary/module-summary.ts @@ -28,7 +28,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreTextUtils } from '@services/utils/text'; +import { CoreText } from '@singletons/text'; import { CoreUtils } from '@services/utils/utils'; import { ModalController, NgZone } from '@singletons'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; @@ -222,7 +222,7 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy { if (this.canPrefetch) { if (moduleInfo.downloadTime && moduleInfo.downloadTime > 0) { - this.downloadTimeReadable = CoreTextUtils.ucFirst(moduleInfo.downloadTimeReadable); + this.downloadTimeReadable = CoreText.capitalize(moduleInfo.downloadTimeReadable); } this.prefetchLoading = moduleInfo.status === DownloadStatus.DOWNLOADING; this.prefetchDisabled = moduleInfo.status === DownloadStatus.DOWNLOADED; diff --git a/src/core/services/utils/mimetype.ts b/src/core/services/utils/mimetype.ts index 5bbf67724..3125c6bf9 100644 --- a/src/core/services/utils/mimetype.ts +++ b/src/core/services/utils/mimetype.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { FileEntry } from '@awesome-cordova-plugins/file/ngx'; import { CoreFile } from '@services/file'; -import { CoreTextUtils } from '@services/utils/text'; +import { CoreText } from '@singletons/text'; import { makeSingleton, Translate } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { CoreWSFile } from '@services/ws'; @@ -466,7 +466,7 @@ export class CoreMimetypeUtilsProvider { const value = attr[key]; translateParams[key] = value; translateParams[key.toUpperCase()] = value.toUpperCase(); - translateParams[CoreTextUtils.ucFirst(key)] = CoreTextUtils.ucFirst(value); + translateParams[CoreText.capitalize(key)] = CoreText.capitalize(value); } // MIME types may include + symbol but this is not permitted in string ids. @@ -486,7 +486,7 @@ export class CoreMimetypeUtilsProvider { } if (capitalise) { - result = CoreTextUtils.ucFirst(result); + result = CoreText.capitalize(result); } return result; diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index a40bcdbd9..2bfb864ed 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -28,6 +28,7 @@ import { CorePath } from '@singletons/path'; import { CorePlatform } from '@services/platform'; import { ContextLevel } from '@/core/constants'; import { CoreDom } from '@singletons/dom'; +import { CoreText } from '@singletons/text'; /** * Different type of errors the app can treat. @@ -1007,9 +1008,10 @@ export class CoreTextUtilsProvider { * * @param text Text to treat. * @returns Treated text. + * @deprecated since 4.5. Use CoreText.capitalize instead. */ ucFirst(text: string): string { - return text.charAt(0).toUpperCase() + text.slice(1); + return CoreText.capitalize(text); } /** diff --git a/src/core/singletons/text.ts b/src/core/singletons/text.ts index 19b15a8b8..0a60c5a48 100644 --- a/src/core/singletons/text.ts +++ b/src/core/singletons/text.ts @@ -95,4 +95,14 @@ export class CoreText { }); } + /** + * Make a string's first character uppercase. + * + * @param text Text to treat. + * @returns Treated text. + */ + static capitalize(text: string): string { + return text.charAt(0).toUpperCase() + text.slice(1); + } + }