Sha256: 9e4be9db1e19c7182fbe78cdc124e878afd97f275a207e567a14f67dd899ec0b
Contents?: true
Size: 1.81 KB
Versions: 19
Compression:
Stored size: 1.81 KB
Contents
/** internal * class Hash * * Thin wraper over Object used internally to keep lists of processors. **/ 'use strict'; // 3rd-party var _ = require('lodash'); //////////////////////////////////////////////////////////////////////////////// /** * new Hash(defaulter) * - defaulter (Function): default value generator **/ function Hash(defaulter) { this.data = {}; this.defaulter = defaulter; } /** * Hash#get(key) -> Mixed * - key (String): * * Returns value associated with given key: * * processors.get('text/css').push(DirectiveProcessor); * * Associates key with value generated by `defaulter` if it does not exists * yet. **/ Hash.prototype.get = function (key) { if (!this.data[key]) { this.data[key] = this.defaulter(key); } return this.data[key]; }; /** * Hash#set(key, val) -> Void * - key (String): * - val (Mixed): * * Set value for a key: * * old_val = processors.get('text/css'); * new_val = _.without(old_val, MyMegaProcessor); * processors.set('text/css', new_val); * * Used to reset value of a key. **/ Hash.prototype.set = function (key, val) { this.data[key] = val || this.defaulter(key); }; /** * Hash#clone() -> Hash * * Makes a copy of a Hash. * * processors.get('text/css').length; // => 1 * * processors_copy = processors.clone(); * processors_copy.get('text/css').push(MyMegaProcessor); * * processors.get('text/css').length; // => 1 * processors_copy.get('text/css').length; // => 2 * * Used upon Environment init - clone globally registered processors **/ Hash.prototype.clone = function () { var clone = new Hash(this.defaulter); Object.keys(this.data).forEach(function (key) { clone.set(key, _.clone(this.data[key])); }, this); return clone; }; module.exports = Hash;
Version data entries
19 entries across 19 versions & 1 rubygems