lib/patch-builder.js
function replace() {
  var select      = null;
  var content     = void 0;
  var cardinality = null;
  var apply       = null;

  var argLen = arguments.length;
  for (var i=0; i < argLen; i++) {
    var arg = arguments[i];
    if (i === 0) {
      select = arg;
      continue;
    }
    if (arg === null && content === void 0) {
      content = arg;
      continue;
    }
    var isString = (typeof arg === 'string' || arg instanceof String);
    if (isString && cardinality === null && /^[?.*+]$/.test(arg)) {
      cardinality = arg;
      continue;
    }
    if (apply === null || apply === undefined) {
      apply = arg.apply;
      if (apply != null) {
        content = arg.content;
        continue;
      }
    }
    if (content === void 0) {
      content = arg;
      continue;
    }
    break;
  }

  if (select === null) {
    throw new Error(
        'replace takes a select path, content or an apply function, and optional cardinality'
        );
  }

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

  return {replace: operation};
}
function replace() {
  var select      = null;
  var content     = void 0;
  var cardinality = null;
  var apply       = null;

  var argLen = arguments.length;
  for (var i=0; i < argLen; i++) {
    var arg = arguments[i];
    if (i === 0) {
      select = arg;
      continue;
    }
    if (arg === null && content === void 0) {
      content = arg;
      continue;
    }
    var isString = (typeof arg === 'string' || arg instanceof String);
    if (isString && cardinality === null && /^[?.*+]$/.test(arg)) {
      cardinality = arg;
      continue;
    }
    if (apply === null || apply === undefined) {
      apply = arg.apply;
      if (apply != null) {
        content = arg.content;
        continue;
      }
    }
    if (content === void 0) {
      content = arg;
      continue;
    }
    break;
  }

  if (select === null) {
    throw new Error(
        'replace takes a select path, content or an apply function, and optional cardinality'
        );
  }

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

  return {replace: operation};
}
function replace ( ) { var select = null ; var content = void 0 ; var cardinality = null ; var apply = null ; var argLen = arguments . length ; for ( var i = 0 ; i < argLen ; i ++ ) { var arg = arguments [ i ] ; if ( i === 0 ) { select = arg ; continue ; } if ( arg === null && content === void 0 ) { content = arg ; continue ; } var isString = ( typeof arg === 'string' || arg instanceof String ) ; if ( isString && cardinality === null && / ^[?.*+]$ / . test ( arg ) ) { cardinality = arg ; continue ; } if ( apply === null || apply === undefined ) { apply = arg . apply ; if ( apply != null ) { content = arg . content ; continue ; } } if ( content === void 0 ) { content = arg ; continue ; } break ; } if ( select === null ) { throw new Error ( 'replace takes a select path, content or an apply function, and optional cardinality' ) ; } var operation = { select : select , content : content } ; if ( cardinality != null ) { operation . cardinality = cardinality ; } if ( apply != null ) { operation . apply = apply ; } return { replace : operation } ; }
Builds an operation to replace a JSON property or XML element or attribute.
@method
@since 1.0
@memberof patchBuilder#
@param {string}  select - the path to select the fragment to replace
@param           [content] - the object or value replacing the selected fragment or
an {@link patchBuilder.ApplyDefinition} specifying a function to apply to the selected
fragment to produce the replacement
@param {string}  [cardinality] - a specification from the ?|.|*|+
enumeration controlling whether the select 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 replace a JSON property or XML element or attribute .