From c1f97c4ea4c3998ac8e378749dad2ac5dd330acc Mon Sep 17 00:00:00 2001 From: pimlie Date: Sat, 9 Mar 2019 18:28:15 +0100 Subject: [PATCH] refactor: move isArray into is-type --- src/browser.js | 2 +- src/client/refresh.js | 2 +- src/client/updateClientMetaInfo.js | 2 +- src/client/updaters/attribute.js | 2 +- src/client/updaters/tag.js | 2 +- src/server/generators/attribute.js | 3 +-- src/server/generators/tag.js | 2 +- src/shared/applyTemplate.js | 2 +- src/shared/ensure.js | 3 +-- src/shared/escape.js | 3 +-- src/shared/getComponentOption.js | 2 +- src/shared/hasMetaInfo.js | 2 +- src/shared/inMetaInfoBranch.js | 2 +- src/shared/is-type.js | 26 ++++++++++++++++++++++++++ src/shared/isArray.js | 10 ---------- src/shared/mixin.js | 2 +- src/shared/options.js | 2 +- src/shared/typeof.js | 15 --------------- src/shared/window.js | 2 +- 19 files changed, 42 insertions(+), 44 deletions(-) create mode 100644 src/shared/is-type.js delete mode 100644 src/shared/isArray.js delete mode 100644 src/shared/typeof.js diff --git a/src/browser.js b/src/browser.js index 885f415..c459669 100644 --- a/src/browser.js +++ b/src/browser.js @@ -1,7 +1,7 @@ import { version } from '../package.json' import createMixin from './shared/mixin' import setOptions from './shared/options' -import { isUndefined } from './shared/typeof' +import { isUndefined } from './shared/is-type' import $meta from './client/$meta' import hasMetaInfo from './shared/hasMetaInfo' diff --git a/src/client/refresh.js b/src/client/refresh.js index a70deee..9c11e0b 100644 --- a/src/client/refresh.js +++ b/src/client/refresh.js @@ -1,5 +1,5 @@ import getMetaInfo from '../shared/getMetaInfo' -import { isFunction } from '../shared/typeof' +import { isFunction } from '../shared/is-type' import updateClientMetaInfo from './updateClientMetaInfo' export default function _refresh(options = {}) { diff --git a/src/client/updateClientMetaInfo.js b/src/client/updateClientMetaInfo.js index 633a9a3..30c7800 100644 --- a/src/client/updateClientMetaInfo.js +++ b/src/client/updateClientMetaInfo.js @@ -1,5 +1,5 @@ import { metaInfoOptionKeys, metaInfoAttributeKeys } from '../shared/constants' -import isArray from '../shared/isArray' +import { isArray } from '../shared/is-type' import { updateAttribute, updateTag, updateTitle } from './updaters' function getTag(tags, tag) { diff --git a/src/client/updaters/attribute.js b/src/client/updaters/attribute.js index 6780c7c..ec05073 100644 --- a/src/client/updaters/attribute.js +++ b/src/client/updaters/attribute.js @@ -1,5 +1,5 @@ import { booleanHtmlAttributes } from '../../shared/constants' -import isArray from '../../shared/isArray' +import { isArray } from '../../shared/is-type' /** * Updates the document's html tag attributes diff --git a/src/client/updaters/tag.js b/src/client/updaters/tag.js index 5b28ff9..9739344 100644 --- a/src/client/updaters/tag.js +++ b/src/client/updaters/tag.js @@ -1,4 +1,4 @@ -import { isUndefined } from '../../shared/typeof' +import { isUndefined } from '../../shared/is-type' /** * Updates meta tags inside and on the client. Borrowed from `react-helmet`: diff --git a/src/server/generators/attribute.js b/src/server/generators/attribute.js index 9b24b53..0ac406a 100644 --- a/src/server/generators/attribute.js +++ b/src/server/generators/attribute.js @@ -1,6 +1,5 @@ import { booleanHtmlAttributes } from '../../shared/constants' -import { isUndefined } from '../../shared/typeof' -import isArray from '../../shared/isArray' +import { isUndefined, isArray } from '../../shared/is-type' /** * Generates tag attributes for use on the server. diff --git a/src/server/generators/tag.js b/src/server/generators/tag.js index ae481de..2849ed2 100644 --- a/src/server/generators/tag.js +++ b/src/server/generators/tag.js @@ -1,5 +1,5 @@ import { booleanHtmlAttributes, tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants' -import { isUndefined } from '../../shared/typeof' +import { isUndefined } from '../../shared/is-type' /** * Generates meta, base, link, style, script, noscript tags for use on the server diff --git a/src/shared/applyTemplate.js b/src/shared/applyTemplate.js index 5805f6f..ca5bc81 100644 --- a/src/shared/applyTemplate.js +++ b/src/shared/applyTemplate.js @@ -1,4 +1,4 @@ -import { isUndefined, isFunction } from './typeof' +import { isUndefined, isFunction } from './is-type' export default function applyTemplate({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) { if (isUndefined(template)) { diff --git a/src/shared/ensure.js b/src/shared/ensure.js index 3054549..865ac3e 100644 --- a/src/shared/ensure.js +++ b/src/shared/ensure.js @@ -1,5 +1,4 @@ -import isArray from './isArray' -import { isObject } from './typeof' +import { isArray, isObject } from './is-type' export function ensureIsArray(arg, key) { if (!key || !isObject(arg)) { diff --git a/src/shared/escape.js b/src/shared/escape.js index 77b73e3..e190b7f 100644 --- a/src/shared/escape.js +++ b/src/shared/escape.js @@ -1,6 +1,5 @@ import { metaInfoOptionKeys, disableOptionKeys } from './constants' -import isArray from './isArray' -import { isString, isObject } from './typeof' +import { isString, isArray, isObject } from './is-type' // sanitizes potentially dangerous characters export default function escape(info, options, escapeOptions) { diff --git a/src/shared/getComponentOption.js b/src/shared/getComponentOption.js index ae819a8..b66df4c 100644 --- a/src/shared/getComponentOption.js +++ b/src/shared/getComponentOption.js @@ -1,7 +1,7 @@ import { merge } from './merge' import applyTemplate from './applyTemplate' import inMetaInfoBranch from './inMetaInfoBranch' -import { isFunction, isObject } from './typeof' +import { isFunction, isObject } from './is-type' /** * Returns the `opts.option` $option value of the given `opts.component`. diff --git a/src/shared/hasMetaInfo.js b/src/shared/hasMetaInfo.js index 7946896..033c34a 100644 --- a/src/shared/hasMetaInfo.js +++ b/src/shared/hasMetaInfo.js @@ -1,4 +1,4 @@ -import { isObject } from './typeof' +import { isObject } from './is-type' // Vue $root instance has a _vueMeta object property, otherwise its a boolean true export default function hasMetaInfo(vm = this) { diff --git a/src/shared/inMetaInfoBranch.js b/src/shared/inMetaInfoBranch.js index e2884d9..cf89e9e 100644 --- a/src/shared/inMetaInfoBranch.js +++ b/src/shared/inMetaInfoBranch.js @@ -1,4 +1,4 @@ -import { isUndefined } from './typeof' +import { isUndefined } from './is-type' // a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has export default function inMetaInfoBranch(vm = this) { diff --git a/src/shared/is-type.js b/src/shared/is-type.js new file mode 100644 index 0000000..220cab7 --- /dev/null +++ b/src/shared/is-type.js @@ -0,0 +1,26 @@ +/** + * checks if passed argument is an array + * @param {any} arr - the object to check + * @return {Boolean} - true if `arr` is an array + */ +export function isArray(arr) { + return Array.isArray + ? Array.isArray(arr) + : Object.prototype.toString.call(arr) === '[object Array]' +} + +export function isUndefined(arg) { + return typeof arg === 'undefined' +} + +export function isObject(arg) { + return typeof arg === 'object' +} + +export function isFunction(arg) { + return typeof arg === 'function' +} + +export function isString(arg) { + return typeof arg === 'string' +} diff --git a/src/shared/isArray.js b/src/shared/isArray.js deleted file mode 100644 index 698b037..0000000 --- a/src/shared/isArray.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * checks if passed argument is an array - * @param {any} arr - the object to check - * @return {Boolean} - true if `arr` is an array - */ -export default function isArray(arr) { - return Array.isArray - ? Array.isArray(arr) - : Object.prototype.toString.call(arr) === '[object Array]' -} diff --git a/src/shared/mixin.js b/src/shared/mixin.js index 1faf876..ca6b83f 100644 --- a/src/shared/mixin.js +++ b/src/shared/mixin.js @@ -1,6 +1,6 @@ import triggerUpdate from '../client/triggerUpdate' import hasMetaInfo from './hasMetaInfo' -import { isUndefined, isFunction } from './typeof' +import { isUndefined, isFunction } from './is-type' import { ensuredPush } from './ensure' export default function createMixin(Vue, options) { diff --git a/src/shared/options.js b/src/shared/options.js index eb81847..8547fd4 100644 --- a/src/shared/options.js +++ b/src/shared/options.js @@ -1,4 +1,4 @@ -import { isObject, isFunction } from './typeof' +import { isObject, isFunction } from './is-type' import { keyName, diff --git a/src/shared/typeof.js b/src/shared/typeof.js deleted file mode 100644 index c6b39b2..0000000 --- a/src/shared/typeof.js +++ /dev/null @@ -1,15 +0,0 @@ -export function isUndefined(arg) { - return typeof arg === 'undefined' -} - -export function isObject(arg) { - return typeof arg === 'object' -} - -export function isFunction(arg) { - return typeof arg === 'function' -} - -export function isString(arg) { - return typeof arg === 'string' -} diff --git a/src/shared/window.js b/src/shared/window.js index 118705e..d31dbab 100644 --- a/src/shared/window.js +++ b/src/shared/window.js @@ -1,4 +1,4 @@ -import { isUndefined } from './typeof' +import { isUndefined } from './is-type' export function hasGlobalWindowFn() { try {