Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ var assert = require('assert');
var dict = require('./dict');
var Parser = require('./parser');
var Handlers = require('./handlers');
var _ = require('underscore');

var JSONPath = function() {
this.initialize.apply(this, arguments);
};

JSONPath.prototype.initialize = function() {
this.parser = new Parser();
this.parser.parse = _.memoize(this.parser.parse);
this.handlers = new Handlers();
};

Expand Down Expand Up @@ -152,7 +154,7 @@ JSONPath.prototype.nodes = function(obj, string, count) {
return count ? matches.slice(0, count) : matches;
};

JSONPath.prototype.stringify = function(path) {
JSONPath.prototype.stringify = _.memoize(function(path) {

assert.ok(path, "we need a path");

Expand Down Expand Up @@ -187,9 +189,9 @@ JSONPath.prototype.stringify = function(path) {
});

return string;
}
});

JSONPath.prototype._normalize = function(path) {
JSONPath.prototype._normalize = _.memoize(function(path) {

assert.ok(path, "we need a path");

Expand Down Expand Up @@ -234,7 +236,7 @@ JSONPath.prototype._normalize = function(path) {
}

throw new Error("couldn't understand path " + path);
}
});

function _is_string(obj) {
return Object.prototype.toString.call(obj) == '[object String]';
Expand Down