Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace typeofs #1434

Merged
merged 8 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class EditorJS {
/**
* If `onReady` was passed in `configuration` then redefine onReady function
*/
if (typeof configuration === 'object' && _.isFunction(configuration.onReady)) {
if (_.isObject(configuration) && _.isFunction(configuration.onReady)) {
onReady = configuration.onReady;
}

Expand Down
1 change: 0 additions & 1 deletion src/components/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export default class Block {
* @param {BlockToolData} options.data - Tool's initial data
* @param {BlockToolConstructable} options.Tool — Tool's class
* @param {ToolSettings} options.settings - default tool's config
* @param {Module} options.api - Editor API module for pass it to the Block Tunes
* @param {boolean} options.readOnly - Read-Only flag
*/
constructor({
Expand Down
6 changes: 3 additions & 3 deletions src/components/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class Core {
* Process zero-configuration or with only holderId
* Make config object
*/
if (typeof config !== 'object') {
if (!_.isObject(config)) {
config = {
holder: config,
};
Expand Down Expand Up @@ -246,11 +246,11 @@ export default class Core {
/**
* Check for a holder element's existence
*/
if (typeof holder === 'string' && !$.get(holder)) {
if (_.isString(holder) && !$.get(holder)) {
throw Error(`element with ID «${holder}» is missing. Pass correct holder's ID.`);
}

if (holder && typeof holder === 'object' && !$.isElement(holder)) {
if (holder && _.isObject(holder) && !$.isElement(holder)) {
throw Error('holder as HTMLElement if provided must be inherit from Element class.');
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export default class Dom {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static isElement(node: any): node is Element {
return node && typeof node === 'object' && node.nodeType && node.nodeType === Node.ELEMENT_NODE;
return node && node.nodeType && node.nodeType === Node.ELEMENT_NODE;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -303,7 +303,7 @@ export default class Dom {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static isFragment(node: any): node is DocumentFragment {
return node && typeof node === 'object' && node.nodeType && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
return node && node.nodeType && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -532,7 +532,7 @@ export default class Dom {
public static containsOnlyInlineElements(data: string | HTMLElement): boolean {
let wrapper: HTMLElement;

if (typeof data === 'string') {
if (_.isString(data)) {
wrapper = document.createElement('div');
wrapper.innerHTML = data;
} else {
Expand Down Expand Up @@ -572,7 +572,7 @@ export default class Dom {
* @returns {HTMLElement}
*/
public static getHolder(element: string | HTMLElement): HTMLElement {
if (typeof element === 'string') {
if (_.isString(element)) {
return document.getElementById(element);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/flipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class Flipper {
* @param {FlipperOptions} options - different constructing settings
*/
constructor(options: FlipperOptions) {
this.allowArrows = typeof options.allowArrows === 'boolean' ? options.allowArrows : true;
this.allowArrows = _.isBoolean(options.allowArrows) ? options.allowArrows : true;
this.iterator = new DomIterator(options.items, options.focusedItemClass);
this.activateCallback = options.activateCallback;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/i18n/namespace-internal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import defaultDictionary from './locales/en/messages.json';
import { DictNamespaces } from '../../types-internal/i18n-internal-namespace';
import { typeOf } from '../utils';
import { isObject, isString } from '../utils';

/**
* Evaluate messages dictionary and return object for namespace chaining
Expand All @@ -12,14 +12,14 @@ function getNamespaces(dict: object, keyPath?: string): DictNamespaces<typeof de
const result = {};

Object.entries(dict).forEach(([key, section]) => {
if (typeOf(section) === 'object') {
if (isObject(section)) {
const newPath = keyPath ? `${keyPath}.${key}` : key;

/**
* Check current section values, if all of them are strings, so there is the last section
*/
const isLastSection = Object.values(section).every((sectionValue) => {
return typeOf(sectionValue) === 'string';
return isString(sectionValue);
});

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export default class Paste extends Module {
return;
}

if (typeof toolInstance.onPaste !== 'function') {
if (!_.isFunction(toolInstance.onPaste)) {
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/modules/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class Sanitizer extends Module {
* Array: call sanitize for each item
*/
return this.cleanArray(dataToSanitize, rules);
} else if (typeof dataToSanitize === 'object') {
} else if (_.isObject(dataToSanitize)) {
/**
* Objects: just clean object deeper.
*/
Expand All @@ -105,7 +105,7 @@ export default class Sanitizer extends Module {
*
* Clean only strings
*/
if (typeof dataToSanitize === 'string') {
if (_.isString(dataToSanitize)) {
return this.cleanOneItem(dataToSanitize, rules);
}

Expand Down Expand Up @@ -169,7 +169,7 @@ export default class Sanitizer extends Module {
if (Object.prototype.hasOwnProperty.call(toolRules, fieldName)) {
const rule = toolRules[fieldName];

if (typeof rule === 'object') {
if (_.isObject(rule)) {
toolConfig[fieldName] = Object.assign({}, baseConfig, rule);
} else {
toolConfig[fieldName] = rule;
Expand All @@ -195,7 +195,7 @@ export default class Sanitizer extends Module {

let config = {} as SanitizerConfig;

if (typeof enableInlineTools === 'boolean' && enableInlineTools) {
if (_.isBoolean(enableInlineTools) && enableInlineTools) {
/**
* getting all tools sanitizer rule
*/
Expand Down Expand Up @@ -292,7 +292,7 @@ export default class Sanitizer extends Module {
* @returns {string}
*/
private cleanOneItem(taintString: string, rule: SanitizerConfig|boolean): string {
if (typeof rule === 'object') {
if (_.isObject(rule)) {
return this.clean(taintString, rule);
} else if (rule === false) {
return this.clean(taintString, {} as SanitizerConfig);
Expand All @@ -309,7 +309,7 @@ export default class Sanitizer extends Module {
* @param {SanitizerConfig} config - config to check
*/
private isRule(config: SanitizerConfig): boolean {
return typeof config === 'object' || typeof config === 'boolean' || _.isFunction(config);
return _.isObject(config) || _.isBoolean(config) || _.isFunction(config);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/toolbar/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {

if (_.isFunction(exportProp)) {
exportData = exportProp(blockData);
} else if (typeof exportProp === 'string') {
} else if (_.isString(exportProp)) {
exportData = blockData[exportProp];
} else {
_.log('Conversion «export» property must be a string or function. ' +
Expand All @@ -242,7 +242,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {

if (_.isFunction(importProp)) {
newBlockData = importProp(cleaned);
} else if (typeof importProp === 'string') {
} else if (_.isString(importProp)) {
newBlockData[importProp] = cleaned;
} else {
_.log('Conversion «import» property must be a string or function. ' +
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
* Returns inline toolbar settings for a particular tool
*
* @param {string} toolName - user specified name of tool
* @returns - array of ordered tool names or false
* @returns {string[] | boolean} array of ordered tool names or false
*/
private getInlineToolbarSettings(toolName): string[] | boolean {
const toolSettings = this.Editor.Tools.getToolSettings(toolName);
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default class Tools extends Module {
* If Tool is an object not a Tool's class then
* save class and settings separately
*/
if (typeof this.config.tools[toolName] === 'object') {
if (_.isObject(this.config.tools[toolName])) {
/**
* Save Tool's class from 'class' field
*
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export default class UI extends Module<UINodes> {
* @param {KeyboardEvent} event - keyboard event
*/
private enterPressed(event: KeyboardEvent): void {
const { BlockManager, BlockSelection, Caret } = this.Editor;
const { BlockManager, BlockSelection } = this.Editor;
const hasPointerToBlock = BlockManager.currentBlockIndex >= 0;

/**
Expand Down
Loading