npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

base-compose

v0.2.1

Published

Selectively merge values from one or more generators onto the current application instance.

Downloads

89,572

Readme

base-compose NPM version NPM downloads Build Status

Selectively merge values from one or more generators onto the current application instance.

Install

Install with npm:

$ npm install --save base-compose

This plugin requires the base-generators to be registered first. If not already registered, you can do so now by following these instructions.

Usage

var compose = require('base-compose');
var Base = require('base');
var app = new Base();

// register the "compose" plugin
app.use(compose());

API

Heads up!

Some of the methods exposed on .compose expect for app to be an instance of templates, or for specific plugins to be registered first.

You don't need to register all of the plugins prescribed below, just use the plugins you need with the methods you need. base-compose will give you detailed error messages when something is missing.

More information is provided in the methods documentation below.

.compose

Setup a composition by passing in an array of generators to compose elements. If a generator cannot be found, an error will be thrown.

Params

  • parent {Object}: Parent generator to lookup generators.
  • names {String|Array}: One or more generator names or instances.
  • returns {Object}: Returns an instance of Compose

Example

app.compose(base, ['a', 'b', 'c'])
  .data()
  .options()
  .helpers()
  .views();

.compose.options

Merge the options from each generator into the app options. This method requires using the [base-option][base-option] plugin.

Params

  • key {String}: Optionally pass the name of a property to merge from the options object. Dot-notation may be used for nested properties.
  • returns {Object}: Returns the Compose instance for chaining

Example

a.option({foo: 'a'});
b.option({foo: 'b'});
c.option({foo: 'c'});

app.compose(base, ['a', 'b', 'c'])
  .options();

console.log(app.options);
//=> {foo: 'c'}

.compose.data

Merge the cache.data object from each generator onto the app.cache.data object. This method requires the .data() method from templates.

Params

  • key {String}: Optionally pass a key to merge from the data object.
  • returns {Object}: Returns the Compose instance for chaining

Example

a.data({foo: 'a'});
b.data({foo: 'b'});
c.data({foo: 'c'});

app.compose(base, ['a', 'b', 'c'])
  .data();

console.log(app.cache.data);
//=> {foo: 'c'}

.compose.engines

Merge the engines from each generator into the app engines. This method requires the .engine() methods from templates.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .engines();

.compose.helpers

Merge the helpers from each generator into app.helpers. Requires the .helper method from templates.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .helpers();

.compose.questions

Merge generator.questions.cache from specified generators onto app.questions.cache. Requires the base-questions plugin to be registered.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .questions();

.compose.pipeline

Merge the pipeline plugins from each generator onto app.plugins. Requires the base-pipeline plugin to be registered.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .pipeline();

.compose.tasks

Copy the specified tasks and task-dependencies from each generator onto app.tasks. Requires using the base-task plugin to be registered.

Params

  • tasks {String|Array}: One or more task names (optional)
  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .tasks(['foo', 'bar', 'default']);

// or to copy all tasks
app.compose(base, ['a', 'b', 'c'])
  .tasks();

.compose.views

Copy view collections and views from each generator onto app. Expects app to be an instance of templates.

Params

  • names {Array|String}: (optional) Names of one or more collections to copy. If undefined all collections will be copied.
  • filter {Function}: Optionally pass a filter function to filter views copied from each collection. The filter function exposes key, view and collection as arguments. If used, the function must return true to copy a view.
  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .views();

.compose.iterator

Returns an iterator function for iterating over an array of generators. The iterator takes a fn that exposes the current generator being iterated over (generator) and the app passed into the original function as arguments. No binding is done within the iterator so the function passed in can be safely bound.

Params

  • names {Array}: Names of generators to iterate over (optional).
  • iteratorFn {Function}: Function to invoke for each generator in generators. Exposes app and generator as arguments.
  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(base, ['a', 'b', 'c'])
  .iterator(function(generator, app) {
    // do work
    app.data(generator.cache.data);
  });

// optionally pass an array of additional generator names as the
// first argument. If generator names are defined on `iterator`,
// any names passed to `.compose()` will be ignored.
app.compose(base, ['a', 'b', 'c'])
  .iterator(['d', 'e', 'f'], function(generator, app) {
    // do stuff to `generator` and `app`
  });

base-generators

Follow these instructions to install and register the base-generators plugin before registering base-compose.

Install base-generators

$ npm install base-generators --save

Register base-generators

var generators = require('base-generators');
var compose = require('base-compose');
var Base = require('base');
var app = new Base();

// register plugins
app.use(generators());
app.use(compose());

Related projects

You might also be interested in these projects:

  • assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • generate: Fast, composable, highly pluggable project generator with a user-friendly and expressive API. | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

This document was generated by verb-readme-generator (a verb generator), please don't edit directly. Any changes to the readme must be made in .verb.md. See Building Docs.

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. Or visit the verb-readme-generator project to submit bug reports or pull requests for the readme layout template.

Building docs

Generate readme and API documentation with verb:

$ npm install -g verb verb-readme-generator && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.


This file was generated by verb, v0.9.0, on June 11, 2016.