Skip to content

Commit

Permalink
Added typeof method (#812)
Browse files Browse the repository at this point in the history
* Add typeof method to check exact type of object #805

* Update changelog
  • Loading branch information
gohabereg committed Jun 30, 2019
1 parent 8da784f commit 5c04e03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `Improvements` — Inline Toolbar now works on mobile devices [#706](https://github.com/codex-team/editor.js/issues/706)
- `Improvements` — Toolbar looks better on mobile devices [#706](https://github.com/codex-team/editor.js/issues/706)
- `Fix` — Resolve bug with deleting leading new lines [#726](https://github.com/codex-team/editor.js/issues/726)
- `Fix` — Added `typeof` util method to check exact object type [#805](https://github.com/codex-team/editor.js/issues/805)

### 2.14

Expand Down
10 changes: 9 additions & 1 deletion src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default class Util {
* @return {object}
*/
public static deepMerge(target, ...sources) {
const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
const isObject = (item) => item && Util.typeof(item) === 'object';

if (!sources.length) { return target; }
const source = sources.shift();
Expand Down Expand Up @@ -351,4 +351,12 @@ export default class Util {
return 'ontouchstart' in document.documentElement;
}

/**
* Return string representation of the object type
*
* @param {any} object
*/
public static typeof(object: any): string {
return Object.prototype.toString.call(object).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}
}

0 comments on commit 5c04e03

Please sign in to comment.