A strict Hash implementation allowing key restriction and virtualization
npm:
npm install strictly-hash
bower
bower install strictly-hash
coffeescript example:
inst = new Hash (
param_one:"foo"
param_two:"bar"
), ['param_one', 'param_two']
inst.set 'param_three', 'baz'
# param_three isn't allowed - prints 'undefined'
console.log inst.get 'param_three'
# prints 'foobar'
console.log "#{inst.get 'param_one'}#{inst.get 'param_two'}"
javascript example:
var inst = new Hash({
param_one:'foo',
param_two:'bar'
}, ['param_one', 'param_two']);
inst.set( 'param_three', 'baz' );
// param_three isn\'t allowed - prints \"undefined\"
console.log( inst.get( 'param_three' ) );
// prints \"foobar\"
console.log( ""+inst.get( 'param_one')+inst.get( 'param_two' ) );
coffeescript example:
class Instance extends Hash
constructor:->
Instance.__super__.constructor.call @, (
param_one:"foo"
param_two:"bar"
), ['param_one', 'param_two']
inst = new Instance
inst.set 'param_three', 'baz'
# param_three isn't allowed - prints 'undefined'
console.log inst.get 'param_three'
# prints 'foobar'
console.log "#{inst.get 'param_one'}#{inst.get 'param_two'}"
javascript example:
(function() {
var Instance, Hash,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Instance = (function(_super) {
__extends(Instance, _super);
function Instance() {
return Instance.__super__.constructor.apply(this, {
param_one:"foo",
param_two:"bar"
}, ['param_one', 'param_two']);
}
})(Hash);
}).call(this);
Creates new hash instance
Object object: (optional) Sets initial contents of Hash
Array restricted_keys: (optional) If present, restricts the hash keys to the provided values
gets key/value from virtualized object
sets key/value to virtualized object
tests for key existance
removes key from hash
traverses hash, calling iterator on each node
returns object keys
returns object
returns object
returns returns string representation of hash, if pretty is true
will format the string for readability
returns true if environment supports Object.freeze
freezes Hash object if feature supported by environment
returns true if Hash is frozen
returns true if environment supports Object.seal
seals Hash object if feature supported by environment
returns true if Hash is sealed
returns true if environment supports Object.canPreventExtensions
returns false if Hash is not Extensible
prevent Extensability for Hash object if feature supported by environment