# is-valid-instance

> Returns true if a value is a valid instance of Base.

Latest version **0.3.0** (published 2017-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-valid-instance
pnpm add is-valid-instance
yarn add is-valid-instance
bun add is-valid-instance
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2017-03-24 |
| First published | 2016-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | app, base, instance, is, valid |

## Links

- npm: https://www.npmjs.com/package/is-valid-instance
- Repository: https://github.com/jonschlinkert/is-valid-instance
- Issues: https://github.com/jonschlinkert/is-valid-instance/issues
- npm.io page: https://npm.io/package/is-valid-instance

## Dependencies (2)

- [isobject](https://npm.io/package/isobject.md) ^3.0.0
- [pascalcase](https://npm.io/package/pascalcase.md) ^0.1.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2017-03-24
- 0.2.0 — 2016-06-27
- 0.1.0 — 2016-05-15

## README

# is-valid-instance [![NPM version](https://img.shields.io/npm/v/is-valid-instance.svg?style=flat)](https://www.npmjs.com/package/is-valid-instance) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-valid-instance.svg?style=flat)](https://npmjs.org/package/is-valid-instance)  [![NPM total downloads](https://img.shields.io/npm/dt/is-valid-instance.svg?style=flat)](https://npmjs.org/package/is-valid-instance) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-valid-instance.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-valid-instance)

> Returns true if a value is a valid instance of Base.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save is-valid-instance
```

## Usage

Use in your [base](https://github.com/node-base/base) plugin to ensure that the plugin is registered on a valid instance.

```js
var isValidInstance = require('is-valid-instance');

function plugin(app) {
  if (!isValidInstance(app)) return;
  // do plugin stauff
}
```

## API

**Params**

* `val` **{Object}**
* `names` **{Array|Function}**: One or more names to check for on the given instance. Example `app` will check for `app.isApp === true` or `app._name === 'app'`.
* `fn` **{Function}**: Custom function for validating the instance.
* `returns` **{Boolean}**

**Example**

```js
function plugin(app) {
  if (!isValidInstance(app)) return;
  // do plugin stuff
}
```

## Examples

**Collection instance**

Return true if the instance is a [templates](https://github.com/jonschlinkert/templates) view-collection (`views`):

```js
function plugin(collection) {
  if (!isValidInstance(collection, ['views'])) {
    // optionally return the plugin function so the plugin is re-tried on 
    // each instance until it finds the correct one
    return plugin;
  }
  // do plugin stauff
}
```

**View instance**

Return true if the instance is a [templates](https://github.com/jonschlinkert/templates) view:

```js
function plugin(view) {
  if (!isValidInstance(view, ['view'])) {
    return plugin;
  }
  // do plugin stauff
}
```

**View instance**

Return true if the instance is either "app" or "collection":

```js
function plugin(app) {
  if (!isValidInstance(app, ['app', 'collection'])) {
    return plugin;
  }
  // do plugin stauff
}
```

## About

### Related projects

* [base-app](https://www.npmjs.com/package/base-app): Starting point for creating a base application, with a few light plugins for running tasks… [more](https://github.com/node-base/base-app) | [homepage](https://github.com/node-base/base-app "Starting point for creating a base application, with a few light plugins for running tasks and writing to the file system, and a functional CLI.")
* [base-plugins](https://www.npmjs.com/package/base-plugins): Upgrade's plugin support in base applications to allow plugins to be called any time after… [more](https://github.com/node-base/base-plugins) | [homepage](https://github.com/node-base/base-plugins "Upgrade's plugin support in base applications to allow plugins to be called any time after init.")
* [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.3, on March 24, 2017._

---
_Source: https://npm.io/package/is-valid-instance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
