How to use the json8-pointer.validArrayToken function in json8-pointer

To help you get started, we’ve selected a few json8-pointer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sonnyp / JSON8 / packages / patch / lib / walk.js View on Github external
module.exports = function walk(doc, tokens) {
  const length = tokens.length;

  let i = 0;
  let target = doc;
  let token;

  while (i < length - 1) {
    token = tokens[i++];

    if (Array.isArray(target)) validArrayToken(token, target.length);
    else if (typeof target !== OBJECT || target === null)
      throw new Error("Cannot be walked");

    target = target[token];
  }

  token = tokens[i];

  if (Array.isArray(target)) validArrayToken(token, target.length);
  else if (typeof target !== OBJECT || target === null)
    throw new Error("Invalid target");

  return [token, target];
};

json8-pointer

JSON Pointer toolkit for JavaScript

ISC
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis