Socket
Book a DemoInstallSign in
Socket

context-manager

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

context-manager

Manage context for templates.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
2
Created
Source

context-manager NPM version

Manage context for templates.

Install with npm

npm i context-manager --save

Usage

var context = require('context-manager');

API

Context

Create an instance of Context.

.setContext

Add a context level, optionally passing a value to start with.

  • name {String}: The name of the context to add.
  • level {Number}: Numerical value representing the order in which this level should be merged versus other lvl.
  • value {Object}: Optionally pass an object to start with.
context.setContext('locals', {a: 'b'});

.getContext

Get the raw (un-merged) context for name.

  • name {String}: The context to get.
  • returns: {*}
context.setContext('a', {a: 'b'});
context.getContext('a');
// => {a: 'b'}

.extendContext

Extend context name with the given value

  • name {String}
  • key {String}
  • value {Object}
  • returns: {String}
context.setContext('locals', {a: 'b'});

.setLevel

Set the level for a context. This determines the order in which the context will be merged when .calculate() is called.

  • name {String}: The name of the context.
  • level {Number}: The level (number) to set for the level.
if (foo) {
  context.setLevel('locals', 10);
} else {
  context.setLevel('locals', 0);
}

.calculate

Calculate the context, optionally passing a callback fn for sorting. (Note that sorting must be done on levels, not on the context names).

  • keys {String|Array}: Key, or array of keys for context levels to include.
  • fn {Function}: Sort function for determining the order of merging.
app.calculate(['a', 'b'], function(a, b) {
  return app.lvl[a] - app.lvl[a];
});

.resetContexts

Clear all contexts.

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the license

This file was generated by verb on February 21, 2015.

Keywords

context

FAQs

Package last updated on 22 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts