Browse Source

Replace lodash methods with native ones

filter
find
has
isEmpty
isString
isUndefined
noop
reject
uniq
JC Brand 4 years ago
parent
commit
6d9752645f

+ 2 - 2
src/components/emoji-picker.js

@@ -4,7 +4,7 @@ import { BaseDropdown } from "./dropdown.js";
 import { CustomElement } from './element.js';
 import { __ } from '../i18n';
 import { _converse, api, converse } from "@converse/headless/converse-core";
-import { debounce, find } from "lodash-es";
+import { debounce } from "lodash-es";
 import { html } from "lit-element";
 import { tpl_emoji_picker } from "../templates/emoji_picker.js";
 import { until } from 'lit-html/directives/until.js';
@@ -177,7 +177,7 @@ export default class EmojiPicker extends CustomElement {
         if (ev.keyCode === converse.keycodes.TAB) {
             if (ev.target.value) {
                 ev.preventDefault();
-                const match = find(converse.emojis.shortnames, sn => _converse.FILTER_CONTAINS(sn, ev.target.value));
+                const match = converse.emojis.shortnames.find(sn => _converse.FILTER_CONTAINS(sn, ev.target.value));
                 match && this.model.set({'query': match});
             } else if (!this.navigator.enabled) {
                 this.enableArrowNavigation(ev);

+ 2 - 2
src/converse-chatview.js

@@ -19,7 +19,7 @@ import { BootstrapModal } from "./converse-modal.js";
 import { View } from '@converse/skeletor/src/view.js';
 import { __ } from './i18n';
 import { _converse, api, converse } from "@converse/headless/converse-core";
-import { debounce, isString } from "lodash-es";
+import { debounce } from "lodash-es";
 import { html, render } from "lit-html";
 
 
@@ -1216,7 +1216,7 @@ converse.plugins.add('converse-chatview', {
                     if (jids === undefined) {
                         return Object.values(_converse.chatboxviews.getAll());
                     }
-                    if (isString(jids)) {
+                    if (typeof jids === 'string') {
                         return _converse.chatboxviews.get(jids);
                     }
                     return jids.map(jid => _converse.chatboxviews.get(jid));

+ 3 - 4
src/converse-modal.js

@@ -5,7 +5,6 @@
  */
 import { View } from '@converse/skeletor/src/view.js';
 import { Model } from '@converse/skeletor/src/model.js';
-import { isString } from "lodash-es";
 import { render } from 'lit-html';
 import { __ } from './i18n';
 import bootstrap from "bootstrap.native";
@@ -186,7 +185,7 @@ converse.plugins.add('converse-modal', {
              *  filled in fields or `false` if the confirm dialog was closed or canceled.
              */
             async confirm (title, messages=[], fields=[]) {
-                if (isString(messages)) {
+                if (typeof messages === 'string') {
                     messages = [messages];
                 }
                 const model = new Model({title, messages, fields, 'type': 'confirm'})
@@ -212,7 +211,7 @@ converse.plugins.add('converse-modal', {
              *  user or `false` if the user canceled the prompt.
              */
             async prompt (title, messages=[], placeholder='') {
-                if (isString(messages)) {
+                if (typeof messages === 'string') {
                     messages = [messages];
                 }
                 const model = new Model({
@@ -244,7 +243,7 @@ converse.plugins.add('converse-modal', {
              * @param { (String[]|String) } messages - The alert text to show to the user.
              */
             alert (type, title, messages) {
-                if (isString(messages)) {
+                if (typeof messages === 'string') {
                     messages = [messages];
                 }
                 let level;

+ 3 - 3
src/converse-muc-views.js

@@ -28,7 +28,7 @@ import { Model } from '@converse/skeletor/src/model.js';
 import { View } from '@converse/skeletor/src/view.js';
 import { __ } from './i18n';
 import { _converse, api, converse } from "@converse/headless/converse-core";
-import { debounce, isString, isUndefined } from "lodash-es";
+import { debounce } from "lodash-es";
 import { render } from "lit-html";
 
 const { Strophe, sizzle, $pres } = converse.env;
@@ -504,7 +504,7 @@ export const ChatRoomView = ChatBoxView.extend({
         if (!this.verifyRoles(['moderator'])) {
             return;
         }
-        if (isUndefined(this.model.modtools_modal)) {
+        if (typeof this.model.modtools_modal === 'undefined') {
             const model = new Model({'affiliation': affiliation});
             this.modtools_modal = new ModeratorToolsModal({model, _converse, 'chatroomview': this});
         } else {
@@ -1736,7 +1736,7 @@ converse.plugins.add('converse-muc-views', {
                     let views;
                     if (jids === undefined) {
                         views = _converse.chatboxviews;
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         views = [_converse.chatboxviews.get(jids)].filter(v => v);
                     } else if (Array.isArray(jids)) {
                         views = jids.map(jid => _converse.chatboxviews.get(jid));

+ 2 - 3
src/converse-push.js

@@ -7,7 +7,6 @@
  * @license Mozilla Public License (MPLv2)
  */
 import { _converse, api, converse } from "@converse/headless/converse-core";
-import { filter, reject } from 'lodash-es';
 import log from "@converse/headless/log";
 
 const { Strophe, $iq } = converse.env;
@@ -95,8 +94,8 @@ converse.plugins.add('converse-push', {
             if (push_enabled.includes(domain)) {
                 return;
             }
-            const enabled_services = reject(api.settings.get('push_app_servers'), 'disable');
-            const disabled_services = filter(api.settings.get('push_app_servers'), 'disable');
+            const enabled_services = api.settings.get('push_app_servers').filter(s => !s.disable);
+            const disabled_services = api.settings.get('push_app_servers').filter(s => s.disable);
             const enabled = enabled_services.map(s => enablePushAppServer(domain, s));
             const disabled = disabled_services.map(s => disablePushAppServer(domain, s));
             try {

+ 4 - 4
src/converse-rosterview.js

@@ -20,7 +20,7 @@ import { OrderedListView } from "@converse/skeletor/src/overview";
 import { View } from '@converse/skeletor/src/view.js';
 import { __ } from './i18n';
 import { _converse, api, converse } from "@converse/headless/converse-core";
-import { compact, debounce, has, isString, uniq, without } from "lodash-es";
+import { compact, debounce, has, without } from "lodash-es";
 
 const { Strophe } = converse.env;
 const u = converse.env.utils;
@@ -72,7 +72,7 @@ converse.plugins.add('converse-rosterview', {
             },
 
             afterRender () {
-                if (api.settings.get('xhr_user_search_url') && isString(api.settings.get('xhr_user_search_url'))) {
+                if (typeof api.settings.get('xhr_user_search_url') === 'string') {
                     this.initXHRAutoComplete();
                 } else {
                     this.initJIDAutoComplete();
@@ -89,7 +89,7 @@ converse.plugins.add('converse-rosterview', {
                 this.jid_auto_complete = new _converse.AutoComplete(el, {
                     'data': (text, input) => `${input.slice(0, input.indexOf("@"))}@${text}`,
                     'filter': _converse.FILTER_STARTSWITH,
-                    'list': uniq(_converse.roster.map(item => Strophe.getDomainFromJid(item.get('jid'))))
+                    'list': [...new Set(_converse.roster.map(item => Strophe.getDomainFromJid(item.get('jid'))))]
                 });
             },
 
@@ -172,7 +172,7 @@ converse.plugins.add('converse-rosterview', {
                 const data = new FormData(ev.target),
                       jid = (data.get('jid') || '').trim();
 
-                if (!jid && api.settings.get('xhr_user_search_url') && isString(api.settings.get('xhr_user_search_url'))) {
+                if (!jid && typeof api.settings.get('xhr_user_search_url') === 'string') {
                     const input_el = this.el.querySelector('input[name="name"]');
                     this.xhr.open("GET", `${api.settings.get('xhr_user_search_url')}q=${encodeURIComponent(input_el.value)}`, true);
                     this.xhr.send()

+ 3 - 3
src/headless/connection.js

@@ -3,7 +3,7 @@ import sizzle from 'sizzle';
 import u from '@converse/headless/utils/core';
 import { Strophe } from 'strophe.js/src/core';
 import { _converse, api, clearSession, tearDown } from "./converse-core";
-import { debounce, isElement, noop } from 'lodash';
+import { debounce, isElement } from 'lodash';
 
 
 const BOSH_WAIT = 59;
@@ -362,9 +362,9 @@ export class MockConnection extends Connection {
                 '</session>'+
             '</stream:features>').firstChild;
 
-        this._proto._processRequest = noop;
+        this._proto._processRequest = () => {};
         this._proto._disconnect = () => this._onDisconnectTimeout();
-        this._proto._onDisconnectTimeout = noop;
+        this._proto._onDisconnectTimeout = () => {};
         this._proto._connect = () => {
             this.connected = true;
             this.mock = true;

+ 1 - 2
src/headless/converse-caps.js

@@ -5,7 +5,6 @@
  */
 import SHA1 from 'strophe.js/src/sha1';
 import { converse } from "@converse/headless/converse-core";
-import { get } from "lodash-es";
 
 const { Strophe, $build } = converse.env;
 
@@ -25,7 +24,7 @@ function generateVerificationString (_converse) {
         propertySort(identities, "lang");
     }
 
-    let S = identities.reduce((result, id) => `${result}${id.category}/${id.type}/${get(id, 'lang', '')}/${id.name}<`, "");
+    let S = identities.reduce((result, id) => `${result}${id.category}/${id.type}/${id?.lang ?? ''}/${id.name}<`, "");
     features.sort();
     S = features.reduce((result, feature) => `${result}${feature}<`, S);
     return SHA1.b64_sha1(S);

+ 5 - 5
src/headless/converse-chat.js

@@ -9,7 +9,7 @@ import st from "./utils/stanza";
 import { Collection } from "@converse/skeletor/src/collection";
 import { Model } from '@converse/skeletor/src/model.js';
 import { _converse, api, converse } from "./converse-core";
-import { find, isMatch, isObject, isString, pick } from "lodash-es";
+import { find, isMatch, isObject, pick } from "lodash-es";
 
 const { $msg, Strophe, sizzle, utils } = converse.env;
 const u = converse.env.utils;
@@ -1282,7 +1282,7 @@ converse.plugins.add('converse-chat', {
                 if (_converse.chatboxes.where({'jid': jid}).length) {
                     return;
                 }
-                if (isString(jid)) {
+                if (typeof jid === 'string') {
                     api.chats.open(jid);
                 } else {
                     log.error('Invalid jid criteria specified for "auto_join_private_chats"');
@@ -1338,7 +1338,7 @@ converse.plugins.add('converse-chat', {
                  * @param {object} [attrs] An object containing configuration attributes.
                  */
                 async create (jids, attrs) {
-                    if (isString(jids)) {
+                    if (typeof jids === 'string') {
                         if (attrs && !attrs?.fullname) {
                             const contact = await api.contacts.get(jids);
                             attrs.fullname = contact?.attributes?.fullname;
@@ -1402,7 +1402,7 @@ converse.plugins.add('converse-chat', {
                  * });
                  */
                 async open (jids, attrs, force) {
-                    if (isString(jids)) {
+                    if (typeof jids === 'string') {
                         const chat = await api.chats.get(jids, attrs, true);
                         if (chat) {
                             return chat.maybeShow(force);
@@ -1457,7 +1457,7 @@ converse.plugins.add('converse-chat', {
                     if (jids === undefined) {
                         const chats = await api.chatboxes.get();
                         return chats.filter(c => (c.get('type') === _converse.PRIVATE_CHAT_TYPE));
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         return _get(jids);
                     }
                     return Promise.all(jids.map(jid => _get(jid)));

+ 2 - 3
src/headless/converse-chatboxes.js

@@ -6,7 +6,6 @@
 import "./converse-emoji";
 import { Collection } from "@converse/skeletor/src/collection";
 import { _converse, api, converse } from "./converse-core";
-import { isString } from "lodash-es";
 import log from "./log";
 
 const { Strophe } = converse.env;
@@ -153,7 +152,7 @@ converse.plugins.add('converse-chatboxes', {
                  */
                 async create (jids=[], attrs={}, model) {
                     await api.waitUntil('chatBoxesFetched');
-                    if (isString(jids)) {
+                    if (typeof jids === 'string') {
                         return createChatBox(jids, attrs, model);
                     } else {
                         return Promise.all(jids.map(jid => createChatBox(jid, attrs, model)));
@@ -168,7 +167,7 @@ converse.plugins.add('converse-chatboxes', {
                     await api.waitUntil('chatBoxesFetched');
                     if (jids === undefined) {
                         return _converse.chatboxes.models;
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         return _converse.chatboxes.get(jids.toLowerCase());
                     } else {
                         jids = jids.map(j => j.toLowerCase());

+ 3 - 3
src/headless/converse-core.js

@@ -20,7 +20,7 @@ import { Events } from '@converse/skeletor/src/events.js';
 import { Model } from '@converse/skeletor/src/model.js';
 import { Router } from '@converse/skeletor/src/router.js';
 import { Strophe, $build, $iq, $msg, $pres } from 'strophe.js/src/strophe';
-import { assignIn, debounce, invoke, isFunction, isObject, isString, pick } from 'lodash-es';
+import { assignIn, debounce, invoke, isFunction, isObject, pick } from 'lodash-es';
 import { html } from 'lit-element';
 import { sprintf } from 'sprintf-js';
 
@@ -712,7 +712,7 @@ export const api = _converse.api = {
             if (isObject(key)) {
                 assignIn(_converse, pick(key, Object.keys(DEFAULT_SETTINGS)));
                 assignIn(_converse.settings, pick(key, Object.keys(DEFAULT_SETTINGS)));
-            } else if (isString('string')) {
+            } else if (typeof key === 'string') {
                 o[key] = val;
                 assignIn(_converse, pick(o, Object.keys(DEFAULT_SETTINGS)));
                 assignIn(_converse.settings, pick(o, Object.keys(DEFAULT_SETTINGS)));
@@ -887,7 +887,7 @@ export const api = _converse.api = {
             log.warn(Strophe.serialize(stanza));
             return;
         }
-        if (isString(stanza)) {
+        if (typeof stanza === 'string') {
             stanza = u.toStanza(stanza);
         }
         if (stanza.tagName === 'iq') {

+ 2 - 2
src/headless/converse-disco.js

@@ -9,7 +9,7 @@ import sizzle from "sizzle";
 import { Collection } from "@converse/skeletor/src/collection";
 import { Model } from '@converse/skeletor/src/model.js';
 import { _converse, api, converse } from "./converse-core";
-import { isEmpty, isObject } from "lodash-es";
+import { isObject } from "lodash-es";
 
 const { Strophe, $iq, utils } = converse.env;
 
@@ -172,7 +172,7 @@ converse.plugins.add('converse-disco', {
             },
 
             async queryForItems () {
-                if (isEmpty(this.identities.where({'category': 'server'}))) {
+                if (this.identities.where({'category': 'server'}).length === 0) {
                     // Don't fetch features and items if this is not a
                     // server or a conference component.
                     return;

+ 6 - 4
src/headless/converse-emoji.js

@@ -6,7 +6,6 @@
 import { ASCII_REPLACE_REGEX, CODEPOINTS_REGEX } from './emoji_regexes.js';
 import { Model } from '@converse/skeletor/src/model.js';
 import { _converse, api, converse } from "./converse-core";
-import { find, isString, uniq } from "lodash-es";
 import { html } from 'lit-html';
 
 const u = converse.env.utils;
@@ -89,10 +88,13 @@ function convert (unicode) {
     return fromCodePoint(unicode);
 }
 
+function unique (arr) {
+    return [...new Set(arr)];
+}
 
 function getTonedEmojis () {
     if (!converse.emojis.toned) {
-        converse.emojis.toned = uniq(
+        converse.emojis.toned = unique(
             Object.values(converse.emojis.json.people)
                 .filter(person => person.sn.includes('_tone'))
                 .map(person => person.sn.replace(/_tone[1-5]/, ''))
@@ -198,7 +200,7 @@ function addEmojisMarkup (text, options) {
         .forEach(ref => {
             const text = list.shift();
             const emoji = getEmojiMarkup(ref, options);
-            if (isString(emoji)) {
+            if (typeof emoji === 'string') {
                 list = [text.slice(0, ref.begin) + emoji + text.slice(ref.end), ...list];
             } else {
                 list = [text.slice(0, ref.begin), emoji, text.slice(ref.end), ...list];
@@ -349,7 +351,7 @@ converse.plugins.add('converse-emoji', {
                     .filter((c, i, arr) => arr.indexOf(c) == i);
 
                 emojis_by_attribute[attr] = {};
-                all_variants.forEach(v => (emojis_by_attribute[attr][v] = find(converse.emojis.list, i => (i[attr] === v))));
+                all_variants.forEach(v => (emojis_by_attribute[attr][v] = converse.emojis.list.find(i => i[attr] === v)));
                 return emojis_by_attribute[attr];
             }
         });

+ 1 - 2
src/headless/converse-headlines.js

@@ -3,7 +3,6 @@
  * @copyright 2020, the Converse.js contributors
  * @description XEP-0045 Multi-User Chat Views
  */
-import { isString } from "lodash-es";
 import { _converse, api, converse } from "@converse/headless/converse-core";
 import st from "./utils/stanza";
 
@@ -148,7 +147,7 @@ converse.plugins.add('converse-headlines', {
                     if (jids === undefined) {
                         const chats = await api.chatboxes.get();
                         return chats.filter(c => (c.get('type') === _converse.HEADLINES_TYPE));
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         return _get(jids);
                     }
                     return Promise.all(jids.map(jid => _get(jid)));

+ 10 - 10
src/headless/converse-muc.js

@@ -9,7 +9,7 @@ import "./converse-disco";
 import "./converse-emoji";
 import { Collection } from "@converse/skeletor/src/collection";
 import { Model } from '@converse/skeletor/src/model.js';
-import { clone, debounce, intersection, invoke, isElement, isObject, isString, pick, uniq, zipObject } from "lodash-es";
+import { debounce, intersection, invoke, isElement, isObject, pick, zipObject } from "lodash-es";
 import { _converse, api, converse } from "./converse-core";
 import log from "./log";
 import muc_utils from "./utils/muc";
@@ -135,7 +135,7 @@ converse.plugins.add('converse-muc', {
         });
         api.promises.add(['roomsAutoJoined']);
 
-        if (api.settings.get('locked_muc_domain') && !isString(api.settings.get('muc_domain'))) {
+        if (api.settings.get('locked_muc_domain') && (typeof api.settings.get('muc_domain') !== 'string')) {
             throw new Error("Config Error: it makes no sense to set locked_muc_domain "+
                             "to true when muc_domain is not set");
         }
@@ -1372,7 +1372,7 @@ converse.plugins.add('converse-muc', {
              * @returns { Promise }
              */
             setAffiliations (members) {
-                const affiliations = uniq(members.map(m => m.affiliation));
+                const affiliations = [...new Set(members.map(m => m.affiliation))];
                 return Promise.all(affiliations.map(a => this.setAffiliation(a, members)));
             },
 
@@ -1713,7 +1713,7 @@ converse.plugins.add('converse-muc', {
              *  message, as returned by {@link st.parseMUCMessage}
              */
             async handleSubjectChange (attrs) {
-                if (isString(attrs.subject) && !attrs.thread && !attrs.message) {
+                if (typeof attrs.subject === 'string' && !attrs.thread && !attrs.message) {
                     // https://xmpp.org/extensions/xep-0045.html#subject-mod
                     // -----------------------------------------------------
                     // The subject is changed by sending a message of type "groupchat" to the <room@service>,
@@ -2697,13 +2697,13 @@ converse.plugins.add('converse-muc', {
          */
         async function autoJoinRooms () {
             await Promise.all(api.settings.get('auto_join_rooms').map(muc => {
-                if (isString(muc)) {
+                if (typeof muc === 'string') {
                     if (_converse.chatboxes.where({'jid': muc}).length) {
                         return Promise.resolve();
                     }
                     return api.rooms.open(muc);
                 } else if (isObject(muc)) {
-                    return api.rooms.open(muc.jid, clone(muc));
+                    return api.rooms.open(muc.jid, {...muc});
                 } else {
                     log.error('Invalid muc criteria specified for "auto_join_rooms"');
                     return Promise.resolve();
@@ -2816,13 +2816,13 @@ converse.plugins.add('converse-muc', {
                  * @returns {Promise} Promise which resolves with the Model representing the chat.
                  */
                 create (jids, attrs={}) {
-                    attrs = isString(attrs) ? {'nick': attrs} : (attrs || {});
+                    attrs = typeof attrs === 'string' ? {'nick': attrs} : (attrs || {});
                     if (!attrs.nick && api.settings.get('muc_nickname_from_jid')) {
                         attrs.nick = Strophe.getNodeFromJid(_converse.bare_jid);
                     }
                     if (jids === undefined) {
                         throw new TypeError('rooms.create: You need to provide at least one JID');
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         return createChatRoom(jids, attrs);
                     }
                     return jids.map(jid => createChatRoom(jid, attrs));
@@ -2893,7 +2893,7 @@ converse.plugins.add('converse-muc', {
                         const err_msg = 'rooms.open: You need to provide at least one JID';
                         log.error(err_msg);
                         throw(new TypeError(err_msg));
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         const room = await api.rooms.create(jids, attrs);
                         room && room.maybeShow(force);
                         return room;
@@ -2944,7 +2944,7 @@ converse.plugins.add('converse-muc', {
                     if (jids === undefined) {
                         const chats = await api.chatboxes.get();
                         return chats.filter(c => (c.get('type') === _converse.CHATROOMS_TYPE));
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         return _get(jids);
                     }
                     return Promise.all(jids.map(jid => _get(jid)));

+ 6 - 7
src/headless/converse-roster.js

@@ -6,7 +6,7 @@
 import "@converse/headless/converse-status";
 import { Collection } from "@converse/skeletor/src/collection";
 import { Model } from '@converse/skeletor/src/model.js';
-import { invoke, isEmpty, isNaN, isString, propertyOf, sum } from "lodash-es";
+import { invoke, isNaN, propertyOf, sum } from "lodash-es";
 import { _converse, api, converse } from "@converse/headless/converse-core";
 import log from "./log";
 
@@ -514,7 +514,7 @@ converse.plugins.add('converse-roster', {
              * @param { Function } errback - A function to call if an error occurred
              */
             sendContactAddIQ (jid, name, groups) {
-                name = isEmpty(name) ? null : name;
+                name = name ? name : null;
                 const iq = $iq({'type': 'set'})
                     .c('query', {'xmlns': Strophe.NS.ROSTER})
                     .c('item', { jid, name });
@@ -1075,7 +1075,7 @@ converse.plugins.add('converse-roster', {
                     const _getter = jid => _converse.roster.get(Strophe.getBareJidFromJid(jid));
                     if (jids === undefined) {
                         jids = _converse.roster.pluck('jid');
-                    } else if (isString(jids)) {
+                    } else if (typeof jids === 'string') {
                         return _getter(jids);
                     }
                     return jids.map(_getter);
@@ -1086,8 +1086,7 @@ converse.plugins.add('converse-roster', {
                  *
                  * @method _converse.api.contacts.add
                  * @param {string} jid The JID of the contact to be added
-                 * @param {string} [name] A custom name to show the user by
-                 *     in the roster.
+                 * @param {string} [name] A custom name to show the user by in the roster
                  * @example
                  *     _converse.api.contacts.add('buddy@example.com')
                  * @example
@@ -1095,10 +1094,10 @@ converse.plugins.add('converse-roster', {
                  */
                 async add (jid, name) {
                     await api.waitUntil('rosterContactsFetched');
-                    if (!isString(jid) || !jid.includes('@')) {
+                    if (typeof jid !== 'string' || !jid.includes('@')) {
                         throw new TypeError('contacts.add: invalid jid');
                     }
-                    return _converse.roster.addAndSubscribe(jid, isEmpty(name)? jid: name);
+                    return _converse.roster.addAndSubscribe(jid, name);
                 }
             }
         });

+ 4 - 4
src/headless/converse-status.js

@@ -3,7 +3,7 @@
  * @copyright The Converse.js contributors
  * @license Mozilla Public License (MPLv2)
  */
-import { isNaN, isObject, isString } from "lodash-es";
+import { isNaN, isObject } from "lodash-es";
 import { Model } from '@converse/skeletor/src/model.js';
 import { _converse, api, converse } from "@converse/headless/converse-core";
 
@@ -49,8 +49,8 @@ converse.plugins.add('converse-status', {
             },
 
             constructPresence (type, to=null, status_message) {
-                type = isString(type) ? type : (this.get('status') || api.settings.get("default_state"));
-                status_message = isString(status_message) ? status_message : this.get('status_message');
+                type = typeof type === 'string' ? type : (this.get('status') || api.settings.get("default_state"));
+                status_message = typeof status_message === 'string' ? status_message : this.get('status_message');
                 let presence;
                 const attrs = {to};
                 if ((type === 'unavailable') ||
@@ -293,7 +293,7 @@ converse.plugins.add('converse-status', {
                             'Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1'
                         );
                     }
-                    if (isString(message)) {
+                    if (typeof message === 'string') {
                         data.status_message = message;
                     }
                     await api.waitUntil('statusInitialized');

+ 4 - 5
src/headless/converse-vcard.js

@@ -8,7 +8,6 @@ import log from "@converse/headless/log";
 import { Collection } from "@converse/skeletor/src/collection";
 import { Model } from '@converse/skeletor/src/model.js';
 import { _converse, api, converse } from "./converse-core";
-import { has, isString } from "lodash-es";
 
 const { Strophe, $iq, dayjs } = converse.env;
 const u = converse.env.utils;
@@ -30,7 +29,7 @@ converse.plugins.add('converse-vcard', {
                 }
             },
 
-            getFullname (){
+            getFullname () {
                 const { _converse } = this.__super__;
                 const fullname = this.__super__.getFullname.apply(this);
                 if (!fullname && _converse.xmppstatus.vcard) {
@@ -88,7 +87,7 @@ converse.plugins.add('converse-vcard', {
                 } else {
                     (attrs = {})[key] = val;
                 }
-                if (has(attrs, 'image') && !attrs['image']) {
+                if ('image' in attrs && !attrs['image']) {
                     attrs['image'] = _converse.DEFAULT_IMAGE;
                     attrs['image_type'] = _converse.DEFAULT_IMAGE_TYPE;
                     return Model.prototype.set.call(this, attrs, options);
@@ -337,7 +336,7 @@ converse.plugins.add('converse-vcard', {
                  * });
                  */
                  get (model, force) {
-                    if (isString(model)) {
+                    if (typeof model === 'string') {
                         return getVCard(_converse, model);
                     } else if (force ||
                             !model.get('vcard_updated') ||
@@ -371,7 +370,7 @@ converse.plugins.add('converse-vcard', {
                  */
                 async update (model, force) {
                     const data = await this.get(model, force);
-                    model = isString(model) ? _converse.vcards.findWhere({'jid': model}) : model;
+                    model = typeof model === 'string' ? _converse.vcards.findWhere({'jid': model}) : model;
                     if (!model) {
                         log.error(`Could not find a VCard model for ${model}`);
                         return;

+ 4 - 4
src/headless/utils/core.js

@@ -5,7 +5,7 @@
  */
 import * as strophe from 'strophe.js/src/core';
 import { Model } from '@converse/skeletor/src/model.js';
-import { compact, last, isElement, isObject, isString } from "lodash-es";
+import { compact, last, isElement, isObject } from "lodash-es";
 import log from "@converse/headless/log";
 import sizzle from "sizzle";
 
@@ -71,7 +71,7 @@ u.prefixMentions = function (message) {
 };
 
 u.isValidJID = function (jid) {
-    if (isString(jid)) {
+    if (typeof jid === 'string') {
         return compact(jid.split('@')).length === 2 && !jid.startsWith('@') && !jid.endsWith('@');
     }
     return false;
@@ -82,7 +82,7 @@ u.isValidMUCJID = function (jid) {
 };
 
 u.isSameBareJID = function (jid1, jid2) {
-    if (!isString(jid1) || !isString(jid2)) {
+    if (typeof jid1 !== 'string' || typeof jid2 !== 'string') {
         return false;
     }
     return Strophe.getBareJidFromJid(jid1).toLowerCase() ===
@@ -91,7 +91,7 @@ u.isSameBareJID = function (jid1, jid2) {
 
 
 u.isSameDomain = function (jid1, jid2) {
-    if (!isString(jid1) || !isString(jid2)) {
+    if (typeof jid1 !== 'string' || typeof jid2 !== 'string') {
         return false;
     }
     return Strophe.getDomainFromJid(jid1).toLowerCase() ===

+ 1 - 1
src/templates/directives/body.js

@@ -3,7 +3,6 @@ import log from '@converse/headless/log';
 import { _converse, api, converse } from  "@converse/headless/converse-core";
 import { convertASCII2Emoji, getEmojiMarkup, getCodePointReferences, getShortnameReferences } from "@converse/headless/converse-emoji.js";
 import { directive, html } from "lit-html";
-import { isString } from "lodash-es";
 import { until } from 'lit-html/directives/until.js';
 
 const u = converse.env.utils;
@@ -84,6 +83,7 @@ class MessageText extends String {
         // Subtract `/me ` from 3rd person messages
         if (this.isMeCommand()) list[0] = list[0].substring(4);
 
+        const isString = (s) => typeof s === 'string';
         return list.reduce((acc, i) => isString(i) ? [...acc, MessageText.replaceText(i)] : [...acc, i], []);
     }
 }