mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-23 15:30:34 +03:00
chore: fix lint
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ import { hasMetaInfo } from './shared/meta-helpers'
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
function install(Vue, options = {}) {
|
||||
function install (Vue, options = {}) {
|
||||
if (Vue.__vuemeta_installed) {
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { getOptions } from '../shared/options'
|
||||
import { pause, resume } from '../shared/pausing'
|
||||
import refresh from './refresh'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
export default function _$meta (options = {}) {
|
||||
const _refresh = refresh(options)
|
||||
const inject = () => {}
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function _$meta(options = {}) {
|
||||
* @this {Object} - the Vue instance (a root component)
|
||||
* @return {Object} - injector
|
||||
*/
|
||||
return function $meta() {
|
||||
return function $meta () {
|
||||
if (!this.$root._vueMeta) {
|
||||
return {
|
||||
getOptions: showWarningNotSupported,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isFunction } from '../utils/is-type'
|
||||
import { clientSequences } from '../shared/escaping'
|
||||
import updateClientMetaInfo from './updateClientMetaInfo'
|
||||
|
||||
export default function _refresh(options = {}) {
|
||||
export default function _refresh (options = {}) {
|
||||
/**
|
||||
* When called, will update the current meta info with new meta info.
|
||||
* Useful when updating meta info as the result of an asynchronous
|
||||
@@ -14,7 +14,7 @@ export default function _refresh(options = {}) {
|
||||
*
|
||||
* @return {Object} - new meta info
|
||||
*/
|
||||
return function refresh() {
|
||||
return function refresh () {
|
||||
const metaInfo = getMetaInfo(options, this.$root, clientSequences)
|
||||
|
||||
const appId = this.$root._vueMeta.appId
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// store an id to keep track of DOM updates
|
||||
let batchId = null
|
||||
|
||||
export function triggerUpdate(vm, hookName) {
|
||||
export function triggerUpdate (vm, hookName) {
|
||||
// if an update was triggered during initialization or when an update was triggered by the
|
||||
// metaInfo watcher, set initialized to null
|
||||
// then we keep falsy value but know we need to run a triggerUpdate after initialization
|
||||
@@ -22,7 +22,7 @@ export function triggerUpdate(vm, hookName) {
|
||||
* @param {Function} callback - the update to perform
|
||||
* @return {Number} id - a new ID
|
||||
*/
|
||||
export function batchUpdate(callback, timeout = 10) {
|
||||
export function batchUpdate (callback, timeout = 10) {
|
||||
clearTimeout(batchId)
|
||||
|
||||
batchId = setTimeout(() => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isArray } from '../utils/is-type'
|
||||
import { includes } from '../utils/array'
|
||||
import { updateAttribute, updateTag, updateTitle } from './updaters'
|
||||
|
||||
function getTag(tags, tag) {
|
||||
function getTag (tags, tag) {
|
||||
if (!tags[tag]) {
|
||||
tags[tag] = document.getElementsByTagName(tag)[0]
|
||||
}
|
||||
@@ -16,7 +16,7 @@ function getTag(tags, tag) {
|
||||
*
|
||||
* @param {Object} newInfo - the meta info to update to
|
||||
*/
|
||||
export default function updateClientMetaInfo(appId, options = {}, newInfo) {
|
||||
export default function updateClientMetaInfo (appId, options = {}, newInfo) {
|
||||
const { ssrAttribute } = options
|
||||
|
||||
// only cache tags for current update
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isArray } from '../../utils/is-type'
|
||||
* @param {Object} attrs - the new document html attributes
|
||||
* @param {HTMLElement} tag - the HTMLElement tag to update with new attrs
|
||||
*/
|
||||
export default function updateAttribute({ attribute } = {}, attrs, tag) {
|
||||
export default function updateAttribute ({ attribute } = {}, attrs, tag) {
|
||||
const vueMetaAttrString = tag.getAttribute(attribute)
|
||||
const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : []
|
||||
const toRemove = toArray(vueMetaAttrs)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { booleanHtmlAttributes } from '../../shared/constants'
|
||||
import { isUndefined } from '../../utils/is-type'
|
||||
import { toArray, includes } from '../../utils/array'
|
||||
|
||||
/**
|
||||
@@ -10,7 +9,7 @@ import { toArray, includes } from '../../utils/array'
|
||||
* @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
|
||||
* @return {Object} - a representation of what tags changed
|
||||
*/
|
||||
export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type, tags, headTag, bodyTag) {
|
||||
export default function updateTag (appId, { attribute, tagIDKeyName } = {}, type, tags, headTag, bodyTag) {
|
||||
const oldHeadTags = toArray(headTag.querySelectorAll(`${type}[${attribute}="${appId}"], ${type}[data-${tagIDKeyName}]`))
|
||||
const oldBodyTags = toArray(bodyTag.querySelectorAll(`${type}[${attribute}="${appId}"][data-body="true"], ${type}[data-${tagIDKeyName}][data-body="true"]`))
|
||||
const dataAttributes = [tagIDKeyName, 'body']
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* @param {String} title - the new title of the document
|
||||
*/
|
||||
export default function updateTitle(title) {
|
||||
export default function updateTitle (title) {
|
||||
if (title === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import { hasMetaInfo } from './shared/meta-helpers'
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
function install(Vue, options = {}) {
|
||||
function install (Vue, options = {}) {
|
||||
if (Vue.__vuemeta_installed) {
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { pause, resume } from '../shared/pausing'
|
||||
import refresh from '../client/refresh'
|
||||
import inject from './inject'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
export default function _$meta (options = {}) {
|
||||
const _refresh = refresh(options)
|
||||
const _inject = inject(options)
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function _$meta(options = {}) {
|
||||
* @this {Object} - the Vue instance (a root component)
|
||||
* @return {Object} - injector
|
||||
*/
|
||||
return function $meta() {
|
||||
return function $meta () {
|
||||
return {
|
||||
getOptions: () => getOptions(options),
|
||||
refresh: _refresh.bind(this),
|
||||
|
||||
@@ -9,7 +9,7 @@ import { titleGenerator, attributeGenerator, tagGenerator } from './generators'
|
||||
* @return {Object} - the new injector
|
||||
*/
|
||||
|
||||
export default function generateServerInjector(appId, options, type, data) {
|
||||
export default function generateServerInjector (appId, options, type, data) {
|
||||
if (type === 'title') {
|
||||
return titleGenerator(appId, options, type, data)
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import { isUndefined, isArray } from '../../utils/is-type'
|
||||
* @param {Object} data - the attributes to generate
|
||||
* @return {Object} - the attribute generator
|
||||
*/
|
||||
export default function attributeGenerator({ attribute } = {}, type, data) {
|
||||
export default function attributeGenerator ({ attribute } = {}, type, data) {
|
||||
return {
|
||||
text() {
|
||||
text () {
|
||||
let attributeStr = ''
|
||||
const watchedAttrs = []
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { booleanHtmlAttributes, tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'
|
||||
import { isUndefined } from '../../utils/is-type'
|
||||
|
||||
/**
|
||||
* Generates meta, base, link, style, script, noscript tags for use on the server
|
||||
@@ -8,9 +7,9 @@ import { isUndefined } from '../../utils/is-type'
|
||||
* @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
|
||||
* @return {Object} - the tag generator
|
||||
*/
|
||||
export default function tagGenerator(appId, { attribute, tagIDKeyName } = {}, type, tags) {
|
||||
export default function tagGenerator (appId, { attribute, tagIDKeyName } = {}, type, tags) {
|
||||
return {
|
||||
text({ body = false } = {}) {
|
||||
text ({ body = false } = {}) {
|
||||
// build a string containing all tags of this type
|
||||
return tags.reduce((tagsStr, tag) => {
|
||||
const tagKeys = Object.keys(tag)
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
* @param {String} data - the title text
|
||||
* @return {Object} - the title generator
|
||||
*/
|
||||
export default function titleGenerator(appId, { attribute } = {}, type, data) {
|
||||
export default function titleGenerator (appId, { attribute } = {}, type, data) {
|
||||
return {
|
||||
text() {
|
||||
text () {
|
||||
return `<${type}>${data}</${type}>`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { metaInfoOptionKeys } from '../shared/constants'
|
||||
import { serverSequences } from '../shared/escaping'
|
||||
import generateServerInjector from './generateServerInjector'
|
||||
|
||||
export default function _inject(options = {}) {
|
||||
export default function _inject (options = {}) {
|
||||
/**
|
||||
* Converts the state of the meta info object such that each item
|
||||
* can be compiled to a tag string on the server
|
||||
@@ -11,7 +11,7 @@ export default function _inject(options = {}) {
|
||||
* @this {Object} - Vue instance - ideally the root component
|
||||
* @return {Object} - server meta info with `toString` methods
|
||||
*/
|
||||
return function inject() {
|
||||
return function inject () {
|
||||
// get meta info with sensible defaults
|
||||
const metaInfo = getMetaInfo(options, this.$root, serverSequences)
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ export const serverSequences = [
|
||||
|
||||
export const clientSequences = [
|
||||
[/&/g, '\u0026'],
|
||||
[/</g, '\u003c'],
|
||||
[/>/g, '\u003e'],
|
||||
[/</g, '\u003C'],
|
||||
[/>/g, '\u003E'],
|
||||
[/"/g, '\u0022'],
|
||||
[/'/g, '\u0027']
|
||||
]
|
||||
|
||||
// sanitizes potentially dangerous characters
|
||||
export function escape(info, options, escapeOptions) {
|
||||
export function escape (info, options, escapeOptions) {
|
||||
const { tagIDKeyName } = options
|
||||
const { doEscape = v => v } = escapeOptions
|
||||
const escaped = {}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { inMetaInfoBranch } from './meta-helpers'
|
||||
* @param {Object} [result={}] - result so far
|
||||
* @return {Object} result - final aggregated result
|
||||
*/
|
||||
export default function getComponentOption(options = {}, component, result = {}) {
|
||||
export default function getComponentOption (options = {}, component, result = {}) {
|
||||
const { keyName, metaTemplateKeyName, tagIDKeyName } = options
|
||||
const { $options, $children } = component
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import getComponentOption from './getComponentOption'
|
||||
* @param {Object} component - the Vue instance to get meta info from
|
||||
* @return {Object} - returned meta info
|
||||
*/
|
||||
export default function getMetaInfo(options = {}, component, escapeSequences = []) {
|
||||
export default function getMetaInfo (options = {}, component, escapeSequences = []) {
|
||||
// collect & aggregate all metaInfo $options
|
||||
let info = getComponentOption(options, component, defaultInfo)
|
||||
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { findIndex } from '../utils/array'
|
||||
import { applyTemplate } from './template'
|
||||
import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants'
|
||||
|
||||
export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
|
||||
export function arrayMerge ({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
|
||||
// we concat the arrays without merging objects contained in,
|
||||
// but we check for a `vmid` property on each object in the array
|
||||
// using an O(1) lookup associative array exploit
|
||||
@@ -65,7 +65,7 @@ export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, conte
|
||||
return destination.concat(source)
|
||||
}
|
||||
|
||||
export function merge(target, source, options = {}) {
|
||||
export function merge (target, source, options = {}) {
|
||||
// remove properties explicitly set to false so child components can
|
||||
// optionally _not_ overwrite the parents content
|
||||
// (for array properties this is checked in arrayMerge)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { isUndefined, isObject } from '../utils/is-type'
|
||||
|
||||
// Vue $root instance has a _vueMeta object property, otherwise its a boolean true
|
||||
export function hasMetaInfo(vm = this) {
|
||||
export function hasMetaInfo (vm = this) {
|
||||
return vm && (vm._vueMeta === true || isObject(vm._vueMeta))
|
||||
}
|
||||
|
||||
// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
|
||||
export function inMetaInfoBranch(vm = this) {
|
||||
export function inMetaInfoBranch (vm = this) {
|
||||
return vm && !isUndefined(vm._vueMeta)
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,16 +6,16 @@ import { addNavGuards } from './nav-guards'
|
||||
|
||||
let appId = 1
|
||||
|
||||
export default function createMixin(Vue, options) {
|
||||
export default function createMixin (Vue, options) {
|
||||
// for which Vue lifecycle hooks should the metaInfo be refreshed
|
||||
const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']
|
||||
|
||||
// watch for client side component updates
|
||||
return {
|
||||
beforeCreate() {
|
||||
beforeCreate () {
|
||||
Object.defineProperty(this, '_hasMetaInfo', {
|
||||
configurable: true,
|
||||
get() {
|
||||
get () {
|
||||
// Show deprecation warning once when devtools enabled
|
||||
if (Vue.config.devtools && !this.$root._vueMeta.hasMetaInfoDeprecationWarningShown) {
|
||||
console.warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead') // eslint-disable-line no-console
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isFunction } from '../utils/is-type'
|
||||
|
||||
export function addNavGuards(vm) {
|
||||
export function addNavGuards (vm) {
|
||||
// return when nav guards already added or no router exists
|
||||
if (vm.$root._vueMeta.navGuards || !vm.$root.$router) {
|
||||
/* istanbul ignore next */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { isObject } from '../utils/is-type'
|
||||
import { defaultOptions } from './constants'
|
||||
|
||||
export function setOptions(options) {
|
||||
export function setOptions (options) {
|
||||
// combine options
|
||||
options = isObject(options) ? options : {}
|
||||
|
||||
@@ -14,7 +14,7 @@ export function setOptions(options) {
|
||||
return options
|
||||
}
|
||||
|
||||
export function getOptions(options) {
|
||||
export function getOptions (options) {
|
||||
const optionsCopy = {}
|
||||
for (const key in options) {
|
||||
optionsCopy[key] = options[key]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export function pause(refresh = true) {
|
||||
export function pause (refresh = true) {
|
||||
this.$root._vueMeta.paused = true
|
||||
|
||||
return () => resume(refresh)
|
||||
}
|
||||
|
||||
export function resume(refresh = true) {
|
||||
export function resume (refresh = true) {
|
||||
this.$root._vueMeta.paused = false
|
||||
|
||||
if (refresh) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isUndefined, isFunction } from '../utils/is-type'
|
||||
|
||||
export function applyTemplate({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
|
||||
export function applyTemplate ({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
|
||||
if (isUndefined(template)) {
|
||||
template = headObject[metaTemplateKeyName]
|
||||
delete headObject[metaTemplateKeyName]
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
// which means the polyfills are removed for other build formats
|
||||
const polyfill = process.env.NODE_ENV === 'test'
|
||||
|
||||
export function findIndex(array, predicate) {
|
||||
export function findIndex (array, predicate) {
|
||||
if (polyfill && !Array.prototype.findIndex) {
|
||||
// idx needs to be a Number, for..in returns string
|
||||
for (let idx = 0; idx < array.length; idx++) {
|
||||
@@ -24,14 +24,14 @@ export function findIndex(array, predicate) {
|
||||
return array.findIndex(predicate, arguments[2])
|
||||
}
|
||||
|
||||
export function toArray(arg) {
|
||||
export function toArray (arg) {
|
||||
if (polyfill && !Array.from) {
|
||||
return Array.prototype.slice.call(arg)
|
||||
}
|
||||
return Array.from(arg)
|
||||
}
|
||||
|
||||
export function includes(array, value) {
|
||||
export function includes (array, value) {
|
||||
if (polyfill && !Array.prototype.includes) {
|
||||
for (const idx in array) {
|
||||
if (array[idx] === value) {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { isArray, isObject } from './is-type'
|
||||
|
||||
export function ensureIsArray(arg, key) {
|
||||
export function ensureIsArray (arg, key) {
|
||||
if (!key || !isObject(arg)) {
|
||||
return isArray(arg) ? arg : []
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export function ensureIsArray(arg, key) {
|
||||
return arg
|
||||
}
|
||||
|
||||
export function ensuredPush(object, key, el) {
|
||||
export function ensuredPush (object, key, el) {
|
||||
ensureIsArray(object, key)
|
||||
|
||||
object[key].push(el)
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
* @param {any} arg - the object to check
|
||||
* @return {Boolean} - true if `arg` is an array
|
||||
*/
|
||||
export function isArray(arg) {
|
||||
export function isArray (arg) {
|
||||
return Array.isArray(arg)
|
||||
}
|
||||
|
||||
export function isUndefined(arg) {
|
||||
export function isUndefined (arg) {
|
||||
return typeof arg === 'undefined'
|
||||
}
|
||||
|
||||
export function isObject(arg) {
|
||||
export function isObject (arg) {
|
||||
return typeof arg === 'object'
|
||||
}
|
||||
|
||||
export function isFunction(arg) {
|
||||
export function isFunction (arg) {
|
||||
return typeof arg === 'function'
|
||||
}
|
||||
|
||||
export function isString(arg) {
|
||||
export function isString (arg) {
|
||||
return typeof arg === 'string'
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { isUndefined } from './is-type'
|
||||
|
||||
export function hasGlobalWindowFn() {
|
||||
export function hasGlobalWindowFn () {
|
||||
try {
|
||||
return !isUndefined(window)
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user