src/attributes.js
function attachAttributeGetter(Class, method, type, EdgeDataClass) {

  /**
   * Get the desired attribute for the given element (node or edge).
   *
   * Arity 2:
   * @param  {any}    element - Target element.
   * @param  {string} name    - Attribute's name.
   *
   * Arity 3 (only for edges):
   * @param  {any}     source - Source element.
   * @param  {any}     target - Target element.
   * @param  {string}  name   - Attribute's name.
   *
   * @return {mixed}          - The attribute's value.
   *
   * @throws {Error} - Will throw if too many arguments are provided.
   * @throws {Error} - Will throw if any of the elements is not found.
   */
  Class.prototype[method] = function(element, name) {
    let data;

    if (this.type !== 'mixed' && type !== 'mixed' && type !== this.type)
      throw new UsageGraphError(`Graph.${method}: cannot find this type of edges in your ${this.type} graph.`);

    if (arguments.length > 2) {

      if (this.multi)
        throw new UsageGraphError(`Graph.${method}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);

      const source = '' + element,
            target = '' + name;

      name = arguments[2];

      data = getMatchingEdge(this, source, target, type);

      if (!data)
        throw new NotFoundGraphError(`Graph.${method}: could not find an edge for the given path ("${source}" - "${target}").`);
    }
    else {
      element = '' + element;
      data = this._edges.get(element);

      if (!data)
        throw new NotFoundGraphError(`Graph.${method}: could not find the "${element}" edge in the graph.`);
    }

    if (type !== 'mixed' && !(data instanceof EdgeDataClass))
      throw new NotFoundGraphError(`Graph.${method}: could not find the "${element}" ${type} edge in the graph.`);

    return data.attributes[name];
  };
}
function attachAttributeGetter(Class, method, type, EdgeDataClass) {

  /**
   * Get the desired attribute for the given element (node or edge).
   *
   * Arity 2:
   * @param  {any}    element - Target element.
   * @param  {string} name    - Attribute's name.
   *
   * Arity 3 (only for edges):
   * @param  {any}     source - Source element.
   * @param  {any}     target - Target element.
   * @param  {string}  name   - Attribute's name.
   *
   * @return {mixed}          - The attribute's value.
   *
   * @throws {Error} - Will throw if too many arguments are provided.
   * @throws {Error} - Will throw if any of the elements is not found.
   */
  Class.prototype[method] = function(element, name) {
    let data;

    if (this.type !== 'mixed' && type !== 'mixed' && type !== this.type)
      throw new UsageGraphError(`Graph.${method}: cannot find this type of edges in your ${this.type} graph.`);

    if (arguments.length > 2) {

      if (this.multi)
        throw new UsageGraphError(`Graph.${method}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);

      const source = '' + element,
            target = '' + name;

      name = arguments[2];

      data = getMatchingEdge(this, source, target, type);

      if (!data)
        throw new NotFoundGraphError(`Graph.${method}: could not find an edge for the given path ("${source}" - "${target}").`);
    }
    else {
      element = '' + element;
      data = this._edges.get(element);

      if (!data)
        throw new NotFoundGraphError(`Graph.${method}: could not find the "${element}" edge in the graph.`);
    }

    if (type !== 'mixed' && !(data instanceof EdgeDataClass))
      throw new NotFoundGraphError(`Graph.${method}: could not find the "${element}" ${type} edge in the graph.`);

    return data.attributes[name];
  };
}
function attachAttributeGetter ( Class , method , type , EdgeDataClass ) { /**
   * Get the desired attribute for the given element (node or edge).
   *
   * Arity 2:
   * @param  {any}    element - Target element.
   * @param  {string} name    - Attribute's name.
   *
   * Arity 3 (only for edges):
   * @param  {any}     source - Source element.
   * @param  {any}     target - Target element.
   * @param  {string}  name   - Attribute's name.
   *
   * @return {mixed}          - The attribute's value.
   *
   * @throws {Error} - Will throw if too many arguments are provided.
   * @throws {Error} - Will throw if any of the elements is not found.
   */ Class . prototype [ method ] = function ( element , name ) { let data ; if ( this . type !== 'mixed' && type !== 'mixed' && type !== this . type ) throw new UsageGraphError ( ` ${ method } ${ this . type } ` ) ; if ( arguments . length > 2 ) { if ( this . multi ) throw new UsageGraphError ( ` ${ method } ` ) ; const source = '' + element , target = '' + name ; name = arguments [ 2 ] ; data = getMatchingEdge ( this , source , target , type ) ; if ( ! data ) throw new NotFoundGraphError ( ` ${ method } ${ source } ${ target } ` ) ; } else { element = '' + element ; data = this . _edges . get ( element ) ; if ( ! data ) throw new NotFoundGraphError ( ` ${ method } ${ element } ` ) ; } if ( type !== 'mixed' && ! ( data instanceof EdgeDataClass ) ) throw new NotFoundGraphError ( ` ${ method } ${ element } ${ type } ` ) ; return data . attributes [ name ] ; } ; }
Attach an attribute getter method onto the provided class.

@param {function} Class         - Target class.
@param {string}   method        - Method name.
@param {string}   type          - Type of the edge to find.
@param {Class}    EdgeDataClass - Class of the edges to filter.
Attach an attribute getter method onto the provided class .