diff --git a/src/addons/badges/services/badges.ts b/src/addons/badges/services/badges.ts index d95e4f733..df39a9595 100644 --- a/src/addons/badges/services/badges.ts +++ b/src/addons/badges/services/badges.ts @@ -83,7 +83,7 @@ export class AddonBadgesProvider { badge.alignment = badge.alignment || badge.competencies; // Check that the alignment is valid, they were broken in 3.7. - if (badge.alignment && badge.alignment[0] && typeof badge.alignment[0].targetname == 'undefined') { + if (badge.alignment && badge.alignment[0] && badge.alignment[0].targetname === undefined) { // If any badge lacks targetname it means they are affected by the Moodle bug, don't display them. delete badge.alignment; } diff --git a/src/addons/badges/services/handlers/user.ts b/src/addons/badges/services/handlers/user.ts index 52e44fb69..5e3a5bc44 100644 --- a/src/addons/badges/services/handlers/user.ts +++ b/src/addons/badges/services/handlers/user.ts @@ -49,7 +49,7 @@ export class AddonBadgesUserHandlerService implements CoreUserProfileHandler { courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed, ): Promise { - if (navOptions && typeof navOptions.badges != 'undefined') { + if (navOptions && navOptions.badges !== undefined) { return navOptions.badges; } diff --git a/src/addons/block/activitymodules/components/activitymodules/activitymodules.ts b/src/addons/block/activitymodules/components/activitymodules/activitymodules.ts index fdeb9a967..60db4a0c0 100644 --- a/src/addons/block/activitymodules/components/activitymodules/activitymodules.ts +++ b/src/addons/block/activitymodules/components/activitymodules/activitymodules.ts @@ -67,13 +67,13 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i section.modules.forEach((mod) => { if (mod.uservisible === false || !CoreCourse.moduleHasView(mod) || - typeof modFullNames[mod.modname] != 'undefined') { + modFullNames[mod.modname] !== undefined) { // Ignore this module. return; } // Get the archetype of the module type. - if (typeof archetypes[mod.modname] == 'undefined') { + if (archetypes[mod.modname] === undefined) { archetypes[mod.modname] = CoreCourseModuleDelegate.supportsFeature( mod.modname, CoreConstants.FEATURE_MOD_ARCHETYPE, diff --git a/src/addons/blog/services/handlers/course-option.ts b/src/addons/blog/services/handlers/course-option.ts index c15f4b4de..c935a221d 100644 --- a/src/addons/blog/services/handlers/course-option.ts +++ b/src/addons/blog/services/handlers/course-option.ts @@ -62,7 +62,7 @@ export class AddonBlogCourseOptionHandlerService implements CoreCourseOptionsHan ): Promise { const enabled = await CoreCourseHelper.hasABlockNamed(courseId, 'blog_menu'); - if (enabled && navOptions && typeof navOptions.blogs != 'undefined') { + if (enabled && navOptions && navOptions.blogs !== undefined) { return navOptions.blogs; } diff --git a/src/addons/calendar/pages/day/day.page.ts b/src/addons/calendar/pages/day/day.page.ts index 984d5931b..b806ed84c 100644 --- a/src/addons/calendar/pages/day/day.page.ts +++ b/src/addons/calendar/pages/day/day.page.ts @@ -211,7 +211,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { this.filter.courseId = CoreNavigator.getRouteNumberParam('courseId'); this.filter.categoryId = CoreNavigator.getRouteNumberParam('categoryId'); - this.filter.filtered = typeof this.filter.courseId != 'undefined' || types.some((name) => !this.filter[name]); + this.filter.filtered = this.filter.courseId !== undefined || types.some((name) => !this.filter[name]); const month = CoreNavigator.getRouteNumberParam('month'); const source = new AddonCalendarDaySlidesItemsManagerSource(this, moment({ diff --git a/src/addons/calendar/services/calendar.ts b/src/addons/calendar/services/calendar.ts index 17c60c3bf..69473fb05 100644 --- a/src/addons/calendar/services/calendar.ts +++ b/src/addons/calendar/services/calendar.ts @@ -538,7 +538,7 @@ export class AddonCalendarProvider { // Ignore errors. } - if (typeof value == 'undefined' || value === null) { + if (value === undefined || value === null) { value = site.getStoredConfig('calendar_lookahead'); } diff --git a/src/addons/competency/pages/competencysummary/competencysummary.ts b/src/addons/competency/pages/competencysummary/competencysummary.ts index fa810bf2b..5119dd2c8 100644 --- a/src/addons/competency/pages/competencysummary/competencysummary.ts +++ b/src/addons/competency/pages/competencysummary/competencysummary.ts @@ -70,7 +70,7 @@ export class AddonCompetencyCompetencySummaryPage implements OnInit { protected async fetchCompetency(): Promise { try { const result = await AddonCompetency.getCompetencySummary(this.competencyId); - if (!this.contextLevel || typeof this.contextInstanceId == 'undefined') { + if (!this.contextLevel || this.contextInstanceId === undefined) { // Context not specified, use user context. this.contextLevel = ContextLevel.USER; this.contextInstanceId = result.usercompetency!.userid; diff --git a/src/addons/competency/services/handlers/course-option.ts b/src/addons/competency/services/handlers/course-option.ts index 7051064ff..d46c2d6fa 100644 --- a/src/addons/competency/services/handlers/course-option.ts +++ b/src/addons/competency/services/handlers/course-option.ts @@ -55,7 +55,7 @@ export class AddonCompetencyCourseOptionHandlerService implements CoreCourseOpti return false; // Not enabled for guests. } - if (navOptions && typeof navOptions.competencies != 'undefined') { + if (navOptions && navOptions.competencies !== undefined) { return navOptions.competencies; } @@ -83,7 +83,7 @@ export class AddonCompetencyCourseOptionHandlerService implements CoreCourseOpti * @inheritdoc */ async invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise { - if (navOptions && typeof navOptions.competencies != 'undefined') { + if (navOptions && navOptions.competencies !== undefined) { // No need to invalidate anything. return; } diff --git a/src/addons/coursecompletion/services/coursecompletion.ts b/src/addons/coursecompletion/services/coursecompletion.ts index 21898f3c6..0fa9d22ec 100644 --- a/src/addons/coursecompletion/services/coursecompletion.ts +++ b/src/addons/coursecompletion/services/coursecompletion.ts @@ -172,12 +172,12 @@ export class AddonCourseCompletionProvider { const course = await CoreCourses.getUserCourse(courseId, preferCache); if (course) { - if (typeof course.enablecompletion != 'undefined' && !course.enablecompletion) { + if (course.enablecompletion !== undefined && !course.enablecompletion) { // Completion not enabled for the course. return false; } - if (typeof course.completionhascriteria != 'undefined' && !course.completionhascriteria) { + if (course.completionhascriteria !== undefined && !course.completionhascriteria) { // No criteria, cannot view completion. return false; } @@ -206,7 +206,7 @@ export class AddonCourseCompletionProvider { // If the site is returning the completionhascriteria then the user can view his own completion. // We already checked the value in isPluginViewEnabledForCourse. - if (course && typeof course.completionhascriteria != 'undefined') { + if (course && course.completionhascriteria !== undefined) { return true; } } diff --git a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts index a0aab60bf..2f9ae9056 100644 --- a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts +++ b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts @@ -86,7 +86,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan // Update MathJax locale if app language changes. CoreEvents.on(CoreEvents.LANGUAGE_CHANGED, (lang: string) => { - if (typeof this.window.MathJax == 'undefined') { + if (this.window.MathJax === undefined) { return; } @@ -223,7 +223,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan if (!this._configured) { const lang = this._lang; - if (typeof that.window.MathJax != 'undefined') { + if (that.window.MathJax !== undefined) { that.window.MathJax.Hub.Queue(() => { that.window.MathJax.Localization.setLocale(lang); }); @@ -238,7 +238,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan this._setLocale(); } - if (typeof that.window.MathJax != 'undefined') { + if (that.window.MathJax !== undefined) { const processDelay = that.window.MathJax.Hub.processSectionDelay; // Set the process section delay to 0 when updating the formula. that.window.MathJax.Hub.processSectionDelay = 0; diff --git a/src/addons/messages/pages/discussion/discussion.page.ts b/src/addons/messages/pages/discussion/discussion.page.ts index ca9028029..7c4176af1 100644 --- a/src/addons/messages/pages/discussion/discussion.page.ts +++ b/src/addons/messages/pages/discussion/discussion.page.ts @@ -205,7 +205,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView message.useridfrom; let added = false; - if (typeof this.keepMessageMap[message.hash] === 'undefined') { + if (this.keepMessageMap[message.hash] === undefined) { // Message not added to the list. Add it now. this.messages.push(message); added = message.useridfrom != this.currentUserId; @@ -1277,7 +1277,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView }, }); - if (typeof userId != 'undefined') { + if (userId !== undefined) { const splitViewLoaded = CoreNavigator.isCurrentPathInTablet('**/messages/**/discussion'); // Open user conversation. diff --git a/src/addons/messages/pages/discussions-35/discussions.page.ts b/src/addons/messages/pages/discussions-35/discussions.page.ts index 5c904cbae..ad60b73e9 100644 --- a/src/addons/messages/pages/discussions-35/discussions.page.ts +++ b/src/addons/messages/pages/discussions-35/discussions.page.ts @@ -77,7 +77,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy { if (data.userId && this.discussions) { const discussion = this.discussions.find((disc) => disc.message!.user == data.userId); - if (typeof discussion == 'undefined') { + if (discussion === undefined) { this.loaded = false; this.refreshData().finally(() => { this.loaded = true; @@ -99,7 +99,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy { if (data.userId && this.discussions) { const discussion = this.discussions.find((disc) => disc.message!.user == data.userId); - if (typeof discussion != 'undefined') { + if (discussion !== undefined) { // A discussion has been read reset counter. discussion.unread = false; diff --git a/src/addons/messages/pages/group-conversations/group-conversations.page.ts b/src/addons/messages/pages/group-conversations/group-conversations.page.ts index f4d884458..47d6ba354 100644 --- a/src/addons/messages/pages/group-conversations/group-conversations.page.ts +++ b/src/addons/messages/pages/group-conversations/group-conversations.page.ts @@ -118,7 +118,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { // Search the conversation to update. const conversation = this.findConversation(data.conversationId, data.userId, expandedOption); - if (typeof conversation == 'undefined') { + if (conversation === undefined) { // Probably a new conversation, refresh the list. this.loaded = false; this.refreshData().finally(() => { @@ -152,7 +152,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { if (data.conversationId) { const conversation = this.findConversation(data.conversationId); - if (typeof conversation != 'undefined') { + if (conversation !== undefined) { // A conversation has been read reset counter. conversation.unreadcount = 0; @@ -318,7 +318,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { await Promise.all(promises); // The expanded status hasn't been initialized. Do it now. - if (typeof this.favourites.expanded == 'undefined' && (this.selectedConversationId || this.selectedUserId)) { + if (this.favourites.expanded === undefined && (this.selectedConversationId || this.selectedUserId)) { // A certain conversation should be opened. // We don't know which option it belongs to, so we need to fetch the data for all of them. const promises: Promise[] = []; @@ -355,7 +355,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { * @return Promise resolved when done. */ protected async fetchDataForExpandedOption(): Promise { - if (typeof this.favourites.expanded == 'undefined') { + if (this.favourites.expanded === undefined) { // Calculate which option should be expanded initially. this.favourites.expanded = this.favourites.count != 0 && !this.group.unread && !this.individual.unread; this.group.expanded = !this.favourites.expanded && this.group.count != 0 && !this.individual.unread; @@ -572,7 +572,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { if (conversation) { // Check if it's the last message. Offline messages are considered more recent than sent messages. - if (typeof conversation.lastmessage === 'undefined' || conversation.lastmessage === null || + if (conversation.lastmessage === undefined || conversation.lastmessage === null || !conversation.lastmessagepending || (conversation.lastmessagedate || 0) <= message.timecreated / 1000) { this.addLastOfflineMessage(conversation, message); diff --git a/src/addons/messages/services/handlers/discussion-link.ts b/src/addons/messages/services/handlers/discussion-link.ts index b0fae3fce..2eb03cdec 100644 --- a/src/addons/messages/services/handlers/discussion-link.ts +++ b/src/addons/messages/services/handlers/discussion-link.ts @@ -69,12 +69,12 @@ export class AddonMessagesDiscussionLinkHandlerService extends CoreContentLinksH return false; } - if (typeof params.id == 'undefined' && typeof params.user2 == 'undefined') { + if (params.id === undefined && params.user2 === undefined) { // Other user not defined, cannot treat the URL. return false; } - if (typeof params.user1 != 'undefined') { + if (params.user1 !== undefined) { // Check if user1 is the current user, since the app only supports current user. const site = await CoreSites.getSite(siteId); diff --git a/src/addons/messages/services/messages-sync.ts b/src/addons/messages/services/messages-sync.ts index cdcc4dd6c..64edaf6df 100644 --- a/src/addons/messages/services/messages-sync.ts +++ b/src/addons/messages/services/messages-sync.ts @@ -107,7 +107,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider { promises.push(this.syncDiscussion(conversationId, undefined, siteId).then((result) => { - if (typeof result == 'undefined') { + if (result === undefined) { return; } @@ -120,7 +120,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider { promises.push(this.syncDiscussion(undefined, userId, siteId).then((result) => { - if (typeof result == 'undefined') { + if (result === undefined) { return; } diff --git a/src/addons/messages/services/messages.ts b/src/addons/messages/services/messages.ts index 1498691b6..ba07393c5 100644 --- a/src/addons/messages/services/messages.ts +++ b/src/addons/messages/services/messages.ts @@ -317,7 +317,7 @@ export class AddonMessagesProvider { userid: userId, }; - if (typeof read != 'undefined') { + if (read !== undefined) { params.read = read; } @@ -1075,10 +1075,10 @@ export class AddonMessagesProvider { preSets.getFromCache = false; preSets.emergencyCache = false; } - if (typeof type != 'undefined' && type != null) { + if (type !== undefined && type != null) { params.type = type; } - if (typeof favourites != 'undefined' && favourites != null) { + if (favourites !== undefined && favourites != null) { params.favourites = !!favourites; } if (site.isVersionGreaterEqualThan('3.7') && type != AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP) { @@ -1244,7 +1244,7 @@ export class AddonMessagesProvider { userId: number, userFullname: string, ): void => { - if (typeof discussions[userId] === 'undefined') { + if (discussions[userId] === undefined) { discussions[userId] = { fullname: userFullname, profileimageurl: '', @@ -1259,7 +1259,7 @@ export class AddonMessagesProvider { // Extract the most recent message. Pending messages are considered more recent than messages already sent. const discMessage = discussions[userId].message; - if (typeof discMessage === 'undefined' || (!discMessage.pending && message.pending) || + if (discMessage === undefined || (!discMessage.pending && message.pending) || (discMessage.pending == message.pending && (discMessage.timecreated < message.timecreated || (discMessage.timecreated == message.timecreated && discMessage.id < messageId)))) { @@ -2646,7 +2646,7 @@ export class AddonMessagesProvider { conversationid: conversationId, messages: messages.map((message) => ({ text: message.text, - textformat: typeof message.textformat != 'undefined' ? message.textformat : 1, + textformat: message.textformat !== undefined ? message.textformat : 1, })), }; diff --git a/src/addons/mod/assign/classes/base-feedback-plugin-component.ts b/src/addons/mod/assign/classes/base-feedback-plugin-component.ts index b44226f47..2bc825f83 100644 --- a/src/addons/mod/assign/classes/base-feedback-plugin-component.ts +++ b/src/addons/mod/assign/classes/base-feedback-plugin-component.ts @@ -57,7 +57,7 @@ export class AddonModAssignFeedbackPluginBaseComponent { }, }); - if (typeof modalData == 'undefined') { + if (modalData === undefined) { throw new CoreCanceledError(); // User cancelled. } diff --git a/src/addons/mod/assign/components/index/index.ts b/src/addons/mod/assign/components/index/index.ts index 80a089d2b..0aa2a9a8e 100644 --- a/src/addons/mod/assign/components/index/index.ts +++ b/src/addons/mod/assign/components/index/index.ts @@ -304,7 +304,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo * @param hasSubmissions If the status has any submission. */ goToSubmissionList(status?: string, hasSubmissions = false): void { - if (typeof status != 'undefined' && !hasSubmissions) { + if (status !== undefined && !hasSubmissions) { return; } @@ -312,7 +312,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo groupId: this.group || 0, moduleName: this.moduleName, }; - if (typeof status != 'undefined') { + if (status !== undefined) { params.status = status; } diff --git a/src/addons/mod/assign/components/submission/submission.ts b/src/addons/mod/assign/components/submission/submission.ts index 4256c120a..5b7b69785 100644 --- a/src/addons/mod/assign/components/submission/submission.ts +++ b/src/addons/mod/assign/components/submission/submission.ts @@ -380,7 +380,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can for (const x in this.gradeInfo.outcomes) { const outcome = this.gradeInfo.outcomes[x]; - if (this.originalGrades.outcomes[outcome.id] == 'undefined' || + if (this.originalGrades.outcomes[outcome.id] === undefined || this.originalGrades.outcomes[outcome.id] != outcome.selectedId) { return true; } @@ -726,7 +726,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can if (submissionGrade.outcomes && Object.keys(submissionGrade.outcomes).length && this.gradeInfo?.outcomes) { this.gradeInfo.outcomes.forEach((outcome) => { - if (typeof submissionGrade.outcomes[outcome.itemNumber!] != 'undefined') { + if (submissionGrade.outcomes[outcome.itemNumber!] !== undefined) { // If outcome has been modified from gradebook, do not use offline. if (outcome.modified! < submissionGrade.timemodified) { outcome.selectedId = submissionGrade.outcomes[outcome.itemNumber!]; @@ -944,7 +944,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can // Check if grading method is simple or not. if (this.gradeInfo.advancedgrading && this.gradeInfo.advancedgrading[0] && - typeof this.gradeInfo.advancedgrading[0].method != 'undefined') { + this.gradeInfo.advancedgrading[0].method !== undefined) { this.grade.method = this.gradeInfo.advancedgrading[0].method || 'simple'; } else { this.grade.method = 'simple'; @@ -1039,7 +1039,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can } const submissionStatementMissing = !!this.assign!.requiresubmissionstatement && - typeof this.assign!.submissionstatement == 'undefined'; + this.assign!.submissionstatement === undefined; this.canSubmit = !this.isSubmittedForGrading && !this.submittedOffline && (submissionStatus.lastattempt.cansubmit || (this.hasOffline && AddonModAssign.canSubmitOffline(this.assign!, submissionStatus))); diff --git a/src/addons/mod/assign/feedback/comments/services/handler.ts b/src/addons/mod/assign/feedback/comments/services/handler.ts index 1b288988c..02a8bc342 100644 --- a/src/addons/mod/assign/feedback/comments/services/handler.ts +++ b/src/addons/mod/assign/feedback/comments/services/handler.ts @@ -69,7 +69,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss */ discardDraft(assignId: number, userId: number, siteId?: string): void { const id = this.getDraftId(assignId, userId, siteId); - if (typeof this.drafts[id] != 'undefined') { + if (this.drafts[id] !== undefined) { delete this.drafts[id]; } } @@ -95,7 +95,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss getDraft(assignId: number, userId: number, siteId?: string): AddonModAssignFeedbackCommentsDraftData | undefined { const id = this.getDraftId(assignId, userId, siteId); - if (typeof this.drafts[id] != 'undefined') { + if (this.drafts[id] !== undefined) { return this.drafts[id]; } } @@ -164,7 +164,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss const initialText = AddonModAssign.getSubmissionPluginText(plugin); const newText = AddonModAssignFeedbackCommentsHandler.getTextFromInputData(plugin, inputData); - if (typeof newText == 'undefined') { + if (newText === undefined) { return false; } diff --git a/src/addons/mod/assign/pages/submission-review/submission-review.ts b/src/addons/mod/assign/pages/submission-review/submission-review.ts index 20342ef15..a51cf4bc4 100644 --- a/src/addons/mod/assign/pages/submission-review/submission-review.ts +++ b/src/addons/mod/assign/pages/submission-review/submission-review.ts @@ -142,7 +142,7 @@ export class AddonModAssignSubmissionReviewPage implements OnInit, OnDestroy, Ca // Grades can be saved if simple grading. if (gradeInfo.advancedgrading && gradeInfo.advancedgrading[0] && - typeof gradeInfo.advancedgrading[0].method != 'undefined') { + gradeInfo.advancedgrading[0].method !== undefined) { const method = gradeInfo.advancedgrading[0].method || 'simple'; this.canSaveGrades = method == 'simple'; diff --git a/src/addons/mod/assign/services/assign-helper.ts b/src/addons/mod/assign/services/assign-helper.ts index 739c93d47..680bfbdaa 100644 --- a/src/addons/mod/assign/services/assign-helper.ts +++ b/src/addons/mod/assign/services/assign-helper.ts @@ -406,7 +406,7 @@ export class AddonModAssignHelperProvider { submissions.forEach((submission) => { submission.submitid = submission.userid && submission.userid > 0 ? submission.userid : submission.blindid; - if (typeof submission.submitid == 'undefined' || submission.submitid <= 0) { + if (submission.submitid === undefined || submission.submitid <= 0) { return; } diff --git a/src/addons/mod/book/services/book.ts b/src/addons/mod/book/services/book.ts index 9cd689d84..1efa28d21 100644 --- a/src/addons/mod/book/services/book.ts +++ b/src/addons/mod/book/services/book.ts @@ -223,7 +223,7 @@ export class AddonModBookProvider { * @return The toc. */ getToc(contents: CoreCourseModuleContentFile[]): AddonModBookTocChapterParsed[] { - if (!contents || !contents.length || typeof contents[0].content == 'undefined') { + if (!contents || !contents.length || contents[0].content === undefined) { return []; } diff --git a/src/addons/mod/data/components/index/index.ts b/src/addons/mod/data/components/index/index.ts index adec614b3..df7ca92aa 100644 --- a/src/addons/mod/data/components/index/index.ts +++ b/src/addons/mod/data/components/index/index.ts @@ -191,7 +191,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp * @return True if refresh is needed, false otherwise. */ protected isRefreshSyncNeeded(syncEventData: AddonModDataAutoSyncData): boolean { - if (this.database && syncEventData.dataId == this.database.id && typeof syncEventData.entryId == 'undefined') { + if (this.database && syncEventData.dataId == this.database.id && syncEventData.entryId === undefined) { this.loaded = false; // Refresh the data. this.content?.scrollToTop(); @@ -309,7 +309,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp this.entriesRendered = ''; - this.foundRecordsTranslationData = typeof entries.maxcount != 'undefined' + this.foundRecordsTranslationData = entries.maxcount !== undefined ? { num: entries.totalcount, max: entries.maxcount, diff --git a/src/addons/mod/data/components/search/search.ts b/src/addons/mod/data/components/search/search.ts index 4221b769a..42fbd7e54 100644 --- a/src/addons/mod/data/components/search/search.ts +++ b/src/addons/mod/data/components/search/search.ts @@ -69,7 +69,7 @@ export class AddonModDataSearchComponent implements OnInit { ngOnInit(): void { this.advancedIndexed = {}; this.search.advanced?.forEach((field) => { - if (typeof field != 'undefined') { + if (field !== undefined) { this.advancedIndexed[field.name] = field.value ? CoreTextUtils.parseJSON(field.value, '') : ''; diff --git a/src/addons/mod/data/fields/latlong/component/latlong.ts b/src/addons/mod/data/fields/latlong/component/latlong.ts index a638544e4..87f1634d7 100644 --- a/src/addons/mod/data/fields/latlong/component/latlong.ts +++ b/src/addons/mod/data/fields/latlong/component/latlong.ts @@ -48,7 +48,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo * @return Readable Latitude and logitude. */ formatLatLong(north?: number, east?: number): string { - if (typeof north !== 'undefined' || typeof east !== 'undefined') { + if (north !== undefined || east !== undefined) { north = north || 0; east = east || 0; const northFixed = Math.abs(north).toFixed(4); @@ -69,7 +69,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo */ getLatLongLink(north?: number, east?: number): SafeUrl { let url = ''; - if (typeof north !== 'undefined' || typeof east !== 'undefined') { + if (north !== undefined || east !== undefined) { const northFixed = north ? north.toFixed(4) : '0.0000'; const eastFixed = east ? east.toFixed(4) : '0.0000'; diff --git a/src/addons/mod/data/fields/latlong/services/handler.ts b/src/addons/mod/data/fields/latlong/services/handler.ts index 4eed24cc1..03ab0a829 100644 --- a/src/addons/mod/data/fields/latlong/services/handler.ts +++ b/src/addons/mod/data/fields/latlong/services/handler.ts @@ -104,7 +104,7 @@ export class AddonModDataFieldLatlongHandlerService implements AddonModDataField // The lat long class has two values that need to be checked. inputData.forEach((value) => { - if (typeof value.value != 'undefined' && value.value != '') { + if (value.value !== undefined && value.value != '') { valueCount++; } }); diff --git a/src/addons/mod/data/fields/picture/services/handler.ts b/src/addons/mod/data/fields/picture/services/handler.ts index d0b503c13..d6e4dd4a5 100644 --- a/src/addons/mod/data/fields/picture/services/handler.ts +++ b/src/addons/mod/data/fields/picture/services/handler.ts @@ -135,7 +135,7 @@ export class AddonModDataFieldPictureHandlerService implements AddonModDataField } const found = inputData.some((input) => { - if (typeof input.subfield != 'undefined' && input.subfield == 'file') { + if (input.subfield !== undefined && input.subfield == 'file') { return !!input.value; } diff --git a/src/addons/mod/data/pages/edit/edit.ts b/src/addons/mod/data/pages/edit/edit.ts index 5af31f6ed..74f60c73f 100644 --- a/src/addons/mod/data/pages/edit/edit.ts +++ b/src/addons/mod/data/pages/edit/edit.ts @@ -110,7 +110,7 @@ export class AddonModDataEditPage implements OnInit { } // If entryId is lower than 0 or null, it is a new entry or an offline entry. - this.isEditing = typeof this.entryId != 'undefined' && this.entryId > 0; + this.isEditing = this.entryId !== undefined && this.entryId > 0; this.title = this.module.name; diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index 95e37b326..df8ebb5be 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -98,7 +98,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { // Refresh data if this discussion is synchronized automatically. this.syncObserver = CoreEvents.on(AddonModDataSyncProvider.AUTO_SYNCED, (data) => { - if (typeof data.entryId == 'undefined') { + if (data.entryId === undefined) { return; } @@ -299,7 +299,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { * @return Resolved when done. */ protected async setEntryFromOffset(): Promise { - if (typeof this.offset == 'undefined' && typeof this.entryId != 'undefined') { + if (this.offset === undefined && this.entryId !== undefined) { // Entry id passed as navigation parameter instead of the offset. // We don't display next/previous buttons in this case. this.hasNext = false; @@ -313,7 +313,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { } const perPage = AddonModDataProvider.PER_PAGE; - const page = typeof this.offset != 'undefined' && this.offset >= 0 + const page = this.offset !== undefined && this.offset >= 0 ? Math.floor(this.offset / perPage) : 0; @@ -329,7 +329,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { // Index of the entry when concatenating offline and online page entries. let pageIndex = 0; - if (typeof this.offset == 'undefined') { + if (this.offset === undefined) { // No offset passed, display the first entry. pageIndex = 0; } else if (this.offset > 0) { diff --git a/src/addons/mod/data/services/data-helper.ts b/src/addons/mod/data/services/data-helper.ts index 869f2be38..18fa06b70 100644 --- a/src/addons/mod/data/services/data-helper.ts +++ b/src/addons/mod/data/services/data-helper.ts @@ -86,7 +86,7 @@ export class AddonModDataHelperProvider { record.groupid = action.groupid; action.fields.forEach((offlineContent) => { - if (typeof offlineContents[offlineContent.fieldid] == 'undefined') { + if (offlineContents[offlineContent.fieldid] === undefined) { offlineContents[offlineContent.fieldid] = {}; } @@ -270,7 +270,7 @@ export class AddonModDataHelperProvider { result.hasOfflineActions = !!actions.length; actions.forEach((action) => { - if (typeof offlineActions[action.entryid] == 'undefined') { + if (offlineActions[action.entryid] === undefined) { offlineActions[action.entryid] = []; } offlineActions[action.entryid].push(action); diff --git a/src/addons/mod/data/services/data-offline.ts b/src/addons/mod/data/services/data-offline.ts index 19d8638fe..67fdb5b78 100644 --- a/src/addons/mod/data/services/data-offline.ts +++ b/src/addons/mod/data/services/data-offline.ts @@ -262,7 +262,7 @@ export class AddonModDataOfflineProvider { const site = await CoreSites.getSite(siteId); timemodified = timemodified || new Date().getTime(); - entryId = typeof entryId == 'undefined' || entryId === null ? -timemodified : entryId; + entryId = entryId === undefined || entryId === null ? -timemodified : entryId; const entry: AddonModDataEntryDBRecord = { dataid: dataId, diff --git a/src/addons/mod/data/services/data-sync.ts b/src/addons/mod/data/services/data-sync.ts index 9a947ffcb..1549bf5f9 100644 --- a/src/addons/mod/data/services/data-sync.ts +++ b/src/addons/mod/data/services/data-sync.ts @@ -197,7 +197,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider const offlineEntries: Record = {}; offlineActions.forEach((entry) => { - if (typeof offlineEntries[entry.entryid] == 'undefined') { + if (offlineEntries[entry.entryid] === undefined) { offlineEntries[entry.entryid] = []; } diff --git a/src/addons/mod/data/services/data.ts b/src/addons/mod/data/services/data.ts index 4dd6ce8e8..8c7e4e993 100644 --- a/src/addons/mod/data/services/data.ts +++ b/src/addons/mod/data/services/data.ts @@ -188,7 +188,7 @@ export class AddonModDataProvider { data, }; - if (typeof groupId !== 'undefined') { + if (groupId !== undefined) { params.groupid = groupId; } @@ -1004,16 +1004,16 @@ export class AddonModDataProvider { componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; - if (typeof options.sort != 'undefined') { + if (options.sort !== undefined) { params.sort = options.sort; } - if (typeof options.order !== 'undefined') { + if (options.order !== undefined) { params.order = options.order; } - if (typeof options.search !== 'undefined') { + if (options.search !== undefined) { params.search = options.search; } - if (typeof options.advSearch !== 'undefined') { + if (options.advSearch !== undefined) { params.advsearch = options.advSearch; } const response = await site.read('mod_data_search_entries', params, preSets); diff --git a/src/addons/mod/data/services/handlers/approve-link.ts b/src/addons/mod/data/services/handlers/approve-link.ts index 5d3072634..f6802bca2 100644 --- a/src/addons/mod/data/services/handlers/approve-link.ts +++ b/src/addons/mod/data/services/handlers/approve-link.ts @@ -50,7 +50,7 @@ export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandl * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Params): Promise { - if (typeof params.d == 'undefined' || (typeof params.approve == 'undefined' && typeof params.disapprove == 'undefined')) { + if (params.d === undefined || (params.approve === undefined && params.disapprove === undefined)) { // Required fields not defined. Cannot treat the URL. return false; } diff --git a/src/addons/mod/data/services/handlers/delete-link.ts b/src/addons/mod/data/services/handlers/delete-link.ts index e17e662b6..71b0d8125 100644 --- a/src/addons/mod/data/services/handlers/delete-link.ts +++ b/src/addons/mod/data/services/handlers/delete-link.ts @@ -48,7 +48,7 @@ export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandle * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Params): Promise { - if (typeof params.d == 'undefined' || typeof params.delete == 'undefined') { + if (params.d === undefined || params.delete === undefined) { // Required fields not defined. Cannot treat the URL. return false; } diff --git a/src/addons/mod/data/services/handlers/edit-link.ts b/src/addons/mod/data/services/handlers/edit-link.ts index e759b20e2..de515049c 100644 --- a/src/addons/mod/data/services/handlers/edit-link.ts +++ b/src/addons/mod/data/services/handlers/edit-link.ts @@ -66,7 +66,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Params): Promise { - if (typeof params.d == 'undefined') { + if (params.d === undefined) { // Id not defined. Cannot treat the URL. return false; } diff --git a/src/addons/mod/data/services/handlers/show-link.ts b/src/addons/mod/data/services/handlers/show-link.ts index f1279506a..1804755af 100644 --- a/src/addons/mod/data/services/handlers/show-link.ts +++ b/src/addons/mod/data/services/handlers/show-link.ts @@ -77,12 +77,12 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Params): Promise { - if (typeof params.d == 'undefined') { + if (params.d === undefined) { // Id not defined. Cannot treat the URL. return false; } - if ((!params.mode || params.mode != 'single') && typeof params.rid == 'undefined') { + if ((!params.mode || params.mode != 'single') && params.rid === undefined) { return false; } diff --git a/src/addons/mod/feedback/components/index/index.ts b/src/addons/mod/feedback/components/index/index.ts index 3e77a7941..bfa04b763 100644 --- a/src/addons/mod/feedback/components/index/index.ts +++ b/src/addons/mod/feedback/components/index/index.ts @@ -299,7 +299,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity item.data = item.data.map((dataItem) => { const parsed = > CoreTextUtils.parseJSON(dataItem); - return typeof parsed.show != 'undefined' ? parsed.show : false; + return parsed.show !== undefined ? parsed.show : false; }).filter((dataItem) => dataItem); // Filter false entries. case 'textfield': @@ -312,7 +312,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity const parsedData = []> item.data.map((dataItem) => { const parsed = > CoreTextUtils.parseJSON(dataItem); - return typeof parsed.answertext != 'undefined' ? parsed : false; + return parsed.answertext !== undefined ? parsed : false; }).filter((dataItem) => dataItem); // Filter false entries. // Format labels. @@ -320,7 +320,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity dataItem.quotient = ( dataItem.quotient * 100).toFixed(2); let label = ''; - if (typeof dataItem.value != 'undefined') { + if (dataItem.value !== undefined) { label = '(' + dataItem.value + ') '; } label += dataItem.answertext; diff --git a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts index 12d312bc0..db568a32a 100644 --- a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts +++ b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts @@ -100,7 +100,7 @@ export class AddonModFeedbackNonRespondentsPage implements OnInit { protected async loadGroupUsers(groupId?: number): Promise { this.loadMoreError = false; - if (typeof groupId == 'undefined') { + if (groupId === undefined) { this.page++; } else { this.selectedGroup = groupId; diff --git a/src/addons/mod/feedback/pages/respondents/respondents.ts b/src/addons/mod/feedback/pages/respondents/respondents.ts index 3ef2266a7..73a95a75f 100644 --- a/src/addons/mod/feedback/pages/respondents/respondents.ts +++ b/src/addons/mod/feedback/pages/respondents/respondents.ts @@ -115,7 +115,7 @@ export class AddonModFeedbackRespondentsPage implements AfterViewInit { * @return Resolved with the attempts loaded. */ protected async loadGroupAttempts(groupId?: number): Promise { - if (typeof groupId == 'undefined') { + if (groupId === undefined) { this.page++; this.loadingMore = true; } else { diff --git a/src/addons/mod/feedback/services/feedback-helper.ts b/src/addons/mod/feedback/services/feedback-helper.ts index 05751c7f5..bb0e6d6af 100644 --- a/src/addons/mod/feedback/services/feedback-helper.ts +++ b/src/addons/mod/feedback/services/feedback-helper.ts @@ -178,7 +178,7 @@ export class AddonModFeedbackHelperProvider { try { const module = await CoreCourse.getModuleBasicInfo(Number(params.id), siteId); - if (typeof params.showcompleted == 'undefined') { + if (params.showcompleted === undefined) { // Param showcompleted not defined. Show entry list. await CoreNavigator.navigateToSitePath( AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/respondents`, @@ -269,7 +269,7 @@ export class AddonModFeedbackHelperProvider { if (type == MODE_COURSE || type == MODE_CATEGORY) { formItem.presentation = formItem.otherdata; - formItem.value = typeof formItem.rawValue != 'undefined' ? formItem.rawValue : formItem.otherdata; + formItem.value = formItem.rawValue !== undefined ? formItem.rawValue : formItem.otherdata; } else if (type == MODE_RESPONSETIME) { formItem.value = '__CURRENT__TIMESTAMP__'; @@ -298,7 +298,7 @@ export class AddonModFeedbackHelperProvider { const formItem: AddonModFeedbackNumericItem = Object.assign(item, { templateName: 'numeric', - value: typeof item.rawValue != 'undefined' ? Number(item.rawValue) : '', + value: item.rawValue !== undefined ? Number(item.rawValue) : '', rangefrom: typeof rangeFrom == 'number' && !isNaN(rangeFrom) ? range[0] : '', rangeto: typeof rangeTo == 'number' && !isNaN(rangeTo) ? rangeTo : '', hasTextInput: true, @@ -318,7 +318,7 @@ export class AddonModFeedbackHelperProvider { return Object.assign(item, { templateName: 'textfield', length: Number(item.presentation.split(AddonModFeedbackProvider.LINE_SEP)[1]) || 255, - value: typeof item.rawValue != 'undefined' ? item.rawValue : '', + value: item.rawValue !== undefined ? item.rawValue : '', hasTextInput: true, }); } @@ -332,7 +332,7 @@ export class AddonModFeedbackHelperProvider { protected getItemFormTextarea(item: AddonModFeedbackItem): AddonModFeedbackFormBasicItem { return Object.assign(item, { templateName: 'textarea', - value: typeof item.rawValue != 'undefined' ? item.rawValue : '', + value: item.rawValue !== undefined ? item.rawValue : '', hasTextInput: true, }); } @@ -373,12 +373,12 @@ export class AddonModFeedbackHelperProvider { if (formItem.subtype === 'r' && formItem.options.search(AddonModFeedbackProvider.MULTICHOICE_HIDENOSELECT) == -1) { formItem.choices.unshift({ value: 0, label: Translate.instant('addon.mod_feedback.not_selected') }); - formItem.value = typeof formItem.rawValue != 'undefined' ? Number(formItem.rawValue) : 0; + formItem.value = formItem.rawValue !== undefined ? Number(formItem.rawValue) : 0; } else if (formItem.subtype === 'd') { formItem.choices.unshift({ value: 0, label: '' }); - formItem.value = typeof formItem.rawValue != 'undefined' ? Number(formItem.rawValue) : 0; + formItem.value = formItem.rawValue !== undefined ? Number(formItem.rawValue) : 0; } else if (formItem.subtype === 'c') { - if (typeof formItem.rawValue != 'undefined') { + if (formItem.rawValue !== undefined) { formItem.rawValue = String(formItem.rawValue); const values = formItem.rawValue.split(AddonModFeedbackProvider.LINE_SEP); formItem.choices.forEach((choice) => { @@ -392,7 +392,7 @@ export class AddonModFeedbackHelperProvider { }); } } else { - formItem.value = typeof formItem.rawValue != 'undefined' ? Number(formItem.rawValue) : ''; + formItem.value = formItem.rawValue !== undefined ? Number(formItem.rawValue) : ''; } return formItem; diff --git a/src/addons/mod/feedback/services/feedback.ts b/src/addons/mod/feedback/services/feedback.ts index c1a254df3..814640e9f 100644 --- a/src/addons/mod/feedback/services/feedback.ts +++ b/src/addons/mod/feedback/services/feedback.ts @@ -87,7 +87,7 @@ export class AddonModFeedbackProvider { let values: AddonModFeedbackResponseValue[]; if (subtype === 'c') { - if (typeof item.rawValue == 'undefined') { + if (item.rawValue === undefined) { values = ['']; } else { item.rawValue = '' + item.rawValue; @@ -146,7 +146,7 @@ export class AddonModFeedbackProvider { }); filledItems.forEach((itemData) => { - if (itemData.hasvalue && typeof values[itemData.id] != 'undefined') { + if (itemData.hasvalue && values[itemData.id] !== undefined) { itemData.rawValue = values[itemData.id]; } }); @@ -182,7 +182,7 @@ export class AddonModFeedbackProvider { }); offlineValuesArray.forEach((value) => { - if (typeof offlineValues[value.item] == 'undefined') { + if (offlineValues[value.item] === undefined) { offlineValues[value.item] = []; } offlineValues[value.item].push(value.value); diff --git a/src/addons/mod/feedback/services/handlers/analysis-link.ts b/src/addons/mod/feedback/services/handlers/analysis-link.ts index 8081f4bee..58a015234 100644 --- a/src/addons/mod/feedback/services/handlers/analysis-link.ts +++ b/src/addons/mod/feedback/services/handlers/analysis-link.ts @@ -78,7 +78,7 @@ export class AddonModFeedbackAnalysisLinkHandlerService extends CoreContentLinks * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record): Promise { - if (typeof params.id == 'undefined') { + if (params.id === undefined) { // Cannot treat the URL. return false; } diff --git a/src/addons/mod/feedback/services/handlers/complete-link.ts b/src/addons/mod/feedback/services/handlers/complete-link.ts index f0bc0ac94..1415653fd 100644 --- a/src/addons/mod/feedback/services/handlers/complete-link.ts +++ b/src/addons/mod/feedback/services/handlers/complete-link.ts @@ -49,7 +49,7 @@ export class AddonModFeedbackCompleteLinkHandlerService extends CoreContentLinks AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/form`, { params: { - page: typeof params.gopage != 'undefined' ? Number(params.gopage) : undefined, + page: params.gopage !== undefined ? Number(params.gopage) : undefined, }, siteId, }, @@ -67,7 +67,7 @@ export class AddonModFeedbackCompleteLinkHandlerService extends CoreContentLinks * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record): Promise { - if (typeof params.id == 'undefined') { + if (params.id === undefined) { return false; } diff --git a/src/addons/mod/feedback/services/handlers/print-link.ts b/src/addons/mod/feedback/services/handlers/print-link.ts index 1a287d5ad..20205347c 100644 --- a/src/addons/mod/feedback/services/handlers/print-link.ts +++ b/src/addons/mod/feedback/services/handlers/print-link.ts @@ -67,7 +67,7 @@ export class AddonModFeedbackPrintLinkHandlerService extends CoreContentLinksHan * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record): Promise { - if (typeof params.id == 'undefined') { + if (params.id === undefined) { return false; } diff --git a/src/addons/mod/feedback/services/handlers/show-entries-link.ts b/src/addons/mod/feedback/services/handlers/show-entries-link.ts index 1d1f857d4..30f3b7c15 100644 --- a/src/addons/mod/feedback/services/handlers/show-entries-link.ts +++ b/src/addons/mod/feedback/services/handlers/show-entries-link.ts @@ -44,7 +44,7 @@ export class AddonModFeedbackShowEntriesLinkHandlerService extends CoreContentLi * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record): Promise { - if (typeof params.id == 'undefined') { + if (params.id === undefined) { // Cannot treat the URL. return false; } diff --git a/src/addons/mod/feedback/services/handlers/show-non-respondents-link.ts b/src/addons/mod/feedback/services/handlers/show-non-respondents-link.ts index cccaadcad..992b9be0d 100644 --- a/src/addons/mod/feedback/services/handlers/show-non-respondents-link.ts +++ b/src/addons/mod/feedback/services/handlers/show-non-respondents-link.ts @@ -61,7 +61,7 @@ export class AddonModFeedbackShowNonRespondentsLinkHandlerService extends CoreCo * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record): Promise { - if (typeof params.id == 'undefined') { + if (params.id === undefined) { // Cannot treat the URL. return false; } diff --git a/src/addons/mod/forum/classes/forum-discussions-source.ts b/src/addons/mod/forum/classes/forum-discussions-source.ts index 26bd22967..7ef18281f 100644 --- a/src/addons/mod/forum/classes/forum-discussions-source.ts +++ b/src/addons/mod/forum/classes/forum-discussions-source.ts @@ -128,7 +128,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource async loadForum(): Promise { this.forum = await AddonModForum.getForum(this.COURSE_ID, this.CM_ID); - if (typeof this.forum.istracked != 'undefined') { + if (this.forum.istracked !== undefined) { this.trackPosts = this.forum.istracked; } } @@ -192,7 +192,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource } // If any discussion has unread posts, the whole forum is being tracked. - if (typeof this.forum.istracked === 'undefined' && !this.trackPosts) { + if (this.forum.istracked === undefined && !this.trackPosts) { for (const discussion of discussions) { if (discussion.numunread > 0) { this.trackPosts = true; diff --git a/src/addons/mod/forum/components/index/index.ts b/src/addons/mod/forum/components/index/index.ts index 696f762da..9afeb028e 100644 --- a/src/addons/mod/forum/components/index/index.ts +++ b/src/addons/mod/forum/components/index/index.ts @@ -218,13 +218,13 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom ) as AddonModForumDiscussion; if (discussion) { - if (typeof data.locked != 'undefined') { + if (data.locked !== undefined) { discussion.locked = data.locked; } - if (typeof data.pinned != 'undefined') { + if (data.pinned !== undefined) { discussion.pinned = data.pinned; } - if (typeof data.starred != 'undefined') { + if (data.starred !== undefined) { discussion.starred = data.starred; } @@ -232,7 +232,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom } } - if (typeof data.deleted != 'undefined' && data.deleted) { + if (data.deleted !== undefined && data.deleted) { if (data.post?.parentid == 0 && CoreScreen.isTablet && !this.discussions.empty) { // Discussion deleted, clear details page. this.discussions.select(this.discussions[0]); diff --git a/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts b/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts index fd1662e5a..ad13a1e84 100644 --- a/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts +++ b/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts @@ -69,7 +69,7 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy return; } - if (typeof this.post.capabilities.delete == 'undefined') { + if (this.post.capabilities.delete === undefined) { if (this.forumId) { try { this.post = diff --git a/src/addons/mod/forum/pages/discussion/discussion.page.ts b/src/addons/mod/forum/pages/discussion/discussion.page.ts index 0b6428ae0..12bf5c553 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.page.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.page.ts @@ -254,17 +254,17 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes this.changeDiscObserver = CoreEvents.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, data => { if (discussion && this.forumId && (this.forumId === data.forumId || data.cmId === this.cmId)) { AddonModForum.invalidateDiscussionsList(this.forumId).finally(() => { - if (typeof data.locked != 'undefined') { + if (data.locked !== undefined) { discussion.locked = data.locked; } - if (typeof data.pinned != 'undefined') { + if (data.pinned !== undefined) { discussion.pinned = data.pinned; } - if (typeof data.starred != 'undefined') { + if (data.starred !== undefined) { discussion.starred = data.starred; } - if (typeof data.deleted != 'undefined' && data.deleted) { + if (data.deleted !== undefined && data.deleted) { if (!data.post?.parentid) { this.goBack(); } else { @@ -469,7 +469,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes // Now try to get the forum. const forum = await this.fetchForum(); // "forum.istracked" is more reliable than "trackPosts". - if (typeof forum.istracked != 'undefined') { + if (forum.istracked !== undefined) { this.trackPosts = forum.istracked; } diff --git a/src/addons/mod/forum/services/forum-sync.ts b/src/addons/mod/forum/services/forum-sync.ts index 65925b3d7..f033e9d22 100644 --- a/src/addons/mod/forum/services/forum-sync.ts +++ b/src/addons/mod/forum/services/forum-sync.ts @@ -379,7 +379,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide // Do not sync same discussion twice. replies.forEach((reply) => { - if (typeof promises[reply.discussionid] != 'undefined') { + if (promises[reply.discussionid] !== undefined) { return; } promises[reply.discussionid] = this.syncDiscussionReplies(reply.discussionid, userId, siteId); diff --git a/src/addons/mod/forum/services/forum.ts b/src/addons/mod/forum/services/forum.ts index 131706f96..fb1b53bbd 100644 --- a/src/addons/mod/forum/services/forum.ts +++ b/src/addons/mod/forum/services/forum.ts @@ -253,11 +253,11 @@ export class AddonModForumProvider { throw new Error('Invalid response calling mod_forum_can_add_discussion'); } - if (typeof result.canpindiscussions == 'undefined') { + if (result.canpindiscussions === undefined) { // WS doesn't support it yet, default it to false to prevent students from seeing the option. result.canpindiscussions = false; } - if (typeof result.cancreateattachment == 'undefined') { + if (result.cancreateattachment === undefined) { // WS doesn't support it yet, default it to true since usually the users will be able to create them. result.cancreateattachment = true; } @@ -816,7 +816,7 @@ export class AddonModForumProvider { discussions: [] as AddonModForumDiscussion[], error: false, }; - let numPages = typeof options.numPages == 'undefined' ? -1 : options.numPages; + let numPages = options.numPages === undefined ? -1 : options.numPages; if (!numPages) { return result; diff --git a/src/addons/mod/forum/services/handlers/post-link.ts b/src/addons/mod/forum/services/handlers/post-link.ts index 7aa3042f3..79002b558 100644 --- a/src/addons/mod/forum/services/handlers/post-link.ts +++ b/src/addons/mod/forum/services/handlers/post-link.ts @@ -78,7 +78,7 @@ export class AddonModForumPostLinkHandlerService extends CoreContentLinksHandler * @return Whether the handler is enabled for the URL and site. */ async isEnabled(siteId: string, url: string, params: Params): Promise { - return typeof params.forum != 'undefined'; + return params.forum !== undefined; } } diff --git a/src/addons/mod/glossary/services/glossary-helper.ts b/src/addons/mod/glossary/services/glossary-helper.ts index 1e25ddffd..ce1dcc587 100644 --- a/src/addons/mod/glossary/services/glossary-helper.ts +++ b/src/addons/mod/glossary/services/glossary-helper.ts @@ -71,7 +71,7 @@ export class AddonModGlossaryHelperProvider { files: CoreFileEntry[], original?: AddonModGlossaryNewEntryWithFiles, ): boolean { - if (!original || typeof original.concept == 'undefined') { + if (!original || original.concept === undefined) { // There is no original data. return !!(entry.definition || entry.concept || files.length > 0); } diff --git a/src/addons/mod/glossary/services/glossary.ts b/src/addons/mod/glossary/services/glossary.ts index 033adbe77..eeb8ec937 100644 --- a/src/addons/mod/glossary/services/glossary.ts +++ b/src/addons/mod/glossary/services/glossary.ts @@ -583,7 +583,7 @@ export class AddonModGlossaryProvider { try { const data = await this.getStoredDataForEntry(entryId, site.getId()); - if (typeof data.from != 'undefined') { + if (data.from !== undefined) { const response = await CoreUtils.ignoreErrors( this.getEntryFromList(data.glossaryId, entryId, data.from, false, options), ); diff --git a/src/addons/mod/glossary/services/handlers/edit-link.ts b/src/addons/mod/glossary/services/handlers/edit-link.ts index f72ea2667..ffc4b3203 100644 --- a/src/addons/mod/glossary/services/handlers/edit-link.ts +++ b/src/addons/mod/glossary/services/handlers/edit-link.ts @@ -70,7 +70,7 @@ export class AddonModGlossaryEditLinkHandlerService extends CoreContentLinksHand * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record): Promise { - return typeof params.cmid != 'undefined'; + return params.cmid !== undefined; } } diff --git a/src/addons/mod/h5pactivity/services/handlers/report-link.ts b/src/addons/mod/h5pactivity/services/handlers/report-link.ts index ee6b8c9ab..760d0b72e 100644 --- a/src/addons/mod/h5pactivity/services/handlers/report-link.ts +++ b/src/addons/mod/h5pactivity/services/handlers/report-link.ts @@ -56,7 +56,7 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink const module = await CoreCourse.getModuleBasicInfoByInstance(instanceId, 'h5pactivity', siteId); - if (typeof params.attemptid != 'undefined') { + if (params.attemptid !== undefined) { this.openAttemptResults(module.id, Number(params.attemptid), courseId, siteId); } else { const userId = params.userid ? Number(params.userid) : undefined; diff --git a/src/addons/mod/lesson/services/lesson-helper.ts b/src/addons/mod/lesson/services/lesson-helper.ts index cebbb9f88..669a9bd5b 100644 --- a/src/addons/mod/lesson/services/lesson-helper.ts +++ b/src/addons/mod/lesson/services/lesson-helper.ts @@ -416,7 +416,7 @@ export class AddonModLessonHelperProvider { // Treat each option. let controlAdded = false; options.forEach((option) => { - if (typeof option.value == 'undefined') { + if (option.value === undefined) { // Option not valid, ignore it. return; } diff --git a/src/addons/mod/lesson/services/lesson.ts b/src/addons/mod/lesson/services/lesson.ts index a89470d6d..5f78849ec 100644 --- a/src/addons/mod/lesson/services/lesson.ts +++ b/src/addons/mod/lesson/services/lesson.ts @@ -418,11 +418,11 @@ export class AddonModLessonProvider { } // The name was changed to "answer_editor" in 3.7. Before it was just "answer". Support both cases. - if (typeof data['answer_editor[text]'] != 'undefined') { + if (data['answer_editor[text]'] !== undefined) { studentAnswer = data['answer_editor[text]']; } else if (typeof data.answer_editor == 'object') { studentAnswer = (<{text: string}> data.answer_editor).text; - } else if (typeof data['answer[text]'] != 'undefined') { + } else if (data['answer[text]'] !== undefined) { studentAnswer = data['answer[text]']; } else if (typeof data.answer == 'object') { studentAnswer = (<{text: string}> data.answer).text; @@ -505,7 +505,7 @@ export class AddonModLessonProvider { value = CoreTextUtils.decodeHTML(value); userResponse.push(value); - if (typeof answers[id] != 'undefined') { + if (answers[id] !== undefined) { const answer = answers[id]; result.studentanswer += '
' + answer.answer + ' = ' + value; @@ -606,7 +606,7 @@ export class AddonModLessonProvider { nHits++; } else { // Always use the first student wrong answer. - if (typeof wrongPageId == 'undefined') { + if (wrongPageId === undefined) { wrongPageId = answer.jumpto; } // Save the answer id for scoring. @@ -621,7 +621,7 @@ export class AddonModLessonProvider { nCorrect++; // Save the first jumpto. - if (typeof correctPageId == 'undefined') { + if (correctPageId === undefined) { correctPageId = answer.jumpto; } // Save the answer id for scoring. @@ -644,7 +644,7 @@ export class AddonModLessonProvider { } } else { // Only one answer allowed. - if (typeof data.answerid == 'undefined' || (!data.answerid && Number(data.answerid) !== 0)) { + if (data.answerid === undefined || (!data.answerid && Number(data.answerid) !== 0)) { result.noanswer = true; return; @@ -1501,7 +1501,7 @@ export class AddonModLessonProvider { const response = await site.read('mod_lesson_get_lesson', params, preSets); - if (typeof response.lesson.ongoing == 'undefined') { + if (response.lesson.ongoing === undefined) { // Basic data not received, password is wrong. Remove stored password. this.removeStoredPassword(lessonId, site.id); @@ -1788,7 +1788,7 @@ export class AddonModLessonProvider { const jumps: AddonModLessonPossibleJumps = {}; response.jumps.forEach((jump) => { - if (typeof jumps[jump.pageid] == 'undefined') { + if (jumps[jump.pageid] === undefined) { jumps[jump.pageid] = {}; } jumps[jump.pageid][jump.jumpto] = jump; @@ -2886,7 +2886,7 @@ export class AddonModLessonProvider { if (options.pageIndex[lastAttempt.pageid].qtype == AddonModLessonProvider.LESSON_PAGE_ESSAY) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const score: number | undefined = ( lastAttempt.useranswer)?.score; - if (typeof score != 'undefined') { + if (score !== undefined) { result.earned += score; } result.nmanual++; @@ -2917,7 +2917,7 @@ export class AddonModLessonProvider { for (const answerId in answers) { const answer = answers[answerId]; - if (typeof bestScores[answer.pageid] == 'undefined') { + if (bestScores[answer.pageid] === undefined) { bestScores[answer.pageid] = answer.score || 0; } else if (bestScores[answer.pageid] < (answer.score || 0)) { bestScores[answer.pageid] = answer.score || 0; @@ -3271,7 +3271,7 @@ export class AddonModLessonProvider { if (lesson.review && !result.correctanswer && !result.isessayquestion) { // Calculate the number of question attempt in the page if it isn't calculated already. - if (typeof nAttempts == 'undefined') { + if (nAttempts === undefined) { const result = await this.getQuestionsAttempts(lesson.id, retake, { cmId: lesson.coursemodule, pageId: pageData.page.id, diff --git a/src/addons/mod/page/components/index/index.ts b/src/addons/mod/page/components/index/index.ts index 3017d9bf1..a58d49a3a 100644 --- a/src/addons/mod/page/components/index/index.ts +++ b/src/addons/mod/page/components/index/index.ts @@ -113,9 +113,9 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp const options: Record = CoreTextUtils.unserialize(this.page.displayoptions) || {}; - this.displayDescription = typeof options.printintro == 'undefined' || + this.displayDescription = options.printintro === undefined || CoreUtils.isTrueOrOne(options.printintro); - this.displayTimemodified = typeof options.printlastmodified == 'undefined' || + this.displayTimemodified = options.printlastmodified === undefined || CoreUtils.isTrueOrOne(options.printlastmodified); } else { this.displayDescription = true; diff --git a/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts b/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts index 447b336b6..b61c24d84 100644 --- a/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts +++ b/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts @@ -48,7 +48,7 @@ export class AddonModQuizAccessPasswordHandlerService implements AddonModQuizAcc prefetch?: boolean, siteId?: string, ): Promise { - if (typeof preflightData.quizpassword != 'undefined') { + if (preflightData.quizpassword !== undefined) { return; } @@ -134,7 +134,7 @@ export class AddonModQuizAccessPasswordHandlerService implements AddonModQuizAcc siteId?: string, ): Promise { // The password is right, store it to use it automatically in following executions. - if (typeof preflightData.quizpassword != 'undefined') { + if (preflightData.quizpassword !== undefined) { return this.storePassword(quiz.id, preflightData.quizpassword, siteId); } } diff --git a/src/addons/mod/quiz/components/index/index.ts b/src/addons/mod/quiz/components/index/index.ts index 078c97054..92bdfd881 100644 --- a/src/addons/mod/quiz/components/index/index.ts +++ b/src/addons/mod/quiz/components/index/index.ts @@ -615,7 +615,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp await Promise.all(promises); - const grade = typeof this.gradebookData?.grade != 'undefined' ? this.gradebookData.grade : this.bestGrade?.grade; + const grade = this.gradebookData?.grade !== undefined ? this.gradebookData.grade : this.bestGrade?.grade; const quizGrade = AddonModQuiz.formatGrade(grade, quiz.decimalpoints); // Calculate data to construct the header of the attempts table. diff --git a/src/addons/mod/quiz/pages/attempt/attempt.page.ts b/src/addons/mod/quiz/pages/attempt/attempt.page.ts index 85481178d..8906d97f2 100644 --- a/src/addons/mod/quiz/pages/attempt/attempt.page.ts +++ b/src/addons/mod/quiz/pages/attempt/attempt.page.ts @@ -186,7 +186,7 @@ export class AddonModQuizAttemptPage implements OnInit { promises.push(AddonModQuiz.invalidateQuizAccessInformation(this.quiz.id)); promises.push(AddonModQuiz.invalidateCombinedReviewOptionsForUser(this.quiz.id)); - if (this.attempt && typeof this.feedback != 'undefined') { + if (this.attempt && this.feedback !== undefined) { promises.push(AddonModQuiz.invalidateFeedback(this.quiz.id)); } } diff --git a/src/addons/mod/quiz/pages/player/player.page.ts b/src/addons/mod/quiz/pages/player/player.page.ts index c2da33f1b..16e1a22de 100644 --- a/src/addons/mod/quiz/pages/player/player.page.ts +++ b/src/addons/mod/quiz/pages/player/player.page.ts @@ -261,7 +261,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave { if (page != -1 && (this.attempt.state == AddonModQuizProvider.ATTEMPT_OVERDUE || this.attempt.finishedOffline)) { // We can't load a page if overdue or the local attempt is finished. return; - } else if (page == this.attempt.currentpage && !this.showSummary && typeof slot != 'undefined') { + } else if (page == this.attempt.currentpage && !this.showSummary && slot !== undefined) { // Navigating to a question in the current page. this.scrollToQuestion(slot); @@ -317,7 +317,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave { } finally { this.loaded = true; - if (typeof slot != 'undefined') { + if (slot !== undefined) { // Scroll to the question. Give some time to the questions to render. setTimeout(() => { this.scrollToQuestion(slot); diff --git a/src/addons/mod/quiz/pages/review/review.page.ts b/src/addons/mod/quiz/pages/review/review.page.ts index 98d01d3da..07fb1c5cd 100644 --- a/src/addons/mod/quiz/pages/review/review.page.ts +++ b/src/addons/mod/quiz/pages/review/review.page.ts @@ -116,7 +116,7 @@ export class AddonModQuizReviewPage implements OnInit { * @param slot Slot of the question to scroll to. */ async changePage(page: number, fromModal?: boolean, slot?: number): Promise { - if (typeof slot != 'undefined' && (this.attempt!.currentpage == -1 || page == this.currentPage)) { + if (slot !== undefined && (this.attempt!.currentpage == -1 || page == this.currentPage)) { // Scrol to a certain question in the current page. this.scrollToQuestion(slot); @@ -136,7 +136,7 @@ export class AddonModQuizReviewPage implements OnInit { } finally { this.loaded = true; - if (typeof slot != 'undefined') { + if (slot !== undefined) { // Scroll to the question. Give some time to the questions to render. setTimeout(() => { this.scrollToQuestion(slot); @@ -286,7 +286,7 @@ export class AddonModQuizReviewPage implements OnInit { if (this.options!.someoptions.marks >= AddonModQuizProvider.QUESTION_OPTIONS_MARK_AND_MAX && AddonModQuiz.quizHasGrades(this.quiz)) { - if (data.grade === null || typeof data.grade == 'undefined') { + if (data.grade === null || data.grade === undefined) { this.readableGrade = AddonModQuiz.formatGrade(data.grade, this.quiz.decimalpoints); } else { // Show raw marks only if they are different from the grade (like on the entry page). diff --git a/src/addons/mod/quiz/services/handlers/prefetch.ts b/src/addons/mod/quiz/services/handlers/prefetch.ts index 47b61b959..e1d035e83 100644 --- a/src/addons/mod/quiz/services/handlers/prefetch.ts +++ b/src/addons/mod/quiz/services/handlers/prefetch.ts @@ -120,7 +120,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet } const attemptGrade = AddonModQuiz.rescaleGrade(attempt.sumgrades, quiz, false); - if (typeof attemptGrade == 'undefined') { + if (attemptGrade === undefined) { return; } @@ -421,7 +421,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet if (AddonModQuiz.isAttemptFinished(attempt.state)) { // Attempt is finished, get feedback and review data. const attemptGrade = AddonModQuiz.rescaleGrade(attempt.sumgrades, quiz, false); - if (typeof attemptGrade != 'undefined') { + if (attemptGrade !== undefined) { promises.push(AddonModQuiz.getFeedbackForGrade(quiz.id, Number(attemptGrade), modOptions)); } diff --git a/src/addons/mod/quiz/services/quiz.ts b/src/addons/mod/quiz/services/quiz.ts index c3cc895df..bc8793596 100644 --- a/src/addons/mod/quiz/services/quiz.ts +++ b/src/addons/mod/quiz/services/quiz.ts @@ -425,7 +425,7 @@ export class AddonModQuizProvider { attemptId: number, options: AddonModQuizGetAttemptReviewOptions = {}, ): Promise { - const page = typeof options.page == 'undefined' ? -1 : options.page; + const page = options.page === undefined ? -1 : options.page; const site = await CoreSites.getSite(options.siteId); @@ -620,7 +620,7 @@ export class AddonModQuizProvider { * @return Number of decimals. */ getGradeDecimals(quiz: AddonModQuizQuizWSData): number { - if (typeof quiz.questiondecimalpoints == 'undefined') { + if (quiz.questiondecimalpoints === undefined) { quiz.questiondecimalpoints = -1; } @@ -1029,7 +1029,7 @@ export class AddonModQuizProvider { ): Promise { const status = options.status || 'all'; - const includePreviews = typeof options.includePreviews == 'undefined' ? true : options.includePreviews; + const includePreviews = options.includePreviews === undefined ? true : options.includePreviews; const site = await CoreSites.getSite(options.siteId); diff --git a/src/addons/mod/resource/components/index/index.ts b/src/addons/mod/resource/components/index/index.ts index a3a29b038..8b95a597a 100644 --- a/src/addons/mod/resource/components/index/index.ts +++ b/src/addons/mod/resource/components/index/index.ts @@ -116,7 +116,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource resource.displayoptions ? CoreTextUtils.unserialize(resource.displayoptions) : {}; try { - this.displayDescription = typeof options.printintro == 'undefined' || !!options.printintro; + this.displayDescription = options.printintro === undefined || !!options.printintro; this.dataRetrieved.emit(resource); if (AddonModResourceHelper.isDisplayedInIframe(this.module)) { diff --git a/src/addons/mod/scorm/components/index/index.ts b/src/addons/mod/scorm/components/index/index.ts index 945ba9112..44985f6d1 100644 --- a/src/addons/mod/scorm/components/index/index.ts +++ b/src/addons/mod/scorm/components/index/index.ts @@ -203,7 +203,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom this.accessInfo = accessInfo; // Check whether to launch the SCORM immediately. - if (typeof this.skip == 'undefined') { + if (this.skip === undefined) { this.skip = !this.hasOffline && !this.errorMessage && (!this.scorm.lastattemptlock || this.attemptsLeft > 0) && this.accessInfo.canskipview && !this.accessInfo.canviewreport && diff --git a/src/addons/mod/scorm/services/scorm-offline.ts b/src/addons/mod/scorm/services/scorm-offline.ts index 2971656e9..9f9874486 100644 --- a/src/addons/mod/scorm/services/scorm-offline.ts +++ b/src/addons/mod/scorm/services/scorm-offline.ts @@ -682,7 +682,7 @@ export class AddonModScormOfflineProvider { scoid: scoId, attempt, element: element, - value: typeof value == 'undefined' ? null : JSON.stringify(value), + value: value === undefined ? null : JSON.stringify(value), timemodified: CoreTimeUtils.timestamp(), synced: 0, }; @@ -937,7 +937,7 @@ export class AddonModScormOfflineProvider { param: string, ifEmpty: AddonModScormDataValue = '', ): AddonModScormDataValue { - if (typeof userData[param] != 'undefined') { + if (userData[param] !== undefined) { return userData[param]; } diff --git a/src/addons/mod/scorm/services/scorm-sync.ts b/src/addons/mod/scorm/services/scorm-sync.ts index 5c9e1f158..520864d6e 100644 --- a/src/addons/mod/scorm/services/scorm-sync.ts +++ b/src/addons/mod/scorm/services/scorm-sync.ts @@ -476,7 +476,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide await this.syncScorm(scorm, siteId) : await this.syncScormIfNeeded(scorm, siteId); - if (typeof data != 'undefined') { + if (data !== undefined) { // We tried to sync. Send event. CoreEvents.trigger(AddonModScormSyncProvider.AUTO_SYNCED, { scormId: scorm.id, diff --git a/src/addons/mod/scorm/services/scorm.ts b/src/addons/mod/scorm/services/scorm.ts index a5cd5ecb9..528e68c6a 100644 --- a/src/addons/mod/scorm/services/scorm.ts +++ b/src/addons/mod/scorm/services/scorm.ts @@ -331,7 +331,7 @@ export class AddonModScormProvider { set.forEach((setElement) => { setElement = setElement.trim(); - if (typeof trackData[setElement] != 'undefined' && + if (trackData[setElement] !== undefined && (trackData[setElement].status == 'completed' || trackData[setElement].status == 'passed')) { count++; } @@ -350,11 +350,11 @@ export class AddonModScormProvider { matches = element.match(reOther)!; element = matches[1].trim(); - if (typeof trackData[element] != 'undefined') { + if (trackData[element] !== undefined) { let value = matches[3].trim().replace(/('|")/gi, ''); let oper: string; - if (typeof STATUSES[value] != 'undefined') { + if (STATUSES[value] !== undefined) { value = STATUSES[value]; } @@ -370,7 +370,7 @@ export class AddonModScormProvider { } } else { // Everything else must be an element defined like S45 ... - if (typeof trackData[element] != 'undefined' && + if (trackData[element] !== undefined && (trackData[element].status == 'completed' || trackData[element].status == 'passed')) { element = 'true'; } else { @@ -395,7 +395,7 @@ export class AddonModScormProvider { * @return Grade to display. */ formatGrade(scorm: AddonModScormScorm, grade: number): string { - if (typeof grade == 'undefined' || grade == -1) { + if (grade === undefined || grade == -1) { return Translate.instant('core.none'); } @@ -607,8 +607,8 @@ export class AddonModScormProvider { attemptScore.scos++; } - if (userData.score_raw || (typeof scorm.scormtype != 'undefined' && - scorm.scormtype == 'sco' && typeof userData.score_raw != 'undefined')) { + if (userData.score_raw || (scorm.scormtype !== undefined && + scorm.scormtype == 'sco' && userData.score_raw !== undefined)) { const scoreRaw = parseFloat( userData.score_raw); attemptScore.values++; @@ -912,14 +912,14 @@ export class AddonModScormProvider { } // Check isvisible attribute. - sco.isvisible = typeof scoData.isvisible == 'undefined' || (!!scoData.isvisible && scoData.isvisible !== 'false'); + sco.isvisible = scoData.isvisible === undefined || (!!scoData.isvisible && scoData.isvisible !== 'false'); // Check pre-requisites status. - sco.prereq = typeof scoData.prerequisites == 'undefined' || + sco.prereq = scoData.prerequisites === undefined || this.evalPrerequisites( scoData.prerequisites, trackDataBySCO); // Add status. - sco.status = (typeof scoData.status == 'undefined' || scoData.status === '') ? 'notattempted' : scoData.status; + sco.status = (scoData.status === undefined || scoData.status === '') ? 'notattempted' : scoData.status; // Exit var. - sco.exitvar = typeof scoData.exitvar == 'undefined' ? 'cmi.core.exit' : scoData.exitvar; + sco.exitvar = scoData.exitvar === undefined ? 'cmi.core.exit' : scoData.exitvar; sco.exitvalue = scoData[sco.exitvar]; // Copy score. sco.scoreraw = scoData.score_raw; @@ -1109,7 +1109,7 @@ export class AddonModScormProvider { } // If the SCORM isn't available the WS returns a warning and it doesn't return timeopen and timeclosed. - if (typeof currentScorm.timeopen == 'undefined') { + if (currentScorm.timeopen === undefined) { const warning = response.warnings?.find(warning => warning.itemid === currentScorm.id); currentScorm.warningMessage = warning?.message; } @@ -1339,7 +1339,7 @@ export class AddonModScormProvider { * @return Whether the SCORM is downloadable. */ isScormDownloadable(scorm: AddonModScormScorm): boolean { - return typeof scorm.protectpackagedownloads != 'undefined' && scorm.protectpackagedownloads === false; + return scorm.protectpackagedownloads !== undefined && scorm.protectpackagedownloads === false; } /** @@ -1635,7 +1635,7 @@ export class AddonModScormProvider { const component = AddonModScormProvider.COMPONENT; - if (typeof isOutdated == 'undefined') { + if (isOutdated === undefined) { // Calculate if it's outdated. const data = await CoreUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, scorm.coursemodule)); diff --git a/src/addons/mod/url/components/index/index.ts b/src/addons/mod/url/components/index/index.ts index e92c6541e..db01da3b2 100644 --- a/src/addons/mod/url/components/index/index.ts +++ b/src/addons/mod/url/components/index/index.ts @@ -92,7 +92,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo if (url.displayoptions) { const unserialized = CoreTextUtils.unserialize(url.displayoptions); - this.displayDescription = typeof unserialized.printintro == 'undefined' || !!unserialized.printintro; + this.displayDescription = unserialized.printintro === undefined || !!unserialized.printintro; } // Try to get module contents, it's needed to get the URL with parameters. diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 1ae8303a8..45ea90277 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -959,28 +959,28 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp candidateSubwikiId = subwiki.id; } - if (typeof candidateSubwikiId != 'undefined') { + if (candidateSubwikiId !== undefined) { if (candidateSubwikiId > 0) { // Subwiki found and created, no need to keep looking. candidateFirstPage = Number(i); break; - } else if (typeof candidateNoFirstPage == 'undefined') { + } else if (candidateNoFirstPage === undefined) { candidateNoFirstPage = Number(i); } - } else if (typeof firstCanEdit == 'undefined') { + } else if (firstCanEdit === undefined) { firstCanEdit = Number(i); } } } let subWikiToTake: number; - if (typeof candidateFirstPage != 'undefined') { + if (candidateFirstPage !== undefined) { // Take the candidate that already has the first page created. subWikiToTake = candidateFirstPage; - } else if (typeof candidateNoFirstPage != 'undefined') { + } else if (candidateNoFirstPage !== undefined) { // No first page created, take the first candidate. subWikiToTake = candidateNoFirstPage; - } else if (typeof firstCanEdit != 'undefined') { + } else if (firstCanEdit !== undefined) { // None selected, take the first the user can edit. subWikiToTake = firstCanEdit; } else { @@ -989,7 +989,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp } const subwiki = subwikiList[subWikiToTake]; - if (typeof subwiki != 'undefined') { + if (subwiki !== undefined) { this.setSelectedWiki(subwiki.id, subwiki.userid, subwiki.groupid); } } @@ -1022,7 +1022,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp // As we loop over each subwiki, add it to the current group subwikiList.forEach((subwiki) => { // Add the subwiki to the currently active grouping. - if (typeof subwiki.canedit == 'undefined') { + if (subwiki.canedit === undefined) { noGrouping.subwikis.push(subwiki); } else if (subwiki.canedit) { myGroupsGrouping.subwikis.push(subwiki); diff --git a/src/addons/mod/wiki/services/handlers/edit-link.ts b/src/addons/mod/wiki/services/handlers/edit-link.ts index 6a164a954..ea0fd3a82 100644 --- a/src/addons/mod/wiki/services/handlers/edit-link.ts +++ b/src/addons/mod/wiki/services/handlers/edit-link.ts @@ -54,7 +54,7 @@ export class AddonModWikiEditLinkHandlerService extends CoreContentLinksHandlerB const module = await CoreCourse.getModuleBasicInfoByInstance(pageContents.wikiid, 'wiki', siteId); let section = ''; - if (typeof params.section != 'undefined') { + if (params.section !== undefined) { section = params.section.replace(/\+/g, ' '); } diff --git a/src/addons/mod/wiki/services/handlers/page-or-map-link.ts b/src/addons/mod/wiki/services/handlers/page-or-map-link.ts index 78bf94f5f..cc9043db3 100644 --- a/src/addons/mod/wiki/services/handlers/page-or-map-link.ts +++ b/src/addons/mod/wiki/services/handlers/page-or-map-link.ts @@ -97,7 +97,7 @@ export class AddonModWikiPageOrMapLinkHandlerService extends CoreContentLinksHan if (params.id && !isMap) { // ID param is more prioritary than pageid in index page, it's a index URL. return false; - } else if (isMap && typeof params.option != 'undefined' && params.option != '5') { + } else if (isMap && params.option !== undefined && params.option != '5') { // Map link but the option isn't "Page list", not supported. return false; } diff --git a/src/addons/mod/wiki/services/wiki.ts b/src/addons/mod/wiki/services/wiki.ts index 580e9f20d..c237c7856 100644 --- a/src/addons/mod/wiki/services/wiki.ts +++ b/src/addons/mod/wiki/services/wiki.ts @@ -58,7 +58,7 @@ export class AddonModWikiProvider { * @param wikiId wiki Id, if not provided all will be cleared. */ clearSubwikiList(wikiId?: number): void { - if (typeof wikiId == 'undefined') { + if (wikiId === undefined) { this.subwikiListsCache = {}; } else { delete this.subwikiListsCache[wikiId]; diff --git a/src/addons/mod/workshop/components/index/index.ts b/src/addons/mod/workshop/components/index/index.ts index 91c8bba44..f3cd51e4d 100644 --- a/src/addons/mod/workshop/components/index/index.ts +++ b/src/addons/mod/workshop/components/index/index.ts @@ -322,7 +322,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity const offlineData = await AddonModWorkshopHelper.applyOfflineData(submission, this.offlineSubmissions); - if (typeof offlineData != 'undefined') { + if (offlineData !== undefined) { this.grades!.push(offlineData); } })); diff --git a/src/addons/mod/workshop/services/handlers/prefetch.ts b/src/addons/mod/workshop/services/handlers/prefetch.ts index ad986d253..7700b19cf 100644 --- a/src/addons/mod/workshop/services/handlers/prefetch.ts +++ b/src/addons/mod/workshop/services/handlers/prefetch.ts @@ -160,7 +160,7 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr return { workshop, groups, - files: files.filter((file) => typeof file !== 'undefined'), + files: files.filter((file) => file !== undefined), }; } catch (error) { if (options.omitFail) { @@ -168,7 +168,7 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr return { workshop, groups, - files: files.filter((file) => typeof file !== 'undefined'), + files: files.filter((file) => file !== undefined), }; } diff --git a/src/addons/mod/workshop/services/workshop-helper.ts b/src/addons/mod/workshop/services/workshop-helper.ts index 7f355f5ac..94eb54851 100644 --- a/src/addons/mod/workshop/services/workshop-helper.ts +++ b/src/addons/mod/workshop/services/workshop-helper.ts @@ -460,7 +460,7 @@ export class AddonModWorkshopHelperProvider { return submission; } - if (typeof submission == 'undefined') { + if (submission === undefined) { submission = { id: 0, workshopid: 0, @@ -559,7 +559,7 @@ export class AddonModWorkshopHelperProvider { return value; } - if (value == null || typeof value == 'undefined') { + if (value == null || value === undefined) { return undefined; } @@ -602,7 +602,7 @@ export class AddonModWorkshopHelperProvider { * @return If grade should be shown or not. */ showGrade(grade?: number|string): boolean { - return typeof grade !== 'undefined' && grade !== null; + return grade !== undefined && grade !== null; } } diff --git a/src/addons/mod/workshop/services/workshop.ts b/src/addons/mod/workshop/services/workshop.ts index 53bc85119..59ab0c196 100644 --- a/src/addons/mod/workshop/services/workshop.ts +++ b/src/addons/mod/workshop/services/workshop.ts @@ -263,8 +263,8 @@ export class AddonModWorkshopProvider { } // Set submission types for Moodle 3.5. - if (typeof workshop.submissiontypetext == 'undefined') { - if (typeof workshop.nattachments != 'undefined' && workshop.nattachments > 0) { + if (workshop.submissiontypetext === undefined) { + if (workshop.nattachments !== undefined && workshop.nattachments > 0) { workshop.submissiontypetext = AddonModWorkshopSubmissionType.SUBMISSION_TYPE_AVAILABLE; workshop.submissiontypefile = AddonModWorkshopSubmissionType.SUBMISSION_TYPE_AVAILABLE; } else { diff --git a/src/addons/notes/pages/list/list.page.ts b/src/addons/notes/pages/list/list.page.ts index 4480fc250..be375f2dd 100644 --- a/src/addons/notes/pages/list/list.page.ts +++ b/src/addons/notes/pages/list/list.page.ts @@ -195,7 +195,7 @@ export class AddonNotesListPage implements OnInit, OnDestroy { }, }); - if (typeof modalData != 'undefined') { + if (modalData !== undefined) { if (modalData.sent && modalData.type) { if (modalData.type != this.type) { diff --git a/src/addons/notes/services/handlers/course-option.ts b/src/addons/notes/services/handlers/course-option.ts index 80ae7da99..646af845c 100644 --- a/src/addons/notes/services/handlers/course-option.ts +++ b/src/addons/notes/services/handlers/course-option.ts @@ -52,7 +52,7 @@ export class AddonNotesCourseOptionHandlerService implements CoreCourseOptionsHa return false; // Not enabled for guests. } - if (navOptions && typeof navOptions.notes != 'undefined') { + if (navOptions && navOptions.notes !== undefined) { return navOptions.notes; } diff --git a/src/addons/notes/services/notes-sync.ts b/src/addons/notes/services/notes-sync.ts index 218b18418..ba85ee026 100644 --- a/src/addons/notes/services/notes-sync.ts +++ b/src/addons/notes/services/notes-sync.ts @@ -75,7 +75,7 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider this.ddQuestion.initObjects.drops; } - if (typeof this.ddQuestion.initObjects.readonly != 'undefined') { + if (this.ddQuestion.initObjects.readonly !== undefined) { this.ddQuestion.readOnly = !!this.ddQuestion.initObjects.readonly; } } else if (this.ddQuestion.amdArgs) { // Moodle version >= 3.6. - if (typeof this.ddQuestion.amdArgs[1] != 'undefined') { + if (this.ddQuestion.amdArgs[1] !== undefined) { this.ddQuestion.readOnly = !!this.ddQuestion.amdArgs[1]; } - if (typeof this.ddQuestion.amdArgs[2] != 'undefined') { + if (this.ddQuestion.amdArgs[2] !== undefined) { this.drops = this.ddQuestion.amdArgs[2]; } } diff --git a/src/addons/qtype/ddmarker/classes/ddmarker.ts b/src/addons/qtype/ddmarker/classes/ddmarker.ts index a8fca0b21..1e747e0de 100644 --- a/src/addons/qtype/ddmarker/classes/ddmarker.ts +++ b/src/addons/qtype/ddmarker/classes/ddmarker.ts @@ -499,7 +499,7 @@ export class AddonQtypeDdMarkerQuestion { const dragging = !!this.doc.dragItemBeingDragged(choiceNo); const coords: number[][] = []; - if (fv !== '' && typeof fv != 'undefined' && fv !== null) { + if (fv !== '' && fv !== undefined && fv !== null) { // Get all the coordinates in the input and add them to the coords list. const coordsStrings = fv.split(';'); diff --git a/src/addons/qtype/ddmarker/component/ddmarker.ts b/src/addons/qtype/ddmarker/component/ddmarker.ts index 547773271..27bd8ca14 100644 --- a/src/addons/qtype/ddmarker/component/ddmarker.ts +++ b/src/addons/qtype/ddmarker/component/ddmarker.ts @@ -64,7 +64,7 @@ export class AddonQtypeDdMarkerComponent extends CoreQuestionBaseComponent imple const ddForm = element.querySelector('.ddform'); this.ddQuestion.text = CoreDomUtils.getContentsOfElement(element, '.qtext'); - if (!ddArea || !ddForm || typeof this.ddQuestion.text == 'undefined') { + if (!ddArea || !ddForm || this.ddQuestion.text === undefined) { this.logger.warn('Aborting because of an error parsing question.', this.ddQuestion.slot); return CoreQuestionHelper.showComponentError(this.onAbort); @@ -82,10 +82,10 @@ export class AddonQtypeDdMarkerComponent extends CoreQuestionBaseComponent imple if (this.ddQuestion.initObjects) { // Moodle version = 3.5. - if (typeof this.ddQuestion.initObjects.dropzones != 'undefined') { + if (this.ddQuestion.initObjects.dropzones !== undefined) { this.dropZones = this.ddQuestion.initObjects.dropzones; } - if (typeof this.ddQuestion.initObjects.readonly != 'undefined') { + if (this.ddQuestion.initObjects.readonly !== undefined) { this.ddQuestion.readOnly = !!this.ddQuestion.initObjects.readonly; } } else if (this.ddQuestion.amdArgs) { @@ -97,12 +97,12 @@ export class AddonQtypeDdMarkerComponent extends CoreQuestionBaseComponent imple nextIndex++; } - if (typeof this.ddQuestion.amdArgs[nextIndex] != 'undefined') { + if (this.ddQuestion.amdArgs[nextIndex] !== undefined) { this.ddQuestion.readOnly = !!this.ddQuestion.amdArgs[nextIndex]; } nextIndex++; - if (typeof this.ddQuestion.amdArgs[nextIndex] != 'undefined') { + if (this.ddQuestion.amdArgs[nextIndex] !== undefined) { this.dropZones = this.ddQuestion.amdArgs[nextIndex]; } } diff --git a/src/addons/qtype/ddwtos/component/ddwtos.ts b/src/addons/qtype/ddwtos/component/ddwtos.ts index bbafd79cc..befd2c3a3 100644 --- a/src/addons/qtype/ddwtos/component/ddwtos.ts +++ b/src/addons/qtype/ddwtos/component/ddwtos.ts @@ -74,7 +74,7 @@ export class AddonQtypeDdwtosComponent extends CoreQuestionBaseComponent impleme this.ddQuestion.answers = answerContainer.outerHTML; this.ddQuestion.text = CoreDomUtils.getContentsOfElement(element, '.qtext'); - if (typeof this.ddQuestion.text == 'undefined') { + if (this.ddQuestion.text === undefined) { this.logger.warn('Aborting because of an error parsing question.', this.ddQuestion.slot); return CoreQuestionHelper.showComponentError(this.onAbort); diff --git a/src/addons/qtype/essay/component/essay.ts b/src/addons/qtype/essay/component/essay.ts index 16e1c75d2..64df2a9fc 100644 --- a/src/addons/qtype/essay/component/essay.ts +++ b/src/addons/qtype/essay/component/essay.ts @@ -45,7 +45,7 @@ export class AddonQtypeEssayComponent extends CoreQuestionBaseComponent implemen * Component being initialized. */ ngOnInit(): void { - this.uploadFilesSupported = typeof this.question?.responsefileareas != 'undefined'; + this.uploadFilesSupported = this.question?.responsefileareas !== undefined; this.initEssayComponent(this.review); this.essayQuestion = this.question; diff --git a/src/addons/qtype/essay/services/handlers/essay.ts b/src/addons/qtype/essay/services/handlers/essay.ts index cb6c91646..707c9737e 100644 --- a/src/addons/qtype/essay/services/handlers/essay.ts +++ b/src/addons/qtype/essay/services/handlers/essay.ts @@ -143,7 +143,7 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler { */ getPreventSubmitMessage(question: CoreQuestionQuestionParsed): string | undefined { const element = CoreDomUtils.convertToElement(question.html); - const uploadFilesSupported = typeof question.responsefileareas != 'undefined'; + const uploadFilesSupported = question.responsefileareas !== undefined; if (!uploadFilesSupported && element.querySelector('div[id*=filemanager]')) { // The question allows attachments. Since the app cannot attach files yet we will prevent submitting the question. @@ -229,7 +229,7 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler { ): number { const hasTextAnswer = !!answers.answer; - const uploadFilesSupported = typeof question.responsefileareas != 'undefined'; + const uploadFilesSupported = question.responsefileareas !== undefined; const allowedOptions = this.getAllowedOptions(question); if (hasTextAnswer && this.checkInputWordCount(question, answers.answer, undefined)) { @@ -281,7 +281,7 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler { component: string, componentId: string | number, ): number { - if (typeof question.responsefileareas == 'undefined') { + if (question.responsefileareas === undefined) { return -1; } @@ -309,7 +309,7 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler { component: string, componentId: string | number, ): boolean { - const uploadFilesSupported = typeof question.responsefileareas != 'undefined'; + const uploadFilesSupported = question.responsefileareas !== undefined; const allowedOptions = this.getAllowedOptions(question); // First check the inline text. @@ -355,7 +355,7 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler { // Search the textarea to get its name. const textarea = element.querySelector('textarea[name*=_answer]'); - if (textarea && typeof answers[textarea.name] != 'undefined') { + if (textarea && answers[textarea.name] !== undefined) { await this.prepareTextAnswer(question, answers, textarea, siteId); } diff --git a/src/addons/userprofilefield/checkbox/services/handlers/checkbox.ts b/src/addons/userprofilefield/checkbox/services/handlers/checkbox.ts index 887770465..643738a62 100644 --- a/src/addons/userprofilefield/checkbox/services/handlers/checkbox.ts +++ b/src/addons/userprofilefield/checkbox/services/handlers/checkbox.ts @@ -56,7 +56,7 @@ export class AddonUserProfileFieldCheckboxHandlerService implements CoreUserProf ): Promise { const name = 'profile_field_' + field.shortname; - if (typeof formValues[name] != 'undefined') { + if (formValues[name] !== undefined) { return { type: 'checkbox', name: name, diff --git a/src/core/classes/base-sync.ts b/src/core/classes/base-sync.ts index 8849ec24c..417b03ff6 100644 --- a/src/core/classes/base-sync.ts +++ b/src/core/classes/base-sync.ts @@ -244,7 +244,7 @@ export class CoreSyncBaseProvider { * @return Promise resolved when the time is set. */ async setSyncTime(id: string | number, siteId?: string, time?: number): Promise { - time = typeof time != 'undefined' ? time : Date.now(); + time = time !== undefined ? time : Date.now(); await CoreSync.insertOrUpdateSyncRecord(this.component, id, { time: time }, siteId); } diff --git a/src/core/classes/cache.ts b/src/core/classes/cache.ts index 833ecac56..325669148 100644 --- a/src/core/classes/cache.ts +++ b/src/core/classes/cache.ts @@ -58,7 +58,7 @@ export class CoreCache { getValue(id: string, name: string, ignoreInvalidate = false): T | undefined { const entry = this.getEntry(id); - if (entry[name] && typeof entry[name].value != 'undefined') { + if (entry[name] && entry[name].value !== undefined) { const now = Date.now(); // Invalidate after 5 minutes. if (ignoreInvalidate || entry[name].timemodified + 300000 >= now) { diff --git a/src/core/classes/delegate.ts b/src/core/classes/delegate.ts index 3e5e7aac3..588f0ce9f 100644 --- a/src/core/classes/delegate.ts +++ b/src/core/classes/delegate.ts @@ -199,7 +199,7 @@ export class CoreDelegate { * @return If the handler is registered or not. */ hasHandler(name: string, enabled: boolean = false): boolean { - return enabled ? typeof this.enabledHandlers[name] !== 'undefined' : typeof this.handlers[name] !== 'undefined'; + return enabled ? this.enabledHandlers[name] !== undefined : this.handlers[name] !== undefined; } /** @@ -226,7 +226,7 @@ export class CoreDelegate { registerHandler(handler: HandlerType): boolean { const key = handler[this.handlerNameProperty] || handler.name; - if (typeof this.handlers[key] !== 'undefined') { + if (this.handlers[key] !== undefined) { this.logger.log(`Handler '${handler[this.handlerNameProperty]}' already registered`); return false; @@ -293,7 +293,7 @@ export class CoreDelegate { * @return Whether is enabled or disabled in site. */ protected isFeatureDisabled(handler: HandlerType, site: CoreSite): boolean { - return typeof this.featurePrefix != 'undefined' && site.isFeatureDisabled(this.featurePrefix + handler.name); + return this.featurePrefix !== undefined && site.isFeatureDisabled(this.featurePrefix + handler.name); } /** diff --git a/src/core/classes/errors/ajaxwserror.ts b/src/core/classes/errors/ajaxwserror.ts index 338a0706a..b21eedd1b 100644 --- a/src/core/classes/errors/ajaxwserror.ts +++ b/src/core/classes/errors/ajaxwserror.ts @@ -41,7 +41,7 @@ export class CoreAjaxWSError extends CoreError { this.backtrace = error.backtrace; this.available = available; - if (typeof this.available == 'undefined') { + if (this.available === undefined) { if (this.errorcode) { this.available = this.errorcode == 'invalidrecord' ? -1 : 1; } else { diff --git a/src/core/classes/interceptor.ts b/src/core/classes/interceptor.ts index 34c8e4f4d..5ddbe7d11 100644 --- a/src/core/classes/interceptor.ts +++ b/src/core/classes/interceptor.ts @@ -53,7 +53,7 @@ export class CoreInterceptor implements HttpInterceptor { innerObj[fullSubName] = subValue; query += this.serialize(innerObj) + '&'; } - } else if (addNull || (typeof value != 'undefined' && value !== null)) { + } else if (addNull || (value !== undefined && value !== null)) { query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&'; } } diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index 201b23ba1..b6f17c472 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -355,7 +355,7 @@ export class CoreSite { * @return Whether the user authenticated in the site using an OAuth method. */ isOAuth(): boolean { - return this.oauthId != null && typeof this.oauthId != 'undefined'; + return this.oauthId != null && this.oauthId !== undefined; } /** @@ -366,7 +366,7 @@ export class CoreSite { canAccessMyFiles(): boolean { const info = this.getInfo(); - return !!(info && (typeof info.usercanmanageownfiles === 'undefined' || info.usercanmanageownfiles)); + return !!(info && (info.usercanmanageownfiles === undefined || info.usercanmanageownfiles)); } /** @@ -390,7 +390,7 @@ export class CoreSite { canUseAdvancedFeature(featureName: string, whenUndefined: boolean = true): boolean { const info = this.getInfo(); - if (typeof info?.advancedfeatures === 'undefined') { + if (info?.advancedfeatures === undefined) { return whenUndefined; } @@ -444,13 +444,13 @@ export class CoreSite { // eslint-disable-next-line @typescript-eslint/no-explicit-any read(method: string, data: any, preSets?: CoreSiteWSPreSets): Promise { preSets = preSets || {}; - if (typeof preSets.getFromCache == 'undefined') { + if (preSets.getFromCache === undefined) { preSets.getFromCache = true; } - if (typeof preSets.saveToCache == 'undefined') { + if (preSets.saveToCache === undefined) { preSets.saveToCache = true; } - if (typeof preSets.reusePending == 'undefined') { + if (preSets.reusePending === undefined) { preSets.reusePending = true; } @@ -468,13 +468,13 @@ export class CoreSite { // eslint-disable-next-line @typescript-eslint/no-explicit-any write(method: string, data: any, preSets?: CoreSiteWSPreSets): Promise { preSets = preSets || {}; - if (typeof preSets.getFromCache == 'undefined') { + if (preSets.getFromCache === undefined) { preSets.getFromCache = false; } - if (typeof preSets.saveToCache == 'undefined') { + if (preSets.saveToCache === undefined) { preSets.saveToCache = false; } - if (typeof preSets.emergencyCache == 'undefined') { + if (preSets.emergencyCache === undefined) { preSets.emergencyCache = false; } @@ -655,7 +655,7 @@ export class CoreSite { this.saveToCache(method, data, error, preSets); throw new CoreWSError(error); - } else if (typeof preSets.emergencyCache !== 'undefined' && !preSets.emergencyCache) { + } else if (preSets.emergencyCache !== undefined && !preSets.emergencyCache) { this.logger.debug(`WS call '${method}' failed. Emergency cache is forbidden, rejecting.`); throw new CoreWSError(error); @@ -681,7 +681,7 @@ export class CoreSite { // eslint-disable-next-line @typescript-eslint/no-explicit-any }).then((response: any) => { // Check if the response is an error, this happens if the error was stored in the cache. - if (response && (typeof response.exception != 'undefined' || typeof response.errorcode != 'undefined')) { + if (response && (response.exception !== undefined || response.errorcode !== undefined)) { throw new CoreWSError(response); } @@ -857,7 +857,7 @@ export class CoreSite { } else { let responseData = response.data ? CoreTextUtils.parseJSON(response.data) : {}; // Match the behaviour of CoreWSProvider.call when no response is expected. - const responseExpected = typeof wsPresets.responseExpected == 'undefined' || wsPresets.responseExpected; + const responseExpected = wsPresets.responseExpected === undefined || wsPresets.responseExpected; if (!responseExpected && (responseData == null || responseData === '')) { responseData = {}; } @@ -938,7 +938,7 @@ export class CoreSite { entry = await db.getRecord(CoreSite.WS_CACHE_TABLE, { id }); } - if (typeof entry == 'undefined') { + if (entry === undefined) { throw new CoreError('Cache entry not valid.'); } @@ -957,7 +957,7 @@ export class CoreSite { } } - if (typeof entry.data != 'undefined') { + if (entry.data !== undefined) { if (!expirationTime) { this.logger.info(`Cached element found, id: ${id}. Expiration time ignored.`); } else { @@ -1206,7 +1206,7 @@ export class CoreSite { * @return Fixed URL. */ fixPluginfileURL(url: string): string { - const accessKey = this.tokenPluginFileWorks || typeof this.tokenPluginFileWorks == 'undefined' ? + const accessKey = this.tokenPluginFileWorks || this.tokenPluginFileWorks === undefined ? this.infos && this.infos.userprivateaccesskey : undefined; return CoreUrlUtils.fixPluginfileURL(url, this.token || '', this.siteUrl, accessKey); @@ -1829,7 +1829,7 @@ export class CoreSite { return entry.value; } catch (error) { - if (typeof defaultValue != 'undefined') { + if (defaultValue !== undefined) { return defaultValue; } @@ -1876,7 +1876,7 @@ export class CoreSite { if (!CoreUrlUtils.canUseTokenPluginFile(url, this.siteUrl, this.infos && this.infos.userprivateaccesskey)) { // Cannot use tokenpluginfile. return Promise.resolve(false); - } else if (typeof this.tokenPluginFileWorks != 'undefined') { + } else if (this.tokenPluginFileWorks !== undefined) { // Already checked. return Promise.resolve(this.tokenPluginFileWorks); } else if (this.tokenPluginFileWorksPromise) { diff --git a/src/core/classes/sqlitedb.ts b/src/core/classes/sqlitedb.ts index 9455e4c6a..c84c52ccd 100644 --- a/src/core/classes/sqlitedb.ts +++ b/src/core/classes/sqlitedb.ts @@ -221,7 +221,7 @@ export class SQLiteDB { columnSql += ` CHECK (${column.check})`; } - if (typeof column.default != 'undefined') { + if (column.default !== undefined) { columnSql += ` DEFAULT ${column.default}`; } @@ -388,7 +388,7 @@ export class SQLiteDB { * @return Promise resolved with the number of affected rows. */ async deleteRecords(table: string, conditions?: SQLiteDBRecordValues): Promise { - if (conditions === null || typeof conditions == 'undefined') { + if (conditions === null || conditions === undefined) { // No conditions, delete the whole table. const result = await this.execute(`DELETE FROM ${table}`); @@ -485,7 +485,7 @@ export class SQLiteDB { // Remove undefined entries and convert null to "NULL". for (const name in data) { - if (typeof data[name] == 'undefined') { + if (data[name] === undefined) { delete data[name]; } } @@ -581,13 +581,13 @@ export class SQLiteDB { let params: SQLiteDBRecordValue[]; // Default behavior, return empty data on empty array. - if (Array.isArray(items) && !items.length && typeof onEmptyItems == 'undefined') { + if (Array.isArray(items) && !items.length && onEmptyItems === undefined) { return { sql: '', params: [] }; } // Handle onEmptyItems on empty array of items. if (Array.isArray(items) && !items.length) { - if (onEmptyItems === null || typeof onEmptyItems === 'undefined') { // Special case, NULL value. + if (onEmptyItems === null || onEmptyItems === undefined) { // Special case, NULL value. sql = equal ? ' IS NULL' : ' IS NOT NULL'; return { sql, params: [] }; @@ -1091,7 +1091,7 @@ export class SQLiteDB { for (const key in conditions) { const value = conditions[key]; - if (typeof value == 'undefined' || value === null) { + if (value === undefined || value === null) { where.push(key + ' IS NULL'); } else { where.push(key + ' = ?'); @@ -1124,7 +1124,7 @@ export class SQLiteDB { let sql = ''; values.forEach((value) => { - if (typeof value == 'undefined' || value === null) { + if (value === undefined || value === null) { sql = field + ' IS NULL'; } else { params.push(value); diff --git a/src/core/classes/tabs.ts b/src/core/classes/tabs.ts index b03b8f827..76527de07 100644 --- a/src/core/classes/tabs.ts +++ b/src/core/classes/tabs.ts @@ -427,7 +427,7 @@ export class CoreTabsBaseComponent implements OnInit, Aft this.slides!.slideTo(this.maxSlides); } else { const currentIndex = await this.slides!.getActiveIndex(); - if (typeof currentIndex !== 'undefined') { + if (currentIndex !== undefined) { const nextSlideIndex = currentIndex + this.maxSlides; this.isInTransition = true; if (nextSlideIndex < this.numTabsShown) { @@ -456,7 +456,7 @@ export class CoreTabsBaseComponent implements OnInit, Aft // Slide to the previous of the latest page. } else { const currentIndex = await this.slides!.getActiveIndex(); - if (typeof currentIndex !== 'undefined') { + if (currentIndex !== undefined) { const prevSlideIndex = currentIndex - this.maxSlides; this.isInTransition = true; if (prevSlideIndex >= 0) { diff --git a/src/core/components/chart/chart.ts b/src/core/components/chart/chart.ts index dbff890ca..cd792d859 100644 --- a/src/core/components/chart/chart.ts +++ b/src/core/components/chart/chart.ts @@ -64,7 +64,7 @@ export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { */ async ngOnInit(): Promise { let legend: ChartLegendOptions = {}; - if (typeof this.legend == 'undefined') { + if (this.legend === undefined) { legend = { display: false, labels: { diff --git a/src/core/components/chrono/chrono.ts b/src/core/components/chrono/chrono.ts index 179ad69f8..b111a9b0e 100644 --- a/src/core/components/chrono/chrono.ts +++ b/src/core/components/chrono/chrono.ts @@ -102,7 +102,7 @@ export class CoreChronoComponent implements OnInit, OnChanges, OnDestroy { this.time += Date.now() - lastExecTime; lastExecTime = Date.now(); - if (typeof this.endTime != 'undefined' && this.time > this.endTime) { + if (this.endTime !== undefined && this.time > this.endTime) { // End time reached, stop the timer and call the end function. this.stop(); this.onEnd.emit(); diff --git a/src/core/components/progress-bar/progress-bar.ts b/src/core/components/progress-bar/progress-bar.ts index ec65e69bc..ae6f86fcc 100644 --- a/src/core/components/progress-bar/progress-bar.ts +++ b/src/core/components/progress-bar/progress-bar.ts @@ -44,7 +44,7 @@ export class CoreProgressBarComponent implements OnChanges { * Detect changes on input properties. */ ngOnChanges(changes: { [name: string]: SimpleChange }): void { - if (changes.text && typeof changes.text.currentValue != 'undefined') { + if (changes.text && changes.text.currentValue !== undefined) { // User provided a custom text, don't use default. this.textSupplied = true; } diff --git a/src/core/components/tabs-outlet/tabs-outlet.ts b/src/core/components/tabs-outlet/tabs-outlet.ts index 1783496b4..54da61022 100644 --- a/src/core/components/tabs-outlet/tabs-outlet.ts +++ b/src/core/components/tabs-outlet/tabs-outlet.ts @@ -80,7 +80,7 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent forceOpenLinksIn setting > data-open-in HTML attribute. let openInApp = this.inApp; - if (typeof this.inApp == 'undefined') { + if (this.inApp === undefined) { if (CoreConstants.CONFIG.forceOpenLinksIn == 'browser') { openInApp = false; } else if (CoreConstants.CONFIG.forceOpenLinksIn == 'app' || openIn == 'app') { diff --git a/src/core/directives/supress-events.ts b/src/core/directives/supress-events.ts index 0ec7aab2e..559558129 100644 --- a/src/core/directives/supress-events.ts +++ b/src/core/directives/supress-events.ts @@ -63,7 +63,7 @@ export class CoreSupressEventsDirective implements OnInit { let events: string[]; - if (this.suppressEvents == 'all' || typeof this.suppressEvents == 'undefined' || this.suppressEvents === null) { + if (this.suppressEvents == 'all' || this.suppressEvents === undefined || this.suppressEvents === null) { // Suppress all events. events = ['click', 'mousedown', 'touchdown', 'touchmove', 'touchstart']; diff --git a/src/core/features/comments/components/comments/comments.ts b/src/core/features/comments/components/comments/comments.ts index 8e8683cac..04c45f389 100644 --- a/src/core/features/comments/components/comments/comments.ts +++ b/src/core/features/comments/components/comments/comments.ts @@ -211,7 +211,7 @@ export class CoreCommentsCommentsComponent implements OnInit, OnChanges, OnDestr * @return Whether it's undefined or equal. */ protected undefinedOrEqual(data: Record, name: string): boolean { - return typeof data[name] == 'undefined' || data[name] == this[name]; + return data[name] === undefined || data[name] == this[name]; } } diff --git a/src/core/features/comments/pages/viewer/viewer.page.ts b/src/core/features/comments/pages/viewer/viewer.page.ts index befbfd691..fba333730 100644 --- a/src/core/features/comments/pages/viewer/viewer.page.ts +++ b/src/core/features/comments/pages/viewer/viewer.page.ts @@ -163,7 +163,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy { this.canAddComments = this.addDeleteCommentsAvailable && !!commentsResponse.canpost; let comments = commentsResponse.comments.sort((a, b) => a.timecreated - b.timecreated); - if (typeof commentsResponse.count != 'undefined') { + if (commentsResponse.count !== undefined) { this.canLoadMore = (this.comments.length + comments.length) < commentsResponse.count; } else { // Old style. diff --git a/src/core/features/comments/services/comments-sync.ts b/src/core/features/comments/services/comments-sync.ts index f402366f8..277c7e651 100644 --- a/src/core/features/comments/services/comments-sync.ts +++ b/src/core/features/comments/services/comments-sync.ts @@ -92,7 +92,7 @@ export class CoreCommentsSyncProvider extends CoreSyncBaseProvider CoreCommentsProvider.pageSize) { + if (response.count === undefined && response.comments.length > CoreCommentsProvider.pageSize) { CoreCommentsProvider.pageSize = response.comments.length; } @@ -434,7 +434,7 @@ export class CoreCommentsProvider { const response = await this.getComments(contextLevel, instanceId, component, itemId, area, page, siteId); // Count is only available in 3.8 onwards. - if (typeof response.count != 'undefined') { + if (response.count !== undefined) { trueCount = true; return response.count; diff --git a/src/core/features/contentlinks/classes/module-index-handler.ts b/src/core/features/contentlinks/classes/module-index-handler.ts index 3cd4da191..5efc4c83a 100644 --- a/src/core/features/contentlinks/classes/module-index-handler.ts +++ b/src/core/features/contentlinks/classes/module-index-handler.ts @@ -83,7 +83,7 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB courseId = Number(courseId || params.courseid || params.cid); const pageParams = this.getPageParams(url, params, courseId); - if (this.instanceIdParam && typeof params[this.instanceIdParam] != 'undefined') { + if (this.instanceIdParam && params[this.instanceIdParam] !== undefined) { const instanceId = parseInt(params[this.instanceIdParam], 10); return [{ diff --git a/src/core/features/contentlinks/services/contentlinks-delegate.ts b/src/core/features/contentlinks/services/contentlinks-delegate.ts index 8c40a4724..eeaab8bbc 100644 --- a/src/core/features/contentlinks/services/contentlinks-delegate.ts +++ b/src/core/features/contentlinks/services/contentlinks-delegate.ts @@ -278,7 +278,7 @@ export class CoreContentLinksDelegateService { * @return True if registered successfully, false otherwise. */ registerHandler(handler: CoreContentLinksHandler): boolean { - if (typeof this.handlers[handler.name] !== 'undefined') { + if (this.handlers[handler.name] !== undefined) { this.logger.log(`Addon '${handler.name}' already registered`); return false; diff --git a/src/core/features/course/classes/module-prefetch-handler.ts b/src/core/features/course/classes/module-prefetch-handler.ts index e68b13c68..ab9bf9fda 100644 --- a/src/core/features/course/classes/module-prefetch-handler.ts +++ b/src/core/features/course/classes/module-prefetch-handler.ts @@ -181,7 +181,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref */ getIntroFilesFromInstance(module: CoreCourseAnyModuleData, instance?: ModuleInstance): CoreWSFile[] { if (instance) { - if (typeof instance.introfiles != 'undefined') { + if (instance.introfiles !== undefined) { return instance.introfiles; } else if (instance.intro) { return CoreFilepool.extractDownloadableFilesFromHtmlAsFakeFileObjects(instance.intro); diff --git a/src/core/features/course/components/format/format.ts b/src/core/features/course/components/format/format.ts index f351df992..32932b687 100644 --- a/src/core/features/course/components/format/format.ts +++ b/src/core/features/course/components/format/format.ts @@ -165,9 +165,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { let section: CoreCourseSection | undefined; - if (typeof data.sectionId != 'undefined' && this.sections) { + if (data.sectionId !== undefined && this.sections) { section = this.sections.find((section) => section.id == data.sectionId); - } else if (typeof data.sectionNumber != 'undefined' && this.sections) { + } else if (data.sectionNumber !== undefined && this.sections) { section = this.sections.find((section) => section.section == data.sectionNumber); } @@ -399,7 +399,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { } } - if (this.moduleId && typeof previousValue == 'undefined') { + if (this.moduleId && previousValue === undefined) { setTimeout(() => { CoreDomUtils.scrollToElementBySelector( this.elementRef.nativeElement, diff --git a/src/core/features/course/format/weeks/services/handlers/weeks-format.ts b/src/core/features/course/format/weeks/services/handlers/weeks-format.ts index 4e7682eee..10de07200 100644 --- a/src/core/features/course/format/weeks/services/handlers/weeks-format.ts +++ b/src/core/features/course/format/weeks/services/handlers/weeks-format.ts @@ -57,7 +57,7 @@ export class CoreCourseFormatWeeksHandlerService implements CoreCourseFormatHand for (let i = 0; i < sections.length; i++) { const section = sections[i]; - if (typeof section.section == 'undefined' || section.section < 1) { + if (section.section === undefined || section.section < 1) { continue; } diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index 1cad013f4..69bbfe521 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -296,7 +296,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { if (this.course.enablecompletion !== false) { const sectionWithModules = sections.find((section) => section.modules.length > 0); - if (sectionWithModules && typeof sectionWithModules.modules[0].completion != 'undefined') { + if (sectionWithModules && sectionWithModules.modules[0].completion !== undefined) { // The module already has completion (3.6 onwards). Load the offline completion. this.modulesHaveCompletion = true; @@ -396,7 +396,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { * @return Promise resolved when done. */ async onCompletionChange(completionData: CoreCourseModuleCompletionData): Promise { - const shouldReload = typeof completionData.valueused == 'undefined' || completionData.valueused; + const shouldReload = completionData.valueused === undefined || completionData.valueused; if (!shouldReload) { // Invalidate the completion. diff --git a/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts b/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts index f24a70c92..735cfc346 100644 --- a/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts +++ b/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts @@ -85,7 +85,7 @@ export class CoreCourseListModTypePage implements OnInit { if (this.modName === 'resources') { // Check that the module is a resource. - if (typeof this.archetypes[mod.modname] == 'undefined') { + if (this.archetypes[mod.modname] === undefined) { this.archetypes[mod.modname] = CoreCourseModuleDelegate.supportsFeature( mod.modname, CoreConstants.FEATURE_MOD_ARCHETYPE, diff --git a/src/core/features/course/pages/preview/preview.page.ts b/src/core/features/course/pages/preview/preview.page.ts index b7a6aa5e2..65fd8e105 100644 --- a/src/core/features/course/pages/preview/preview.page.ts +++ b/src/core/features/course/pages/preview/preview.page.ts @@ -356,7 +356,7 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy { }, ); - if (typeof modalData != 'undefined') { + if (modalData !== undefined) { this.selfEnrolInCourse(modalData, instanceId); return; diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 8d246dcd2..e254f5b2f 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -1253,7 +1253,7 @@ export class CoreCourseHelperProvider { const module = section.modules[j]; const offlineCompletion = offlineCompletionsMap[module.id]; - if (offlineCompletion && typeof module.completiondata != 'undefined' && + if (offlineCompletion && module.completiondata !== undefined && offlineCompletion.timecompleted >= module.completiondata.timecompleted * 1000) { // The module has offline completion. Load it. module.completiondata.state = offlineCompletion.completed; @@ -1771,7 +1771,7 @@ export class CoreCourseHelperProvider { promises.push(CoreCourses.getCoursesByField('id', course.id)); const sectionWithModules = sections.find((section) => section.modules && section.modules.length > 0); - if (!sectionWithModules || typeof sectionWithModules.modules[0].completion == 'undefined') { + if (!sectionWithModules || sectionWithModules.modules[0].completion === undefined) { promises.push(CoreCourse.getActivitiesCompletionStatus(course.id)); } @@ -1988,7 +1988,7 @@ export class CoreCourseHelperProvider { return false; } - return (typeof section.availabilityinfo != 'undefined' && section.availabilityinfo != '') || + return (section.availabilityinfo !== undefined && section.availabilityinfo != '') || section.summary != '' || (section.modules && section.modules.length > 0); } diff --git a/src/core/features/course/services/course-options-delegate.ts b/src/core/features/course/services/course-options-delegate.ts index 87765a546..038b5d51a 100644 --- a/src/core/features/course/services/course-options-delegate.ts +++ b/src/core/features/course/services/course-options-delegate.ts @@ -585,7 +585,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate { - if (typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh) { + if (course.navOptions === undefined || course.admOptions === undefined || refresh) { const options = await CoreCourses.getCoursesAdminAndNavOptions([course.id]); course.navOptions = options.navOptions[course.id]; diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 3d440e2a8..c8da4ec5f 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -293,7 +293,7 @@ export class CoreCourseProvider { offlineCompletions.forEach((offlineCompletion) => { - if (offlineCompletion && typeof completionStatus[offlineCompletion.cmid] != 'undefined') { + if (offlineCompletion && completionStatus[offlineCompletion.cmid] !== undefined) { const onlineCompletion = completionStatus[offlineCompletion.cmid]; // If the activity uses manual completion, override the value with the offline one. @@ -992,7 +992,7 @@ export class CoreCourseProvider { }; const wsName = 'core_course_view_course'; - if (typeof sectionNumber != 'undefined') { + if (sectionNumber !== undefined) { params.sectionnumber = sectionNumber; } @@ -1135,7 +1135,7 @@ export class CoreCourseProvider { // Wait for site plugins to be fetched. await CoreUtils.ignoreErrors(CoreSitePlugins.waitFetchPlugins()); - if (!('format' in course) || typeof course.format == 'undefined') { + if (!('format' in course) || course.format === undefined) { const result = await CoreCourseHelper.getCourse(course.id); course = result.course; @@ -1255,7 +1255,7 @@ export class CoreCourseProvider { try { const entry = await this.getCourseStatusData(courseId, siteId); - if (typeof downloadTime == 'undefined') { + if (downloadTime === undefined) { // Keep previous download time. downloadTime = entry.downloadTime; previousDownloadTime = entry.previousDownloadTime; diff --git a/src/core/features/course/services/module-prefetch-delegate.ts b/src/core/features/course/services/module-prefetch-delegate.ts index f835799eb..e1166739b 100644 --- a/src/core/features/course/services/module-prefetch-delegate.ts +++ b/src/core/features/course/services/module-prefetch-delegate.ts @@ -392,7 +392,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'downloadSize'); - if (typeof downloadSize != 'undefined') { + if (downloadSize !== undefined) { return downloadSize; } @@ -430,7 +430,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'downloadedSize'); - if (typeof downloadedSize != 'undefined') { + if (downloadedSize !== undefined) { return downloadedSize; } @@ -558,7 +558,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status'); - if (!refresh && typeof status != 'undefined') { + if (!refresh && status !== undefined) { this.storeCourseAndSection(packageId, courseId, sectionId); return this.determineModuleStatus(module, status); @@ -612,7 +612,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status', true); - if (typeof cacheStatus == 'undefined') { + if (cacheStatus === undefined) { throw error; } @@ -769,7 +769,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status'); - if (typeof status != 'undefined' && !CoreFileHelper.isStateDownloaded(status)) { + if (status !== undefined && !CoreFileHelper.isStateDownloaded(status)) { // Module isn't downloaded, just return the status. return { status }; } @@ -976,7 +976,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'downloadable'); - if (typeof downloadable != 'undefined') { + if (downloadable !== undefined) { return downloadable; } diff --git a/src/core/features/courses/components/course-progress/course-progress.ts b/src/core/features/courses/components/course-progress/course-progress.ts index 7b1e37c7b..9d295b906 100644 --- a/src/core/features/courses/components/course-progress/course-progress.ts +++ b/src/core/features/courses/components/course-progress/course-progress.ts @@ -82,7 +82,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy, On // This field is only available from 3.6 onwards. this.courseOptionMenuEnabled = this.showAll && 'isfavourite' in this.course && - typeof this.course.isfavourite != 'undefined'; + this.course.isfavourite !== undefined; // Refresh the enabled flag if site is updated. this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { diff --git a/src/core/features/courses/services/courses-helper.ts b/src/core/features/courses/services/courses-helper.ts index 62f98ed70..aa794077b 100644 --- a/src/core/features/courses/services/courses-helper.ts +++ b/src/core/features/courses/services/courses-helper.ts @@ -270,12 +270,12 @@ export class CoreCoursesHelperProvider { courses = slice > 0 ? courses.slice(0, slice) : courses; return Promise.all(courses.map(async (course) => { - if (typeof course.completed != 'undefined') { + if (course.completed !== undefined) { // The WebService already returns the completed status, no need to fetch it. return course; } - if (typeof course.enablecompletion != 'undefined' && !course.enablecompletion) { + if (course.enablecompletion !== undefined && !course.enablecompletion) { // Completion is disabled for this course, there is no need to fetch the completion status. return course; } diff --git a/src/core/features/courses/services/courses.ts b/src/core/features/courses/services/courses.ts index 002d3fc28..a724803f0 100644 --- a/src/core/features/courses/services/courses.ts +++ b/src/core/features/courses/services/courses.ts @@ -524,15 +524,15 @@ export class CoreCoursesProvider { // Courses will be sorted using sortorder if available. return response.courses.sort((a, b) => { - if (typeof a.sortorder == 'undefined' && typeof b.sortorder == 'undefined') { + if (a.sortorder === undefined && b.sortorder === undefined) { return b.id - a.id; } - if (typeof a.sortorder == 'undefined') { + if (a.sortorder === undefined) { return 1; } - if (typeof b.sortorder == 'undefined') { + if (b.sortorder === undefined) { return -1; } diff --git a/src/core/features/courses/services/handlers/course-link.ts b/src/core/features/courses/services/handlers/course-link.ts index dfe5426a7..5e1800ddb 100644 --- a/src/core/features/courses/services/handlers/course-link.ts +++ b/src/core/features/courses/services/handlers/course-link.ts @@ -65,7 +65,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler const pageParams: Params = { sectionId: sectionId || null, }; - let sectionNumber = typeof params.section != 'undefined' ? parseInt(params.section, 10) : NaN; + let sectionNumber = params.section !== undefined ? parseInt(params.section, 10) : NaN; if (!sectionId && !sectionNumber) { // Check if the URL has a hash to navigate to the section. @@ -294,7 +294,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler let body = ' '; // Empty message. const placeholder = Translate.instant('core.courses.password'); - if (typeof password != 'undefined') { + if (password !== undefined) { // The user attempted a password. Show an error message. body = CoreTextUtils.getErrorMessageFromError(error) || body; } diff --git a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts index 84c2931ef..2b82866d7 100644 --- a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts +++ b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts @@ -484,7 +484,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn }; let range = document.createRange(); - if (typeof chars === 'undefined') { + if (chars === undefined) { // Select all so it will go to the end. range.selectNode(parent); range.selectNodeContents(parent); @@ -601,7 +601,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn * @param value text */ protected isNullOrWhiteSpace(value: string | null): boolean { - if (value == null || typeof value == 'undefined') { + if (value == null || value === undefined) { return true; } @@ -926,10 +926,10 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn */ protected shouldAutoSaveDrafts(): boolean { return !!CoreSites.getCurrentSite() && - (typeof this.autoSave == 'undefined' || CoreUtils.isTrueOrOne(this.autoSave)) && - typeof this.contextLevel != 'undefined' && - typeof this.contextInstanceId != 'undefined' && - typeof this.elementId != 'undefined'; + (this.autoSave === undefined || CoreUtils.isTrueOrOne(this.autoSave)) && + this.contextLevel !== undefined && + this.contextInstanceId !== undefined && + this.elementId !== undefined; } /** @@ -948,7 +948,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn this.originalContent, ); - if (typeof entry == 'undefined') { + if (entry === undefined) { // No draft found. return; } diff --git a/src/core/features/emulator/services/capture-helper.ts b/src/core/features/emulator/services/capture-helper.ts index daee4b3d7..a65ebca93 100644 --- a/src/core/features/emulator/services/capture-helper.ts +++ b/src/core/features/emulator/services/capture-helper.ts @@ -192,7 +192,7 @@ export class CoreEmulatorCaptureHelperProvider { * @return Promise resolved when loaded. */ load(): Promise { - if (typeof window.MediaRecorder != 'undefined' && this.initGetUserMedia()) { + if (window.MediaRecorder !== undefined && this.initGetUserMedia()) { this.initMimeTypes(); } diff --git a/src/core/features/emulator/services/file.ts b/src/core/features/emulator/services/file.ts index bde3461bd..71eae6136 100644 --- a/src/core/features/emulator/services/file.ts +++ b/src/core/features/emulator/services/file.ts @@ -344,10 +344,10 @@ export class FileMock extends File { // eslint-disable-next-line @typescript-eslint/no-explicit-any const win = window; // Convert to to be able to use non-standard properties. - if (typeof win.requestFileSystem == 'undefined') { + if (win.requestFileSystem === undefined) { win.requestFileSystem = win.webkitRequestFileSystem; } - if (typeof win.resolveLocalFileSystemURL == 'undefined') { + if (win.resolveLocalFileSystemURL === undefined) { win.resolveLocalFileSystemURL = win.webkitResolveLocalFileSystemURL; } win.LocalFileSystem = { diff --git a/src/core/features/fileuploader/services/fileuploader-helper.ts b/src/core/features/fileuploader/services/fileuploader-helper.ts index b00769de3..33b70931d 100644 --- a/src/core/features/fileuploader/services/fileuploader-helper.ts +++ b/src/core/features/fileuploader/services/fileuploader-helper.ts @@ -123,8 +123,8 @@ export class CoreFileUploaderHelperProvider { throw new CoreError(Translate.instant('core.fileuploader.errormustbeonlinetoupload')); } - wifiThreshold = typeof wifiThreshold == 'undefined' ? CoreFileUploaderProvider.WIFI_SIZE_WARNING : wifiThreshold; - limitedThreshold = typeof limitedThreshold == 'undefined' ? + wifiThreshold = wifiThreshold === undefined ? CoreFileUploaderProvider.WIFI_SIZE_WARNING : wifiThreshold; + limitedThreshold = limitedThreshold === undefined ? CoreFileUploaderProvider.LIMITED_SIZE_WARNING : limitedThreshold; if (size < 0) { @@ -203,7 +203,7 @@ export class CoreFileUploaderHelperProvider { const fileName = options?.fileName || CoreFile.getFileAndDirectoryFromPath(path).name; // Check that size isn't too large. - if (typeof maxSize != 'undefined' && maxSize != -1) { + if (maxSize !== undefined && maxSize != -1) { try { const fileEntry = await CoreFile.getExternalFile(path); diff --git a/src/core/features/filter/services/filter.ts b/src/core/features/filter/services/filter.ts index 4b7dd89ca..e413084d5 100644 --- a/src/core/features/filter/services/filter.ts +++ b/src/core/features/filter/services/filter.ts @@ -205,11 +205,11 @@ export class CoreFilterProvider { // Clone object if needed so we can modify it. options = options ? Object.assign({}, options) : {}; - if (typeof options.clean == 'undefined') { + if (options.clean === undefined) { options.clean = false; } - if (typeof options.filter == 'undefined') { + if (options.filter === undefined) { options.filter = true; } diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index 319dc9313..b602a8df5 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -184,13 +184,13 @@ export class CoreGradesHelperProvider { let normalRow = formatted.rows.find( row => row.itemtype != 'leader' && - (typeof row.grade != 'undefined' || typeof row.percentage != 'undefined'), + (row.grade !== undefined || row.percentage !== undefined), ); // Decide if grades or percentage is being shown on phones. - if (normalRow && typeof normalRow.grade != 'undefined') { + if (normalRow && normalRow.grade !== undefined) { columns.grade = true; - } else if (normalRow && typeof normalRow.percentage != 'undefined') { + } else if (normalRow && normalRow.percentage !== undefined) { columns.percentage = true; } else { normalRow = formatted.rows.find((e) => e.itemtype != 'leader'); @@ -198,7 +198,7 @@ export class CoreGradesHelperProvider { } for (const colName in columns) { - if (normalRow && typeof normalRow[colName] != 'undefined') { + if (normalRow && normalRow[colName] !== undefined) { formatted.columns.push({ name: colName, colspan: colName == 'gradeitem' ? maxDepth : 1, @@ -562,7 +562,7 @@ export class CoreGradesHelperProvider { row.iconAlt = Translate.instant('core.grades.calculatedgrade'); } else if (text.indexOf('/mod/') > -1) { const module = text.match(/mod\/([^/]*)\//); - if (typeof module?.[1] != 'undefined') { + if (module?.[1] !== undefined) { row.itemtype = 'mod'; row.itemmodule = module[1]; row.iconAlt = CoreCourse.translateModuleName(row.itemmodule) || ''; @@ -613,7 +613,7 @@ export class CoreGradesHelperProvider { defaultValue: string | number = '', scale?: string, ): Promise { - if (typeof gradingType == 'undefined') { + if (gradingType === undefined) { return []; } diff --git a/src/core/features/grades/services/grades.ts b/src/core/features/grades/services/grades.ts index 00280957d..80b588e8a 100644 --- a/src/core/features/grades/services/grades.ts +++ b/src/core/features/grades/services/grades.ts @@ -318,7 +318,7 @@ export class CoreGradesProvider { const course = await CoreCourses.getUserCourse(courseId, true, siteId); - return !(course && typeof course.showgrades != 'undefined' && !course.showgrades); + return !(course && course.showgrades !== undefined && !course.showgrades); } /** diff --git a/src/core/features/grades/services/handlers/course-option.ts b/src/core/features/grades/services/handlers/course-option.ts index d3954b748..21fb0053b 100644 --- a/src/core/features/grades/services/handlers/course-option.ts +++ b/src/core/features/grades/services/handlers/course-option.ts @@ -41,7 +41,7 @@ export class CoreGradesCourseOptionHandlerService implements CoreCourseOptionsHa * @return Promise resolved when done. */ invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise { - if (navOptions && typeof navOptions.grades != 'undefined') { + if (navOptions && navOptions.grades !== undefined) { // No need to invalidate anything. return Promise.resolve(); } @@ -75,7 +75,7 @@ export class CoreGradesCourseOptionHandlerService implements CoreCourseOptionsHa return false; // Not enabled for guests. } - if (navOptions && typeof navOptions.grades != 'undefined') { + if (navOptions && navOptions.grades !== undefined) { return navOptions.grades; } diff --git a/src/core/features/h5p/classes/content-validator.ts b/src/core/features/h5p/classes/content-validator.ts index fb3468d5c..e3e916ba6 100644 --- a/src/core/features/h5p/classes/content-validator.ts +++ b/src/core/features/h5p/classes/content-validator.ts @@ -91,7 +91,7 @@ export class CoreH5PContentValidator { const group = CoreUtils.clone(metadata || {}); // Stop complaining about "invalid selected option in select" for old content without license chosen. - if (typeof group.license == 'undefined') { + if (group.license === undefined) { group.license = 'U'; } @@ -168,7 +168,7 @@ export class CoreH5PContentValidator { } // Check if string is within allowed length. - if (typeof semantics.maxLength != 'undefined') { + if (semantics.maxLength !== undefined) { text = text.substr(0, semantics.maxLength); } @@ -202,22 +202,22 @@ export class CoreH5PContentValidator { num = 0; } // Check if number is within valid bounds. Move within bounds if not. - if (typeof semantics.min != 'undefined' && num < semantics.min) { + if (semantics.min !== undefined && num < semantics.min) { num = semantics.min; } - if (typeof semantics.max != 'undefined' && num > semantics.max) { + if (semantics.max !== undefined && num > semantics.max) { num = semantics.max; } // Check if number is within allowed bounds even if step value is set. - if (typeof semantics.step != 'undefined') { - const testNumber = num - (typeof semantics.min != 'undefined' ? semantics.min : 0); + if (semantics.step !== undefined) { + const testNumber = num - (semantics.min !== undefined ? semantics.min : 0); const rest = testNumber % semantics.step; if (rest !== 0) { num -= rest; } } // Check if number has proper number of decimals. - if (typeof semantics.decimals != 'undefined') { + if (semantics.decimals !== undefined) { num = Number(num.toFixed(semantics.decimals)); } @@ -303,7 +303,7 @@ export class CoreH5PContentValidator { let keys = Object.keys(list); // Check that list is not longer than allowed length. - if (typeof semantics.max != 'undefined') { + if (semantics.max !== undefined) { keys = keys.slice(0, semantics.max); } @@ -392,8 +392,8 @@ export class CoreH5PContentValidator { file.bitrate = parseInt(file.bitrate, 10); } - if (typeof file.quality != 'undefined') { - if (file.quality === null || typeof file.quality.level == 'undefined' || typeof file.quality.label == 'undefined') { + if (file.quality !== undefined) { + if (file.quality === null || file.quality.level === undefined || file.quality.label === undefined) { delete file.quality; } else { this.filterParams(file.quality, ['level', 'label']); @@ -402,7 +402,7 @@ export class CoreH5PContentValidator { } } - if (typeof file.copyright != 'undefined') { + if (file.copyright !== undefined) { await this.validateGroup(file.copyright, this.getCopyrightSemantics()); } diff --git a/src/core/features/h5p/classes/core.ts b/src/core/features/h5p/classes/core.ts index 6ba4aeec8..ac6dddb45 100644 --- a/src/core/features/h5p/classes/core.ts +++ b/src/core/features/h5p/classes/core.ts @@ -241,7 +241,7 @@ export class CoreH5PCore { return content.filtered; } - if (typeof content.library == 'undefined' || typeof content.params == 'undefined') { + if (content.library === undefined || content.params === undefined) { return null; } diff --git a/src/core/features/h5p/classes/framework.ts b/src/core/features/h5p/classes/framework.ts index cfb77cac5..6386d853e 100644 --- a/src/core/features/h5p/classes/framework.ts +++ b/src/core/features/h5p/classes/framework.ts @@ -388,7 +388,7 @@ export class CoreH5PFramework { * @return Library parameter values separated by ', ' */ libraryParameterValuesToCsv(libraryData: CoreH5PLibraryBeingSaved, key: string, searchParam: string = 'path'): string { - if (typeof libraryData[key] != 'undefined') { + if (libraryData[key] !== undefined) { const parameterValues: string[] = []; libraryData[key].forEach((file) => { @@ -489,7 +489,7 @@ export class CoreH5PFramework { params.metadata.title = params.title; } content.metadata = params.metadata; - content.params = JSON.stringify(typeof params.params != 'undefined' && params.params != null ? params.params : params); + content.params = JSON.stringify(params.params !== undefined && params.params != null ? params.params : params); return content; } @@ -690,15 +690,15 @@ export class CoreH5PFramework { const preloadedCSS = this.libraryParameterValuesToCsv(libraryData, 'preloadedCss', 'path'); const dropLibraryCSS = this.libraryParameterValuesToCsv(libraryData, 'dropLibraryCss', 'machineName'); - if (typeof libraryData.semantics == 'undefined') { + if (libraryData.semantics === undefined) { libraryData.semantics = []; } - if (typeof libraryData.fullscreen == 'undefined') { + if (libraryData.fullscreen === undefined) { libraryData.fullscreen = 0; } let embedTypes = ''; - if (typeof libraryData.embedTypes != 'undefined') { + if (libraryData.embedTypes !== undefined) { embedTypes = libraryData.embedTypes.join(', '); } @@ -717,9 +717,9 @@ export class CoreH5PFramework { preloadedjs: preloadedJS, preloadedcss: preloadedCSS, droplibrarycss: dropLibraryCSS, - semantics: typeof libraryData.semantics != 'undefined' ? JSON.stringify(libraryData.semantics) : null, - addto: typeof libraryData.addTo != 'undefined' ? JSON.stringify(libraryData.addTo) : null, - metadatasettings: typeof libraryData.metadataSettings != 'undefined' ? + semantics: libraryData.semantics !== undefined ? JSON.stringify(libraryData.semantics) : null, + addto: libraryData.addTo !== undefined ? JSON.stringify(libraryData.addTo) : null, + metadatasettings: libraryData.metadataSettings !== undefined ? CoreH5PMetadata.boolifyAndEncodeSettings(libraryData.metadataSettings) : null, }; @@ -841,7 +841,7 @@ export class CoreH5PFramework { const db = await CoreSites.getSiteDb(siteId); // If the libraryid declared in the package is empty, get the latest version. - if (content.library && typeof content.library.libraryId == 'undefined') { + if (content.library && content.library.libraryId === undefined) { const mainLibrary = await this.getLatestLibraryVersion(content.library.machineName, siteId); content.library.libraryId = mainLibrary.id; @@ -867,7 +867,7 @@ export class CoreH5PFramework { }; let contentId: number | undefined; - if (typeof content.id != 'undefined') { + if (content.id !== undefined) { data.id = content.id; contentId = content.id; } else { diff --git a/src/core/features/h5p/classes/metadata.ts b/src/core/features/h5p/classes/metadata.ts index 359b0af26..b0639e57d 100644 --- a/src/core/features/h5p/classes/metadata.ts +++ b/src/core/features/h5p/classes/metadata.ts @@ -32,10 +32,10 @@ export class CoreH5PMetadata { } // Convert metadataSettings values to boolean. - if (typeof metadataSettings.disable != 'undefined') { + if (metadataSettings.disable !== undefined) { metadataSettings.disable = metadataSettings.disable === 1; } - if (typeof metadataSettings.disableExtraTitleField != 'undefined') { + if (metadataSettings.disableExtraTitleField !== undefined) { metadataSettings.disableExtraTitleField = metadataSettings.disableExtraTitleField === 1; } diff --git a/src/core/features/h5p/classes/storage.ts b/src/core/features/h5p/classes/storage.ts index c79bdd305..984dd022d 100644 --- a/src/core/features/h5p/classes/storage.ts +++ b/src/core/features/h5p/classes/storage.ts @@ -94,7 +94,7 @@ export class CoreH5PStorage { throw error; } - if (typeof libraryData.libraryId != 'undefined') { + if (libraryData.libraryId !== undefined) { const promises: Promise[] = []; // Remove all indexes of contents that use this library. @@ -127,17 +127,17 @@ export class CoreH5PStorage { // Insert the different new ones. const promises: Promise[] = []; - if (typeof libraryData.preloadedDependencies != 'undefined') { + if (libraryData.preloadedDependencies !== undefined) { promises.push(this.h5pFramework.saveLibraryDependencies( libraryData, libraryData.preloadedDependencies, 'preloaded', )); } - if (typeof libraryData.dynamicDependencies != 'undefined') { + if (libraryData.dynamicDependencies !== undefined) { promises.push(this.h5pFramework.saveLibraryDependencies(libraryData, libraryData.dynamicDependencies, 'dynamic')); } - if (typeof libraryData.editorDependencies != 'undefined') { + if (libraryData.editorDependencies !== undefined) { promises.push(this.h5pFramework.saveLibraryDependencies(libraryData, libraryData.editorDependencies, 'editor')); } diff --git a/src/core/features/h5p/classes/validator.ts b/src/core/features/h5p/classes/validator.ts index ac300f409..b95399f4b 100644 --- a/src/core/features/h5p/classes/validator.ts +++ b/src/core/features/h5p/classes/validator.ts @@ -65,13 +65,13 @@ export class CoreH5PValidator { const missing: Record = {}; Object.values(libraries).forEach((library) => { - if (typeof library.preloadedDependencies !== 'undefined') { + if (library.preloadedDependencies !== undefined) { Object.assign(missing, this.getMissingDependencies(library.preloadedDependencies, library, libraries)); } - if (typeof library.dynamicDependencies !== 'undefined') { + if (library.dynamicDependencies !== undefined) { Object.assign(missing, this.getMissingDependencies(library.dynamicDependencies, library, libraries)); } - if (typeof library.editorDependencies !== 'undefined') { + if (library.editorDependencies !== undefined) { Object.assign(missing, this.getMissingDependencies(library.editorDependencies, library, libraries)); } }); diff --git a/src/core/features/login/pages/email-signup/email-signup.ts b/src/core/features/login/pages/email-signup/email-signup.ts index 02812cc92..794e81e1d 100644 --- a/src/core/features/login/pages/email-signup/email-signup.ts +++ b/src/core/features/login/pages/email-signup/email-signup.ts @@ -165,7 +165,7 @@ export class CoreLoginEmailSignupPage implements OnInit { if (this.treatSiteConfig()) { // Check content verification. - if (typeof this.ageDigitalConsentVerification == 'undefined') { + if (this.ageDigitalConsentVerification === undefined) { const result = await CoreUtils.ignoreErrors( CoreWS.callAjax( diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index 627547671..ec3052968 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -323,7 +323,7 @@ export class CoreLoginHelperProvider { * @return OAuth ID. */ getOAuthIdFromParams(params?: CoreUrlParams): number | undefined { - return params && typeof params.oauthsso != 'undefined' ? Number(params.oauthsso) : undefined; + return params && params.oauthsso !== undefined ? Number(params.oauthsso) : undefined; } /** @@ -530,7 +530,7 @@ export class CoreLoginHelperProvider { * @return Whether email signup is disabled. */ isFeatureDisabled(feature: string, config?: CoreSitePublicConfigResponse, disabledFeatures?: string): boolean { - if (typeof disabledFeatures == 'undefined') { + if (disabledFeatures === undefined) { disabledFeatures = this.getDisabledFeatures(config); } @@ -978,7 +978,7 @@ export class CoreLoginHelperProvider { } const info = currentSite.getInfo(); - if (typeof info != 'undefined' && typeof info.username != 'undefined') { + if (info !== undefined && info.username !== undefined) { // If current page is already reconnect, stop. if (CoreNavigator.isCurrent('/login/reconnect')) { return; @@ -1249,7 +1249,7 @@ export class CoreLoginHelperProvider { * @return Whether the QR reader should be displayed in site screen. */ displayQRInSiteScreen(): boolean { - return CoreUtils.canScanQR() && (typeof CoreConstants.CONFIG.displayqronsitescreen == 'undefined' || + return CoreUtils.canScanQR() && (CoreConstants.CONFIG.displayqronsitescreen === undefined || !!CoreConstants.CONFIG.displayqronsitescreen); } diff --git a/src/core/features/mainmenu/pages/home/home.ts b/src/core/features/mainmenu/pages/home/home.ts index c7dfce575..a4d89d00e 100644 --- a/src/core/features/mainmenu/pages/home/home.ts +++ b/src/core/features/mainmenu/pages/home/home.ts @@ -109,7 +109,7 @@ export class CoreMainMenuHomePage implements OnInit { // Sort them by priority so new handlers are in the right position. newTabs.sort((a, b) => (handlersMap[b.title].priority || 0) - (handlersMap[a.title].priority || 0)); - if (typeof this.selectedTab == 'undefined' && newTabs.length > 0) { + if (this.selectedTab === undefined && newTabs.length > 0) { let maxPriority = 0; this.selectedTab = Object.entries(newTabs).reduce((maxIndex, [index, tab]) => { diff --git a/src/core/features/mainmenu/services/mainmenu.ts b/src/core/features/mainmenu/services/mainmenu.ts index d34ecde37..f1c09fef0 100644 --- a/src/core/features/mainmenu/services/mainmenu.ts +++ b/src/core/features/mainmenu/services/mainmenu.ts @@ -176,7 +176,7 @@ export class CoreMainMenuProvider { } // Remove undefined values. - return result.filter((entry) => typeof entry != 'undefined'); + return result.filter((entry) => entry !== undefined); } /** diff --git a/src/core/features/pushnotifications/services/push-delegate.ts b/src/core/features/pushnotifications/services/push-delegate.ts index 548301644..b897d0324 100644 --- a/src/core/features/pushnotifications/services/push-delegate.ts +++ b/src/core/features/pushnotifications/services/push-delegate.ts @@ -150,7 +150,7 @@ export class CorePushNotificationsDelegateService { * @return Observer to subscribe. */ on(eventName: string): Subject { - if (typeof this.observables[eventName] == 'undefined') { + if (this.observables[eventName] === undefined) { const eventNames = Object.keys(this.observables).join(', '); this.logger.warn(`'${eventName}' event name is not allowed. Use one of the following: '${eventNames}'.`); @@ -167,7 +167,7 @@ export class CorePushNotificationsDelegateService { * @return True if registered successfully, false otherwise. */ registerClickHandler(handler: CorePushNotificationsClickHandler): boolean { - if (typeof this.clickHandlers[handler.name] !== 'undefined') { + if (this.clickHandlers[handler.name] !== undefined) { this.logger.log(`Addon '${handler.name}' already registered`); return false; @@ -186,7 +186,7 @@ export class CorePushNotificationsDelegateService { * @param name Handler's name. */ registerCounterHandler(name: string): void { - if (typeof this.counterHandlers[name] == 'undefined') { + if (this.counterHandlers[name] === undefined) { this.logger.debug(`Registered handler '${name}' as badge counter handler.`); this.counterHandlers[name] = name; } else { @@ -201,7 +201,7 @@ export class CorePushNotificationsDelegateService { * @return If handler name is present. */ isCounterHandlerRegistered(name: string): boolean { - return typeof this.counterHandlers[name] != 'undefined'; + return this.counterHandlers[name] !== undefined; } /** diff --git a/src/core/features/question/classes/base-question-component.ts b/src/core/features/question/classes/base-question-component.ts index 630142130..7753c9d86 100644 --- a/src/core/features/question/classes/base-question-component.ts +++ b/src/core/features/question/classes/base-question-component.ts @@ -164,7 +164,7 @@ export class CoreQuestionBaseComponent { for (const i in options) { const optionEl = options[i]; - if (typeof optionEl.value == 'undefined') { + if (optionEl.value === undefined) { this.logger.warn('Aborting because couldn\'t find input.', this.question?.slot); CoreQuestionHelper.showComponentError(this.onAbort); @@ -225,7 +225,7 @@ export class CoreQuestionBaseComponent { // Extract question text. this.question.text = CoreDomUtils.getContentsOfElement(element, '.qtext'); - if (typeof this.question.text == 'undefined') { + if (this.question.text === undefined) { this.logger.warn('Aborting because of an error parsing question.', this.question.slot); return CoreQuestionHelper.showComponentError(this.onAbort); @@ -554,7 +554,7 @@ export class CoreQuestionBaseComponent { for (const j in options) { const optionEl = options[j]; - if (typeof optionEl.value == 'undefined') { + if (optionEl.value === undefined) { this.logger.warn('Aborting because couldn\'t find the value of an option.', question.slot); return CoreQuestionHelper.showComponentError(this.onAbort); diff --git a/src/core/features/question/services/question-helper.ts b/src/core/features/question/services/question-helper.ts index 6aacaca8a..b8ab02ad4 100644 --- a/src/core/features/question/services/question-helper.ts +++ b/src/core/features/question/services/question-helper.ts @@ -153,7 +153,7 @@ export class CoreQuestionHelperProvider { }); // If we have a certainty value stored in local we'll use that one. - if (question.localAnswers && typeof question.localAnswers['-certainty'] != 'undefined') { + if (question.localAnswers && question.localAnswers['-certainty'] !== undefined) { question.behaviourCertaintySelected = question.localAnswers['-certainty']; } diff --git a/src/core/features/rating/components/rate/rate.ts b/src/core/features/rating/components/rate/rate.ts index 55f489c7f..cf2c43639 100644 --- a/src/core/features/rating/components/rate/rate.ts +++ b/src/core/features/rating/components/rate/rate.ts @@ -142,7 +142,7 @@ export class CoreRatingRateComponent implements OnChanges, OnDestroy { this.aggregateMethod, ); - if (typeof response == 'undefined') { + if (response === undefined) { CoreDomUtils.showToast('core.datastoredoffline', true, 3000); } else { this.onUpdate.emit(); diff --git a/src/core/features/settings/services/settings-helper.ts b/src/core/features/settings/services/settings-helper.ts index 51e7a9c1f..3ca96984a 100644 --- a/src/core/features/settings/services/settings-helper.ts +++ b/src/core/features/settings/services/settings-helper.ts @@ -290,7 +290,7 @@ export class CoreSettingsHelperProvider { // Check old setting and update the new. try { const fontSize = await CoreConfig.get('CoreSettingsFontSize'); - if (typeof fontSize == 'undefined') { + if (fontSize === undefined) { // Already upgraded. return; } diff --git a/src/core/features/siteplugins/classes/call-ws-click-directive.ts b/src/core/features/siteplugins/classes/call-ws-click-directive.ts index 4e822ba1c..94c8b28f6 100644 --- a/src/core/features/siteplugins/classes/call-ws-click-directive.ts +++ b/src/core/features/siteplugins/classes/call-ws-click-directive.ts @@ -48,7 +48,7 @@ export class CoreSitePluginsCallWSOnClickBaseDirective extends CoreSitePluginsCa ev.preventDefault(); ev.stopPropagation(); - if (typeof this.confirmMessage != 'undefined') { + if (this.confirmMessage !== undefined) { // Ask for confirm. try { await CoreDomUtils.showConfirm(this.confirmMessage || Translate.instant('core.areyousure')); @@ -71,7 +71,7 @@ export class CoreSitePluginsCallWSOnClickBaseDirective extends CoreSitePluginsCa try { await super.callWS(); } catch (error) { - if (typeof this.showError == 'undefined' || CoreUtils.isTrueOrOne(this.showError)) { + if (this.showError === undefined || CoreUtils.isTrueOrOne(this.showError)) { CoreDomUtils.showErrorModalDefault(error, 'core.serverconnection', true); } } finally { diff --git a/src/core/features/siteplugins/classes/handlers/module-handler.ts b/src/core/features/siteplugins/classes/handlers/module-handler.ts index 847d2894b..9a945b48a 100644 --- a/src/core/features/siteplugins/classes/handlers/module-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-handler.ts @@ -87,7 +87,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp title: module.name, icon: this.getIconSrc(), class: this.handlerSchema.displaydata?.class, - showDownloadButton: typeof showDowloadButton != 'undefined' ? showDowloadButton : hasOffline, + showDownloadButton: showDowloadButton !== undefined ? showDowloadButton : hasOffline, }; if (this.handlerSchema.method) { diff --git a/src/core/features/siteplugins/directives/call-ws.ts b/src/core/features/siteplugins/directives/call-ws.ts index e2b2226a4..6c232973e 100644 --- a/src/core/features/siteplugins/directives/call-ws.ts +++ b/src/core/features/siteplugins/directives/call-ws.ts @@ -72,7 +72,7 @@ export class CoreSitePluginsCallWSDirective extends CoreSitePluginsCallWSOnClick this.parentContent.refreshContent(true); } - if (typeof this.successMessage != 'undefined') { + if (this.successMessage !== undefined) { // Display the success message. CoreDomUtils.showToast(this.successMessage || Translate.instant('core.success')); } diff --git a/src/core/features/siteplugins/services/siteplugins.ts b/src/core/features/siteplugins/services/siteplugins.ts index c03ffbe91..70e85ea13 100644 --- a/src/core/features/siteplugins/services/siteplugins.ts +++ b/src/core/features/siteplugins/services/siteplugins.ts @@ -403,7 +403,7 @@ export class CoreSitePluginsProvider { return false; } - if (restrictEnrolled || typeof restrictEnrolled == 'undefined') { + if (restrictEnrolled || restrictEnrolled === undefined) { // Only enabled for courses the user is enrolled to. Check if the user is enrolled in the course. try { await CoreCourses.getUserCourse(courseId, true); @@ -485,7 +485,7 @@ export class CoreSitePluginsProvider { otherData = otherData || {}; - if (typeof useOtherData == 'undefined') { + if (useOtherData === undefined) { // No need to add other data, return args as they are. return args; } else if (Array.isArray(useOtherData)) { @@ -560,12 +560,12 @@ export class CoreSitePluginsProvider { for (const i in paramsList) { const paramName = paramsList[i]; - if (typeof args[paramName] != 'undefined') { + if (args[paramName] !== undefined) { params[paramName] = args[paramName]; } else { // The param is not one of the default ones. Try to calculate the param to use. const value = this.getDownloadParam(component, paramName, courseId, module); - if (typeof value != 'undefined') { + if (value !== undefined) { params[paramName] = value; } } diff --git a/src/core/features/user/services/handlers/course-option.ts b/src/core/features/user/services/handlers/course-option.ts index 8d0484c9e..37de80356 100644 --- a/src/core/features/user/services/handlers/course-option.ts +++ b/src/core/features/user/services/handlers/course-option.ts @@ -42,7 +42,7 @@ export class CoreUserCourseOptionHandlerService implements CoreCourseOptionsHand * @return Promise resolved when done. */ invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise { - if (navOptions && typeof navOptions.participants != 'undefined') { + if (navOptions && navOptions.participants !== undefined) { // No need to invalidate anything. return Promise.resolve(); } @@ -76,7 +76,7 @@ export class CoreUserCourseOptionHandlerService implements CoreCourseOptionsHand return false; // Not enabled for guests. } - if (navOptions && typeof navOptions.participants != 'undefined') { + if (navOptions && navOptions.participants !== undefined) { return navOptions.participants; } diff --git a/src/core/features/user/services/user-delegate.ts b/src/core/features/user/services/user-delegate.ts index df503bc7d..6adebcf06 100644 --- a/src/core/features/user/services/user-delegate.ts +++ b/src/core/features/user/services/user-delegate.ts @@ -367,14 +367,14 @@ export class CoreUserDelegateService extends CoreDelegate { const site = await CoreSites.getSite(siteId); - if (typeof onlineValue == 'undefined') { + if (onlineValue === undefined) { const preference = await this.getPreference(name, site.id); onlineValue = preference.onlinevalue; diff --git a/src/core/features/user/services/user-profile-field-delegate.ts b/src/core/features/user/services/user-profile-field-delegate.ts index 93f893b5b..0432a8ea0 100644 --- a/src/core/features/user/services/user-profile-field-delegate.ts +++ b/src/core/features/user/services/user-profile-field-delegate.ts @@ -140,7 +140,7 @@ export class CoreUserProfileFieldDelegateService extends CoreDelegate { const name = (fileName.match(/^(?:\.\/)?(.+)\.ts$/) || [])[1]; - if (typeof name !== 'undefined' && name !== 'index') { + if (name !== undefined && name !== 'index') { providers.push({ provide: APP_INITIALIZER, useValue: context(fileName).default, diff --git a/src/core/pipes/format-date.ts b/src/core/pipes/format-date.ts index 960ec19c0..2e49d275a 100644 --- a/src/core/pipes/format-date.ts +++ b/src/core/pipes/format-date.ts @@ -59,7 +59,7 @@ export class CoreFormatDatePipe implements PipeTransform { format = 'core.' + format; } - if (typeof convert == 'undefined') { + if (convert === undefined) { // Initialize convert param. Set it to false if it's a core.df format, set it to true otherwise. convert = format.indexOf('core.df') != 0; } diff --git a/src/core/services/config.ts b/src/core/services/config.ts index 37c65708e..70d6982ef 100644 --- a/src/core/services/config.ts +++ b/src/core/services/config.ts @@ -73,7 +73,7 @@ export class CoreConfigProvider { return entry.value; } catch (error) { - if (typeof defaultValue != 'undefined') { + if (defaultValue !== undefined) { return defaultValue; } diff --git a/src/core/services/cron.ts b/src/core/services/cron.ts index 76a043947..a5b82dfa3 100644 --- a/src/core/services/cron.ts +++ b/src/core/services/cron.ts @@ -337,7 +337,7 @@ export class CoreCronDelegateService { // Invalid handler. return; } - if (typeof this.handlers[handler.name] != 'undefined') { + if (this.handlers[handler.name] !== undefined) { this.logger.debug(`The cron handler '${handler.name}' is already registered.`); return; diff --git a/src/core/services/db.ts b/src/core/services/db.ts index 1d1b2efea..a715625c8 100644 --- a/src/core/services/db.ts +++ b/src/core/services/db.ts @@ -36,7 +36,7 @@ export class CoreDbProvider { * @return DB. */ getDB(name: string, forceNew?: boolean): SQLiteDB { - if (typeof this.dbInstances[name] === 'undefined' || forceNew) { + if (this.dbInstances[name] === undefined || forceNew) { if (Platform.is('cordova')) { this.dbInstances[name] = new SQLiteDB(name); } else { @@ -54,7 +54,7 @@ export class CoreDbProvider { * @return Promise resolved when the DB is deleted. */ async deleteDB(name: string): Promise { - if (typeof this.dbInstances[name] != 'undefined') { + if (this.dbInstances[name] !== undefined) { // Close the database first. await this.dbInstances[name].close(); diff --git a/src/core/services/file-helper.ts b/src/core/services/file-helper.ts index 17b5f0d21..136d1291e 100644 --- a/src/core/services/file-helper.ts +++ b/src/core/services/file-helper.ts @@ -449,7 +449,7 @@ export class CoreFileHelperProvider { getFilenameFromPath(file: CoreFileEntry): string | undefined { const path = CoreUtils.isFileEntry(file) ? file.fullPath : file.filepath; - if (typeof path == 'undefined' || path.length == 0) { + if (path === undefined || path.length == 0) { return; } diff --git a/src/core/services/file.ts b/src/core/services/file.ts index 2316855b8..698cdac02 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -157,7 +157,7 @@ export class CoreFileProvider { * @return Whether the plugin is available. */ isAvailable(): boolean { - return typeof window.resolveLocalFileSystemURL !== 'undefined'; + return window.resolveLocalFileSystemURL !== undefined; } /** @@ -982,7 +982,7 @@ export class CoreFileProvider { async replaceInFile(path: string, search: string | RegExp, newValue: string): Promise { let content = await this.readFile(path); - if (typeof content == 'undefined' || content === null || !content.replace) { + if (content === undefined || content === null || !content.replace) { throw new CoreError(`Error reading file ${path}`); } @@ -1139,7 +1139,7 @@ export class CoreFileProvider { * @return Unique name. */ calculateUniqueName(usedNames: Record, name: string): string { - if (typeof usedNames[name.toLowerCase()] == 'undefined') { + if (usedNames[name.toLowerCase()] === undefined) { // No file with the same name. return name; } @@ -1153,7 +1153,7 @@ export class CoreFileProvider { do { name = nameWithoutExtension + '(' + num + ')' + extension; num++; - } while (typeof usedNames[name.toLowerCase()] != 'undefined'); + } while (usedNames[name.toLowerCase()] !== undefined); return name; } diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index 98efbef5f..d0c00aece 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -466,7 +466,7 @@ export class CoreFilepoolProvider { let size: number; - if (typeof this.sizeCache[fileUrl] != 'undefined') { + if (this.sizeCache[fileUrl] !== undefined) { size = this.sizeCache[fileUrl]; } else { if (!CoreApp.isOnline()) { @@ -594,7 +594,7 @@ export class CoreFilepoolProvider { * @return Link, null if nothing to link. */ protected createComponentLink(component?: string, componentId?: string | number): CoreFilepoolComponentLink | undefined { - if (typeof component != 'undefined' && component != null) { + if (component !== undefined && component != null) { return { component, componentId: this.fixComponentId(componentId) }; } } @@ -681,7 +681,7 @@ export class CoreFilepoolProvider { } const extension = CoreMimetypeUtils.guessExtensionFromUrl(fileUrl); - const addExtension = typeof filePath == 'undefined'; + const addExtension = filePath === undefined; const path = filePath || (await this.getFilePath(siteId, fileId, extension)); if (poolFileObject && poolFileObject.fileId !== fileId) { @@ -994,7 +994,7 @@ export class CoreFilepoolProvider { const links = this.createComponentLinks(component, componentId); const finishSuccessfulDownload = (url: string): string => { - if (typeof component != 'undefined') { + if (component !== undefined) { CoreUtils.ignoreErrors(this.addFileLink(siteId, fileId, component, componentId)); } @@ -1104,7 +1104,7 @@ export class CoreFilepoolProvider { * @return Promise resolved when done. */ protected async fillExtensionInFile(entry: CoreFilepoolFileEntry, siteId: string): Promise { - if (typeof entry.extension != 'undefined') { + if (entry.extension !== undefined) { // Already filled. return; } @@ -1149,7 +1149,7 @@ export class CoreFilepoolProvider { return componentId; } - if (typeof componentId == 'undefined' || componentId === null) { + if (componentId === undefined || componentId === null) { return -1; } @@ -1335,7 +1335,7 @@ export class CoreFilepoolProvider { protected async getFilePath(siteId: string, fileId: string, extension?: string): Promise { let path = this.getFilepoolFolderPath(siteId) + '/' + fileId; - if (typeof extension == 'undefined') { + if (extension === undefined) { // We need the extension to be able to open files properly. try { const entry = await this.hasFileInPool(siteId, fileId); @@ -1555,7 +1555,7 @@ export class CoreFilepoolProvider { try { const entry = await this.hasFileInPool(siteId, fileId); - if (typeof entry === 'undefined') { + if (entry === undefined) { throw new CoreError('File not downloaded.'); } @@ -1949,7 +1949,7 @@ export class CoreFilepoolProvider { } const matches = url.match(revisionRegex); - if (matches && typeof matches[1] != 'undefined') { + if (matches && matches[1] !== undefined) { return parseInt(matches[1], 10); } @@ -2131,7 +2131,7 @@ export class CoreFilepoolProvider { const db = await CoreSites.getSiteDb(siteId); const entry = await db.getRecord(FILES_TABLE_NAME, { fileId }); - if (typeof entry === 'undefined') { + if (entry === undefined) { throw new CoreError('File not found in filepool.'); } @@ -2149,7 +2149,7 @@ export class CoreFilepoolProvider { const db = await this.appDB; const entry = await db.getRecord(QUEUE_TABLE_NAME, { siteId, fileId }); - if (typeof entry === 'undefined') { + if (entry === undefined) { throw new CoreError('File not found in queue.'); } // Convert the links to an object. @@ -2872,7 +2872,7 @@ export class CoreFilepoolProvider { const entry = await site.getDb().getRecord(PACKAGES_TABLE_NAME, { id: packageId }); extra = extra ?? entry.extra; - if (typeof downloadTime == 'undefined') { + if (downloadTime === undefined) { // Keep previous download time. downloadTime = entry.downloadTime; previousDownloadTime = entry.previousDownloadTime; diff --git a/src/core/services/groups.ts b/src/core/services/groups.ts index b0d63b803..39320f09a 100644 --- a/src/core/services/groups.ts +++ b/src/core/services/groups.ts @@ -214,7 +214,7 @@ export class CoreGroupsProvider { const response: CoreGroupGetActivityGroupModeWSResponse = await site.read('core_group_get_activity_groupmode', params, preSets); - if (!response || typeof response.groupmode == 'undefined') { + if (!response || response.groupmode === undefined) { throw new CoreError('Activity group mode not found.'); } diff --git a/src/core/services/lang.ts b/src/core/services/lang.ts index f0430b64f..e8c09518c 100644 --- a/src/core/services/lang.ts +++ b/src/core/services/lang.ts @@ -223,7 +223,7 @@ export class CoreLangProvider { * @return Promise resolved with the current language. */ async getCurrentLanguage(): Promise { - if (typeof this.currentLanguage != 'undefined') { + if (this.currentLanguage !== undefined) { return this.currentLanguage; } @@ -254,13 +254,13 @@ export class CoreLangProvider { let preferredLanguage = navigator.language.toLowerCase(); if (preferredLanguage.indexOf('-') > -1) { // Language code defined by locale has a dash, like en-US or es-ES. Check if it's supported. - if (CoreConstants.CONFIG.languages && typeof CoreConstants.CONFIG.languages[preferredLanguage] == 'undefined') { + if (CoreConstants.CONFIG.languages && CoreConstants.CONFIG.languages[preferredLanguage] === undefined) { // Code is NOT supported. Fallback to language without dash. E.g. 'en-US' would fallback to 'en'. preferredLanguage = preferredLanguage.substr(0, preferredLanguage.indexOf('-')); } } - if (typeof CoreConstants.CONFIG.languages[preferredLanguage] == 'undefined') { + if (CoreConstants.CONFIG.languages[preferredLanguage] === undefined) { // Language not supported, use default language. return this.defaultLanguage; } @@ -349,7 +349,7 @@ export class CoreLangProvider { loadCustomStringsFromSite(currentSite: CoreSite): void { const customStrings = currentSite.getStoredConfig('tool_mobile_customlangstrings'); - if (typeof customStrings != 'undefined') { + if (customStrings !== undefined) { this.loadCustomStrings(customStrings); } } diff --git a/src/core/services/local-notifications.ts b/src/core/services/local-notifications.ts index 9b69435e0..f486e79e9 100644 --- a/src/core/services/local-notifications.ts +++ b/src/core/services/local-notifications.ts @@ -227,7 +227,7 @@ export class CoreLocalNotificationsProvider { const key = table + '#' + id; // Check if the code is already in memory. - if (typeof this.codes[key] != 'undefined') { + if (this.codes[key] !== undefined) { return this.codes[key]; } @@ -413,7 +413,7 @@ export class CoreLocalNotificationsProvider { protected async processNextRequest(): Promise { const nextKey = Object.keys(this.codeRequestsQueue)[0]; - if (typeof nextKey == 'undefined') { + if (nextKey === undefined) { // No more requests in queue, stop. return; } @@ -469,11 +469,11 @@ export class CoreLocalNotificationsProvider { ): CoreEventObserver { this.logger.debug(`Register observer '${component}' for event '${eventName}'.`); - if (typeof this.observables[eventName] == 'undefined') { + if (this.observables[eventName] === undefined) { this.observables[eventName] = {}; } - if (typeof this.observables[eventName][component] == 'undefined') { + if (this.observables[eventName][component] === undefined) { // No observable for this component, create a new one. this.observables[eventName][component] = new Subject(); } @@ -511,7 +511,7 @@ export class CoreLocalNotificationsProvider { const key = table + '#' + id; const isQueueEmpty = Object.keys(this.codeRequestsQueue).length == 0; - if (typeof this.codeRequestsQueue[key] != 'undefined') { + if (this.codeRequestsQueue[key] !== undefined) { // There's already a pending request for this store and ID, add the promise to it. this.codeRequestsQueue[key].deferreds.push(deferred); } else { diff --git a/src/core/services/plugin-file-delegate.ts b/src/core/services/plugin-file-delegate.ts index 9c566fec0..ef78e78ae 100644 --- a/src/core/services/plugin-file-delegate.ts +++ b/src/core/services/plugin-file-delegate.ts @@ -167,7 +167,7 @@ export class CorePluginFileDelegateService extends CoreDelegate { const size = await this.getFileSize(file, siteId); - if (typeof size == 'undefined') { + if (size === undefined) { // We don't have the file size, cannot calculate its total size. result.total = false; } else { diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index 116f125dd..f90b14ace 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -121,7 +121,7 @@ export class CoreSitesProvider { const demoSites = CoreConstants.CONFIG.demo_sites; name = name.toLowerCase(); - if (typeof demoSites != 'undefined' && typeof demoSites[name] != 'undefined') { + if (demoSites !== undefined && demoSites[name] !== undefined) { return demoSites[name]; } } @@ -364,13 +364,13 @@ export class CoreSitesProvider { throw new CoreError(Translate.instant('core.cannotconnecttrouble')); } - if (typeof data == 'undefined') { + if (data === undefined) { throw new CoreError(Translate.instant('core.cannotconnecttrouble')); } else { - if (typeof data.token != 'undefined') { + if (data.token !== undefined) { return { token: data.token, siteUrl, privateToken: data.privatetoken }; } else { - if (typeof data.error != 'undefined') { + if (data.error !== undefined) { // We only allow one retry (to avoid loops). if (!retry && data.errorcode == 'requirecorrectaccess') { siteUrl = CoreUrlUtils.addOrRemoveWWW(siteUrl); @@ -468,7 +468,7 @@ export class CoreSitesProvider { } } - if (typeof config != 'undefined') { + if (config !== undefined) { candidateSite.setConfig(config); } @@ -891,7 +891,7 @@ export class CoreSitesProvider { * @return Whether the user is logged in a site. */ isLoggedIn(): boolean { - return typeof this.currentSite != 'undefined' && typeof this.currentSite.token != 'undefined' && + return this.currentSite !== undefined && this.currentSite.token !== undefined && this.currentSite.token != ''; } @@ -904,7 +904,7 @@ export class CoreSitesProvider { async deleteSite(siteId: string): Promise { this.logger.debug(`Delete site ${siteId}`); - if (typeof this.currentSite != 'undefined' && this.currentSite.id == siteId) { + if (this.currentSite !== undefined && this.currentSite.id == siteId) { this.logout(); } @@ -956,7 +956,7 @@ export class CoreSitesProvider { throw new CoreError('No current site found.'); } else if (this.currentSite && this.currentSite.getId() == siteId) { return this.currentSite; - } else if (typeof this.sites[siteId] != 'undefined') { + } else if (this.sites[siteId] !== undefined) { return this.sites[siteId]; } else { // Retrieve and create the site. @@ -981,7 +981,7 @@ export class CoreSitesProvider { const db = await this.appDB; const data = await db.getRecord(SITES_TABLE_NAME, { siteUrl }); - if (typeof this.sites[data.id] != 'undefined') { + if (this.sites[data.id] !== undefined) { return this.sites[data.id]; } @@ -1326,7 +1326,7 @@ export class CoreSitesProvider { loggedOut: site.isLoggedOut() ? 1 : 0, }; - if (typeof config != 'undefined') { + if (config !== undefined) { site.setConfig(config); newValues.config = JSON.stringify(config); } diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 9b22c544e..945871287 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -200,8 +200,8 @@ export class CoreDomUtilsProvider { const availableSpace = getAvailableSpace(availableBytes); - wifiThreshold = typeof wifiThreshold == 'undefined' ? CoreConstants.WIFI_DOWNLOAD_THRESHOLD : wifiThreshold; - limitedThreshold = typeof limitedThreshold == 'undefined' ? CoreConstants.DOWNLOAD_THRESHOLD : limitedThreshold; + wifiThreshold = wifiThreshold === undefined ? CoreConstants.WIFI_DOWNLOAD_THRESHOLD : wifiThreshold; + limitedThreshold = limitedThreshold === undefined ? CoreConstants.DOWNLOAD_THRESHOLD : limitedThreshold; let wifiPrefix = ''; if (CoreApp.isNetworkAccessLimited()) { @@ -948,7 +948,7 @@ export class CoreDomUtilsProvider { paths[CoreUrlUtils.removeUrlParams(CoreTextUtils.decodeURIComponent(currentSrc))] : undefined; - if (typeof newSrc != 'undefined') { + if (newSrc !== undefined) { media.setAttribute('src', newSrc); } @@ -956,7 +956,7 @@ export class CoreDomUtilsProvider { if (media.tagName == 'VIDEO' && media.getAttribute('poster')) { const currentPoster = media.getAttribute('poster'); const newPoster = paths[CoreTextUtils.decodeURIComponent(currentPoster!)]; - if (typeof newPoster !== 'undefined') { + if (newPoster !== undefined) { media.setAttribute('poster', newPoster); } } @@ -970,7 +970,7 @@ export class CoreDomUtilsProvider { paths[CoreUrlUtils.removeUrlParams(CoreTextUtils.decodeURIComponent(currentHref))] : undefined; - if (typeof newHref != 'undefined') { + if (newHref !== undefined) { anchor.setAttribute('href', newHref); if (typeof anchorFn == 'function') { @@ -1226,7 +1226,7 @@ export class CoreDomUtilsProvider { if (options.buttons) { // Execute dismiss function if any. const cancelButton = options.buttons.find( - (button) => typeof button != 'string' && typeof button.handler != 'undefined' && button.role == 'cancel', + (button) => typeof button != 'string' && button.handler !== undefined && button.role == 'cancel', ); cancelButton.handler?.(null); } diff --git a/src/core/services/utils/mimetype.ts b/src/core/services/utils/mimetype.ts index ddf65901d..98ab537a6 100644 --- a/src/core/services/utils/mimetype.ts +++ b/src/core/services/utils/mimetype.ts @@ -325,7 +325,7 @@ export class CoreMimetypeUtilsProvider { } // Check extension corresponds to a mimetype to know if it's valid. - if (extension && typeof this.getMimeType(extension) == 'undefined') { + if (extension && this.getMimeType(extension) === undefined) { this.logger.warn('Guess file extension: Not valid extension ' + extension); return; @@ -350,7 +350,7 @@ export class CoreMimetypeUtilsProvider { ext = this.cleanExtension(ext); // Check extension corresponds to a mimetype to know if it's valid. - if (typeof this.getMimeType(ext) == 'undefined') { + if (this.getMimeType(ext) === undefined) { this.logger.warn('Get file extension: Not valid extension ' + ext); return; @@ -370,7 +370,7 @@ export class CoreMimetypeUtilsProvider { getGroupMimeInfo(group: string): MimeTypeGroupInfo; getGroupMimeInfo(group: string, field: string): string[] | undefined; getGroupMimeInfo(group: string, field?: string): MimeTypeGroupInfo | string[] | undefined { - if (typeof this.groupsMimeInfo[group] == 'undefined') { + if (this.groupsMimeInfo[group] === undefined) { this.fillGroupMimeInfo(group); } @@ -590,7 +590,7 @@ export class CoreMimetypeUtilsProvider { if (position > -1) { // Check extension corresponds to a mimetype to know if it's valid. extension = path.substr(position + 1).toLowerCase(); - if (typeof this.getMimeType(extension) != 'undefined') { + if (this.getMimeType(extension) !== undefined) { return path.substr(0, position); // Remove extension. } } diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 362298e18..c37c3f8a9 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -215,7 +215,7 @@ export class CoreTextUtilsProvider { * @return Size in human readable format. */ bytesToSize(bytes: number, precision: number = 2): string { - if (typeof bytes == 'undefined' || bytes === null || bytes < 0) { + if (bytes === undefined || bytes === null || bytes < 0) { return Translate.instant('core.notapplicable'); } @@ -347,7 +347,7 @@ export class CoreTextUtilsProvider { * @return Decoded text. */ decodeHTML(text: string | number): string { - if (typeof text == 'undefined' || text === null || (typeof text == 'number' && isNaN(text))) { + if (text === undefined || text === null || (typeof text == 'number' && isNaN(text))) { return ''; } else if (typeof text != 'string') { return '' + text; @@ -430,7 +430,7 @@ export class CoreTextUtilsProvider { * @return Escaped text. */ escapeHTML(text?: string | number | null, doubleEncode: boolean = true): string { - if (typeof text == 'undefined' || text === null || (typeof text == 'number' && isNaN(text))) { + if (text === undefined || text === null || (typeof text == 'number' && isNaN(text))) { return ''; } else if (typeof text != 'string') { return '' + text; @@ -673,7 +673,7 @@ export class CoreTextUtilsProvider { } // Error parsing, return the default value or the original value. - if (typeof defaultValue != 'undefined') { + if (defaultValue !== undefined) { return defaultValue; } diff --git a/src/core/services/utils/time.ts b/src/core/services/utils/time.ts index 684c741b0..60457d388 100644 --- a/src/core/services/utils/time.ts +++ b/src/core/services/utils/time.ts @@ -97,7 +97,7 @@ export class CoreTimeUtilsProvider { converted += ']'; } - converted += typeof CoreTimeUtilsProvider.FORMAT_REPLACEMENTS[char] != 'undefined' ? + converted += CoreTimeUtilsProvider.FORMAT_REPLACEMENTS[char] !== undefined ? CoreTimeUtilsProvider.FORMAT_REPLACEMENTS[char] : char; } else { // Not a PHP format. We need to escape them, otherwise the letters could be confused with Moment formats. @@ -338,7 +338,7 @@ export class CoreTimeUtilsProvider { convertToTimestamp(date: string, applyOffset?: boolean): number { const timestamp = moment(date).unix(); - if (typeof applyOffset !== 'undefined') { + if (applyOffset !== undefined) { return applyOffset ? timestamp - moment().utcOffset() * 60 : timestamp; } diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts index 1fbf79211..15ed16dfc 100644 --- a/src/core/services/utils/url.ts +++ b/src/core/services/utils/url.ts @@ -146,7 +146,7 @@ export class CoreUrlUtilsProvider { } urlAndHash[0].replace(regex, (match: string, key: string, value: string): string => { - params[key] = typeof value != 'undefined' ? CoreTextUtils.decodeURIComponent(value) : ''; + params[key] = value !== undefined ? CoreTextUtils.decodeURIComponent(value) : ''; if (subParams) { params[key] = params[key].replace(subParamsPlaceholder, subParams); @@ -246,7 +246,7 @@ export class CoreUrlUtilsProvider { async getDocsUrl(release?: string, page: string = 'Mobile_app'): Promise { let docsUrl = 'https://docs.moodle.org/en/' + page; - if (typeof release != 'undefined') { + if (release !== undefined) { const version = CoreSites.getMajorReleaseNumber(release).replace('.', ''); // Check is a valid number. diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 1ffe37ddf..e66e673fd 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -150,7 +150,7 @@ export class CoreUtilsProvider { ): Record { for (const entry of array) { const key = propertyName ? entry[propertyName] : entry; - if (typeof result[key] == 'undefined') { + if (result[key] === undefined) { result[key] = []; } @@ -202,7 +202,7 @@ export class CoreUtilsProvider { return equal; } else { if (undefinedIsNull && ( - (typeof itemA == 'undefined' && itemB === null) || (itemA === null && typeof itemB == 'undefined'))) { + (itemA === undefined && itemB === null) || (itemA === null && itemB === undefined))) { return true; } @@ -524,7 +524,7 @@ export class CoreUtilsProvider { * @return Locale float. */ formatFloat(float: unknown): string { - if (typeof float == 'undefined' || float === null || typeof float == 'boolean') { + if (float === undefined || float === null || typeof float == 'boolean') { return ''; } @@ -836,7 +836,7 @@ export class CoreUtilsProvider { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any isFalseOrZero(value: any): boolean { - return typeof value != 'undefined' && (value === false || value === 'false' || parseInt(value, 10) === 0); + return value !== undefined && (value === false || value === 'false' || parseInt(value, 10) === 0); } /** @@ -847,7 +847,7 @@ export class CoreUtilsProvider { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any isTrueOrOne(value: any): boolean { - return typeof value != 'undefined' && (value === true || value === 'true' || parseInt(value, 10) === 1); + return value !== undefined && (value === true || value === 'true' || parseInt(value, 10) === 1); } /** @@ -858,7 +858,7 @@ export class CoreUtilsProvider { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any isWebServiceError(error: any): boolean { - return error && (typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' && + return error && (error.warningcode !== undefined || (error.errorcode !== undefined && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' && error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' && error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' && @@ -929,7 +929,7 @@ export class CoreUtilsProvider { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any notNullOrUndefined(value: any): boolean { - return typeof value != 'undefined' && value !== null; + return value !== undefined && value !== null; } /** @@ -1183,7 +1183,7 @@ export class CoreUtilsProvider { ): A[] { // Get the entries from an object or primitive value. const getEntries = (elKey: string, value: unknown): Record[] | unknown => { - if (typeof value == 'undefined' || value == null) { + if (value === undefined || value == null) { // Filter undefined and null values. return; } else if (this.isObject(value)) { @@ -1277,7 +1277,7 @@ export class CoreUtilsProvider { for (const name in flattened) { let value = flattened[name]; - if (removeEmpty && (value === null || typeof value == 'undefined')) { + if (removeEmpty && (value === null || value === undefined)) { continue; } @@ -1379,8 +1379,8 @@ export class CoreUtilsProvider { obj2: Record | unknown[], key: string, ): boolean { - let value1 = typeof obj1[key] != 'undefined' ? obj1[key] : ''; - let value2 = typeof obj2[key] != 'undefined' ? obj2[key] : ''; + let value1 = obj1[key] !== undefined ? obj1[key] : ''; + let value2 = obj2[key] !== undefined ? obj2[key] : ''; if (typeof value1 == 'number' || typeof value1 == 'boolean') { value1 = '' + value1; @@ -1484,7 +1484,7 @@ export class CoreUtilsProvider { // eslint-disable-next-line @typescript-eslint/no-explicit-any unformatFloat(localeFloat: any, strict?: boolean): false | '' | number { // Bad format on input type number. - if (typeof localeFloat == 'undefined') { + if (localeFloat === undefined) { return false; } @@ -1656,7 +1656,7 @@ export class CoreUtilsProvider { if (error) { this.qrScanData.deferred.reject(data); - } else if (typeof data != 'undefined') { + } else if (data !== undefined) { this.qrScanData.deferred.resolve(data as string); } else { this.qrScanData.deferred.reject(new CoreCanceledError()); diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index ff2d7e869..d1ab15a5e 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -100,7 +100,7 @@ export class CoreWSProvider { } preSets.typeExpected = preSets.typeExpected || 'object'; - if (typeof preSets.responseExpected == 'undefined') { + if (preSets.responseExpected === undefined) { preSets.responseExpected = true; } @@ -323,7 +323,7 @@ export class CoreWSProvider { */ protected getPromiseHttp(method: string, url: string, params?: Record): Promise | undefined { const queueItemId = this.getQueueItemId(method, url, params); - if (typeof this.ongoingCalls[queueItemId] != 'undefined') { + if (this.ongoingCalls[queueItemId] !== undefined) { return this.ongoingCalls[queueItemId]; } } @@ -414,13 +414,13 @@ export class CoreWSProvider { // eslint-disable-next-line @typescript-eslint/no-explicit-any let promise: Promise>; - if (typeof preSets.siteUrl == 'undefined') { + if (preSets.siteUrl === undefined) { throw new CoreAjaxError(Translate.instant('core.unexpectederror')); } else if (!CoreApp.isOnline()) { throw new CoreAjaxError(Translate.instant('core.networkerrormsg')); } - if (typeof preSets.responseExpected == 'undefined') { + if (preSets.responseExpected === undefined) { preSets.responseExpected = true; } @@ -655,7 +655,7 @@ export class CoreWSProvider { } } - if (typeof data.exception !== 'undefined') { + if (data.exception !== undefined) { // Special debugging for site plugins, otherwise it's hard to debug errors if the data is cached. if (method == 'tool_mobile_get_content') { this.logger.error('Error calling WS', method, data); @@ -664,7 +664,7 @@ export class CoreWSProvider { throw new CoreWSError(data); } - if (typeof data.debuginfo != 'undefined') { + if (data.debuginfo !== undefined) { throw new CoreError('Error. ' + data.message); } @@ -787,7 +787,7 @@ export class CoreWSProvider { } preSets.typeExpected = preSets.typeExpected || 'object'; - if (typeof preSets.responseExpected == 'undefined') { + if (preSets.responseExpected === undefined) { preSets.responseExpected = true; } @@ -838,7 +838,7 @@ export class CoreWSProvider { throw new CoreError(Translate.instant('core.errorinvalidresponse')); } - if (typeof data.exception != 'undefined' || typeof data.debuginfo != 'undefined') { + if (data.exception !== undefined || data.debuginfo !== undefined) { throw new CoreWSError(data); } @@ -907,14 +907,14 @@ export class CoreWSProvider { throw new CoreError(Translate.instant('core.errorinvalidresponse')); } - if (typeof data.exception !== 'undefined') { + if (data.exception !== undefined) { throw new CoreWSError(data); - } else if (typeof data.error !== 'undefined') { + } else if (data.error !== undefined) { throw new CoreWSError({ errorcode: data.errortype, message: data.error, }); - } else if (data[0] && typeof data[0].error !== 'undefined') { + } else if (data[0] && data[0].error !== undefined) { throw new CoreWSError({ errorcode: data[0].errortype, message: data[0].error, @@ -966,7 +966,7 @@ export class CoreWSProvider { async sendHTTPRequest(url: string, options: HttpRequestOptions): Promise> { // Set default values. options.responseType = options.responseType || 'json'; - options.timeout = typeof options.timeout == 'undefined' ? this.getRequestTimeout() : options.timeout; + options.timeout = options.timeout === undefined ? this.getRequestTimeout() : options.timeout; if (CoreApp.isMobile()) { // Use the cordova plugin. diff --git a/src/core/singletons/events.ts b/src/core/singletons/events.ts index a88ea0722..ecc3a9ad8 100644 --- a/src/core/singletons/events.ts +++ b/src/core/singletons/events.ts @@ -137,7 +137,7 @@ export class CoreEvents { this.logger.debug(`New observer listening to event '${eventName}'`); - if (typeof this.observables[eventName] == 'undefined') { + if (this.observables[eventName] === undefined) { // No observable for this event, create a new one. this.observables[eventName] = new Subject(); }