Module: grappling-hook

Methods

(static) attach(base, presetsopt, optsopt) → {function}

Attaches GrapplingHook methods to base's prototype.

Parameters:
Name Type Attributes Description
base function
presets string <optional>

presets name, see set

opts options <optional>

options.

Mixes In:
Source:
See:
Returns:
Type
function
Example
var grappling = require('grappling-hook');
var MyClass = function() {
};
MyClass.prototype.save = function(done) {
  console.log('save!');
  done();
};
grappling.attach(MyClass); // attach grappling-hook functionality to a 'class'

(static) create(presetsopt, optsopt) → {GrapplingHook}

Creates an object with GrapplingHook functionality.

Parameters:
Name Type Attributes Description
presets string <optional>

presets name, see set

opts options <optional>

options.

Source:
See:
Returns:
Type
GrapplingHook
Example
var grappling = require('grappling-hook');
var instance = grappling.create(); // create an instance

(static) get(name) → {*}

Retrieves presets stored as name. Or a specific value of a preset. (The use of namespaces is to avoid the very unlikely case of name conflicts with deduped node_modules)

Parameters:
Name Type Description
name string
Since:
  • 3.0.0
Source:
See:
  • set for storing presets
Returns:
Type
*
Examples
grappling.get('grapplinghook:example.qualifiers.pre');
grappling.get('grapplinghook:example.qualifiers');
grappling.get('grapplinghook:example');

(static) isThenable(subject) → {Boolean}

Determines whether subject is a thenable.

Parameters:
Name Type Description
subject *
Source:
See:
Returns:
Type
Boolean

(static) mixin(instance, presetsopt, optsopt) → {GrapplingHook}

Mixes GrapplingHook methods into instance.

Parameters:
Name Type Attributes Description
instance Object
presets string <optional>

presets name, see set

opts options <optional>

options.

Mixes In:
Source:
See:
Returns:
Type
GrapplingHook
Example
var grappling = require('grappling-hook');
var instance = {
};
grappling.mixin(instance); // add grappling-hook functionality to an existing object

(static) set(name, options) → {module:grappling-hook}

Store presets as name. Or set a specific value of a preset. (The use of namespaces is to avoid the very unlikely case of name conflicts with deduped node_modules)

Parameters:
Name Type Description
name string
options options
Since:
  • 3.0.0
Source:
See:
  • get for retrieving presets
Returns:
Type
module:grappling-hook
Examples
//index.js - declaration
var grappling = require('grappling-hook');
grappling.set('grapplinghook:example', {
  strict: false,
  qualifiers: {
    pre: 'before',
    post: 'after'
  }
});

//foo.js - usage
var instance = grappling.create('grapplinghook:example'); // uses options as cached for 'grapplinghook:example'
grappling.set('grapplinghook:example.qualifiers.pre', 'first');
grappling.set('grapplinghook:example.qualifiers.post', 'last');