googlearchive / observe-js

A library for observing Arrays, Objects and PathValues
1.35k stars 118 forks source link

feature request: Path.toParent() #97

Open capaj opened 9 years ago

capaj commented 9 years ago

I have a path like this for example:

'foo.arr[map]'
or
'foo.arr.map'

and I would really appreciate it, if I could easily get a new path which would lose the last property accessor. I could parse the strings, but it seems to me this would be useful feature for other people using Path objects.

so ideally:

var pathObj = Path.get('foo.arr[map]');
var parentPathObj = pathObj.toParent();
parentPathObj  //should be equivalent to Path.get('foo.arr');