Skip to content

Commit 704d401

Browse files
committed
cache -> store: not saving results of #get but #set so is a store
1 parent a21a86c commit 704d401

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ exports = module.exports = Parth;
77

88
function Parth(){
99
if(!(this instanceof Parth)){ return new Parth(); }
10-
this.cache = {
10+
this.store = {
1111
_ : Object.create(null),
1212
regex: Object.create(null),
1313
masterRE: Object.create(null),
1414
};
15-
this.cache.masterRE._ = [];
15+
this.store.masterRE._ = [];
1616
}
1717

1818
// ## Parth.set(p[, o]) -> path, options
@@ -34,9 +34,9 @@ util.paramRE = /(^|\W)\:([^()?#\.\/ ]+)(\(.+?\))?/g;
3434
Parth.prototype.set = function(p, o){
3535
o = o || { }; if(!util.boil(p, o)){ return this; }
3636

37-
var cache = this.cache;
37+
var store = this.store;
3838
// already defined ? give it
39-
if(cache._[o.path]){ o = cache._[o.path]; return this; }
39+
if(store._[o.path]){ o = store._[o.path]; return this; }
4040

4141
o.custom = o.default = 0; // number of default and custom regex
4242
o.regex = '^' + o.path.replace(/\S+/g, function(stem){
@@ -50,10 +50,10 @@ Parth.prototype.set = function(p, o){
5050
.replace(/\^\]\+/g, ' ]+'); // default params
5151

5252
// update depths
53-
if(!cache.regex[o.depth]){
54-
cache.regex[o.depth] = [ ];
55-
cache.masterRE.depth = cache.masterRE._.push(o.depth)-1;
56-
cache.masterRE._ = cache.masterRE._.sort();
53+
if(!store.regex[o.depth]){
54+
store.regex[o.depth] = [ ];
55+
store.masterRE.depth = store.masterRE._.push(o.depth)-1;
56+
store.masterRE._ = store.masterRE._.sort();
5757
}
5858

5959
o.regex = new RegExp(o.regex, 'i');
@@ -62,14 +62,14 @@ Parth.prototype.set = function(p, o){
6262
o.regex.path = o.path;
6363
o.regex.argv = o.argv;
6464

65-
cache.regex[o.depth].push(o.regex);
66-
cache.regex[o.depth] = cache.regex[o.depth].sort(function(a, b){
65+
store.regex[o.depth].push(o.regex);
66+
store.regex[o.depth] = store.regex[o.depth].sort(function(a, b){
6767
return (b.def - b.cust) - (a.def - a.cust);
6868
});
6969

7070
// sum up all learned: void groups and make it one
71-
cache.masterRE[o.depth] =
72-
new RegExp(cache.regex[o.depth].map(function(re){
71+
store.masterRE[o.depth] =
72+
new RegExp(store.regex[o.depth].map(function(re){
7373
return '(' + re.source.replace(/\((?=[^?])/g, '(?:') + ')';
7474
}).join('|'), 'i');
7575

@@ -93,7 +93,7 @@ Parth.prototype.get = function(p, o){
9393
o = o || { }; o.notFound = true;
9494
if(!util.boil(p, o)){ return null; }
9595

96-
o.found = this.cache.masterRE;
96+
o.found = this.store.masterRE;
9797
o.index = o.depth = o.found.depth;
9898

9999
while(o.index > -1){
@@ -106,7 +106,7 @@ Parth.prototype.get = function(p, o){
106106
}
107107

108108
o.index = o.found.indexOf(o.found.join(''));
109-
o.regex = this.cache.regex[o.depth][o.index];
109+
o.regex = this.store.regex[o.depth][o.index];
110110

111111
o.index = 0;
112112
o.params = { _ : o.path.match(o.regex).slice(1) };
@@ -119,5 +119,5 @@ Parth.prototype.get = function(p, o){
119119

120120
o.notFound = !(/^[ ]/).test(o.notFound);
121121
delete o.found; delete o.index; delete o.depth;
122-
return o;
122+
return o.regex.argv;
123123
};

0 commit comments

Comments
 (0)