Comparing version 1.1.1 to 1.2.0
@@ -154,2 +154,4 @@ /** | ||
children = [], | ||
prefixType = null, | ||
prefix = '', | ||
create = function(key) { | ||
@@ -189,2 +191,8 @@ var hash = new Hash(self.childKey(key), self.root); | ||
if (def.__validate__ && typeof def.__validate__ === 'function') validateFn = true; | ||
prefixType = typeof def.__prefix__; | ||
if (prefixType === 'string' && def.__prefix__) { | ||
prefix = def.__prefix__; | ||
} else if (prefixType === 'number') { | ||
prefix = def.__prefix__.toString(); | ||
} | ||
this[name] = function(value) { | ||
@@ -208,3 +216,3 @@ var isValid = false, | ||
if (isValid !== true) throw new Error('Invalid key'); | ||
return create(value); | ||
return create(prefix + value); | ||
}; | ||
@@ -211,0 +219,0 @@ } |
{ | ||
"name": "cachetree", | ||
"description": "A scoped, fluent API for easily interacting with hierarchical, key-value data", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"author": "David Wood <bitprobe@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -178,2 +178,20 @@ /*global describe: true, it:true, beforeEach: true, afterEach: true, before: true, after: true */ | ||
it('should accept an object with a key prefix as a string', function() { | ||
var cache = cachetree(), | ||
hash, | ||
err; | ||
cache.add('alpha', { __prefix__: 'bravo-' }); | ||
hash = cache.alpha('charlie'); | ||
isHash(hash, ['cache', 'bravo-charlie']); | ||
}); | ||
it('should accept an object with a key prefix as a number', function() { | ||
var cache = cachetree(), | ||
hash, | ||
err; | ||
cache.add('alpha', { __prefix__: 123 }); | ||
hash = cache.alpha('charlie'); | ||
assert.deepEqual(hash.key, ['cache', '123charlie']); | ||
}); | ||
it('should create a child hash that can be extended', function() { | ||
@@ -180,0 +198,0 @@ var cache = cachetree(), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44702
1275