lib/patch-builder.js
function insert() {
  var context     = null;
  var position    = null;
  var content     = void 0;
  var cardinality = null;

  var argLen = arguments.length;
  for (var i=0; i < argLen; i++) {
    var arg = arguments[i];
    if (i === 0) {
      context = arg;
      continue;
    }
    if (arg === null && content === void 0) {
      content = arg;
      continue;
    }
    var isString = (typeof arg === 'string' || arg instanceof String);
    if (isString) {
      if (position === null && /^(before|after|last-child)$/.test(arg)) {
        position = arg;
        continue;
      }
      if (cardinality === null && /^[?.*+]$/.test(arg)) {
        cardinality = arg;
        continue;
      }
    }
    if (content === void 0) {
      content = arg;
      continue;
    }
    break;
  }

  if (context === null || position === null || content === void 0) {
    throw new Error(
        'insert takes context, position, content, and optional cardinality'
        );
  }

  var operation = {
    context:  context,
    position: position,
    content:  content
  };
  if (cardinality !== null) {
    operation.cardinality = cardinality;
  }

  return {insert: operation};
}
function insert() {
  var context     = null;
  var position    = null;
  var content     = void 0;
  var cardinality = null;

  var argLen = arguments.length;
  for (var i=0; i < argLen; i++) {
    var arg = arguments[i];
    if (i === 0) {
      context = arg;
      continue;
    }
    if (arg === null && content === void 0) {
      content = arg;
      continue;
    }
    var isString = (typeof arg === 'string' || arg instanceof String);
    if (isString) {
      if (position === null && /^(before|after|last-child)$/.test(arg)) {
        position = arg;
        continue;
      }
      if (cardinality === null && /^[?.*+]$/.test(arg)) {
        cardinality = arg;
        continue;
      }
    }
    if (content === void 0) {
      content = arg;
      continue;
    }
    break;
  }

  if (context === null || position === null || content === void 0) {
    throw new Error(
        'insert takes context, position, content, and optional cardinality'
        );
  }

  var operation = {
    context:  context,
    position: position,
    content:  content
  };
  if (cardinality !== null) {
    operation.cardinality = cardinality;
  }

  return {insert: operation};
}
function insert ( ) { var context = null ; var position = null ; var content = void 0 ; var cardinality = null ; var argLen = arguments . length ; for ( var i = 0 ; i < argLen ; i ++ ) { var arg = arguments [ i ] ; if ( i === 0 ) { context = arg ; continue ; } if ( arg === null && content === void 0 ) { content = arg ; continue ; } var isString = ( typeof arg === 'string' || arg instanceof String ) ; if ( isString ) { if ( position === null && / ^(before|after|last-child)$ / . test ( arg ) ) { position = arg ; continue ; } if ( cardinality === null && / ^[?.*+]$ / . test ( arg ) ) { cardinality = arg ; continue ; } } if ( content === void 0 ) { content = arg ; continue ; } break ; } if ( context === null || position === null || content === void 0 ) { throw new Error ( 'insert takes context, position, content, and optional cardinality' ) ; } var operation = { context : context , position : position , content : content } ; if ( cardinality !== null ) { operation . cardinality = cardinality ; } return { insert : operation } ; }
Builds an operation to insert content.
@method
@since 1.0
@memberof patchBuilder#
@param {string}  context - the path to the container of the inserted content
@param {string}  position - a specification from the before|after|last-child
enumeration controlling where the content will be inserted relative to the context
@param           content - the inserted object or value
@param {string}  [cardinality] - a specification from the ?|.|*|+
enumeration controlling whether the context path must match zero-or-one
fragment, exactly one fragment, any number of fragments (the default), or
one-or-more fragments.
@returns {patchBuilder.PatchOperation} a patch operation
Builds an operation to insert content .