get-view: Assemble View Utility
get-view is a utility designed to retrieve 'view' objects from collection structures, primarily within the `assemble` and `templates` ecosystems. It works with collections of Vinyl files, offering flexible lookup mechanisms including by path, basename, filename, relative path, or a custom function. The package is currently stable at version 2.0.0, but it appears to be abandoned, with no updates or activity detected for approximately 8 years (as of April 2026). It was designed for Node.js environments `>=6` and is tightly coupled with the older `assemble` and `templates` frameworks, which are also no longer actively maintained. As such, while functional, users should consider its long-term viability and potential lack of modern feature support or security updates.
Common errors
-
TypeError: getView is not a function
cause Attempting to use ES module named import (`import { getView } from 'get-view';`) for a CommonJS-only package, or incorrect destructuring of the `require` call.fixFor CommonJS, use `const getView = require('get-view');`. For ESM interop, use `import getView from 'get-view';`. -
TypeError: The "collection" argument must be an object, or null
cause Incorrect argument order for `getView` function, passing the lookup key as the first argument instead of the collection object, which was a breaking change in v2.0.fixEnsure the first argument is the collection object (e.g., `app.views.pages`) and the second is the lookup key or function: `getView(collection, lookupValue)`. -
No view found for [...]
cause The provided lookup key or custom function did not match any view in the collection. This could be due to an incorrect key, or expecting glob matching which is no longer default in v2.0.fixVerify the lookup key (path, basename, filename, relative) exactly matches a view's property. If using a custom function, ensure its logic correctly identifies the target view. If globbing, implement and pass a glob-matching function explicitly.
Warnings
- breaking In `v2.0`, the order of arguments for the `getView` function was reversed. The collection of views is now passed as the first argument, and the lookup value (key or function) as the second.
- breaking As of `v2.0`, `get-view` no longer matches views using glob patterns by default. If glob matching is required, a dedicated glob matcher function must be passed as the second argument.
- gotcha The `get-view` package, along with its related projects like `assemble` and `templates`, appears to be abandoned. It has not received updates for approximately 8 years. This means there will be no new features, compatibility updates for newer Node.js versions or ecosystems, or security patches.
Install
-
npm install get-view -
yarn add get-view -
pnpm add get-view
Imports
- getView
const getView = require('get-view'); - getView
import { getView } from 'get-view';import getView from 'get-view';
- module object
const { getView } = require('get-view');const moduleExport = require('get-view'); // moduleExport is the function itself
Quickstart
const templates = require('templates');
const getView = require('get-view');
// Initialize templates instance
const app = templates();
app.create('page');
// Add some pages to the collection
app.page('foo', { content: 'this is foo' });
app.page('bar.md', { content: 'this is bar' });
app.page('a/b/c/baz.md', { content: 'this is baz', base: 'a' });
app.page('test/fixtures/templates/a.tmpl');
// Get a view by filename 'baz'
const viewByFilename = getView(app.views.pages, 'baz');
console.log('View by filename:', viewByFilename ? viewByFilename.basename : 'Not found');
// Get a view by relative path 'b/c/baz.md'
const viewByRelative = getView(app.views.pages, 'b/c/baz.md');
console.log('View by relative path:', viewByRelative ? viewByRelative.basename : 'Not found');
// Get a view using a custom lookup function
const viewByFunction = getView(app.views.pages, function(view) {
return view.stem === 'foo';
});
console.log('View by custom function:', viewByFunction ? viewByFunction.basename : 'Not found');