is-vue-component

Check if the given value is a valid Vue component.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
is-vue-component
1.0.04 years ago4 years agoMinified + gzip package size for is-vue-component in KB

Readme

is-vue-component
Build Status Downloads Version
Check if the given value is a valid Vue component.

What is a valid Vue component?
  1. It is a plain object.
  2. It has at least one of the following properties:
- `el`: a non-empty string or an `Element`.
- `template`: a non-empty string.
- `render`: a function.
- `extends`: a valid Vue component.
- `mixins`: an array includes at least a valid Vue component.

Main

dist/
├── is-vue-component.js        (UMD)
├── is-vue-component.min.js    (UMD, compressed)
├── is-vue-component.common.js (CommonJS, default)
└── is-vue-component.esm.js    (ES Module)

Install

npm install is-vue-component

Usage

<div id="app"></div>

import isVueComponent from 'is-vue-component';

isVueComponent({
  el: '#app',
});
// > true

isVueComponent({
  el: document.getElementById('app'),
});
// > true

isVueComponent({
  template: '<p>Hello, World!</p>',
});
// > true

isVueComponent({
  render(createElement) {
    return createElement('p', 'Hello, World!');
  },
});
// > true

isVueComponent({
  extends: {
    render(createElement) {
      return createElement('p', 'Hello, World!');
    },
  },
});
// > true

isVueComponent({
  mixins: [
    {
      render(createElement) {
        return createElement('p', 'Hello, World!');
      },
    },
  ],
});
// > true

isVueComponent({});
// > false

License

MIT © Chen Fengyuan