@hyperjump/json-pointer
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -6,10 +6,24 @@ "use strict"; | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var nil = exports.nil = ""; | ||
var get = exports.get = function get(pointer) { | ||
if (pointer.length > 0 && pointer[0] !== "/") { | ||
throw Error("Invalid JSON Pointer"); | ||
} | ||
var ptr = pointer.split("/").slice(1).map(unescape); | ||
return function (value) { | ||
return ptr.reduce(function (acc, segment) { | ||
return acc[segment]; | ||
}, value); | ||
return ptr.reduce(function (_ref, segment) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
value = _ref2[0], | ||
pointer = _ref2[1]; | ||
return [applySegment(value, segment, pointer), append(pointer, segment)]; | ||
}, [value, ""])[0]; | ||
}; | ||
@@ -27,2 +41,14 @@ }; | ||
return segment.toString().replace("~0", "~").replace("~1", "/"); | ||
}; | ||
var applySegment = function applySegment(value, segment) { | ||
var pointer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ""; | ||
if (value === null || (typeof value === "undefined" ? "undefined" : _typeof(value)) !== "object") { | ||
throw Error("Value at '" + pointer + "' is a scalar and can't be indexed"); | ||
} else if (!(segment in value)) { | ||
throw Error("Value at '" + pointer + "' does not have index '" + segment + "'"); | ||
} | ||
return value[segment]; | ||
}; |
{ | ||
"name": "@hyperjump/json-pointer", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "An RFC-6901 JSON Pointer implementation", | ||
@@ -5,0 +5,0 @@ "main": "./dist/json-pointer.js", |
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
5713
40