2015-10-08 20:16:45 +03:00
|
|
|
'use strict';
|
|
|
|
import JsonPointerLib from 'json-pointer';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper for JsonPointer. Provides common operations
|
|
|
|
*/
|
|
|
|
export class JsonPointer extends JsonPointerLib {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns last JsonPointer token
|
2015-10-09 08:31:09 +03:00
|
|
|
* if level > 1 returns levels last (second last/third last)
|
2015-10-08 20:16:45 +03:00
|
|
|
* @example
|
|
|
|
* // returns subpath
|
2015-10-09 08:31:09 +03:00
|
|
|
* JsonPointerHelper.baseName('/path/0/subpath')
|
|
|
|
* // returns foo
|
|
|
|
* JsonPointerHelper.baseName('/path/foo/subpath', 2)
|
2015-10-08 20:16:45 +03:00
|
|
|
*/
|
2015-10-09 08:31:09 +03:00
|
|
|
static baseName(pointer, level=1) {
|
2015-10-08 23:21:51 +03:00
|
|
|
var tokens = JsonPointer.parse(pointer);
|
|
|
|
return tokens[tokens.length - (level)];
|
2015-10-08 20:16:45 +03:00
|
|
|
}
|
|
|
|
}
|
2015-10-08 23:21:51 +03:00
|
|
|
|
|
|
|
export default JsonPointer;
|