lib/common.js
function handleArrayIndexRange(obj, key, any, val) {
  var match, start, end, leading, trailing, arr, set;
  match = key.match(PROPERTY_RANGE_REG);
  if (!match) {
    return;
  }

  set = isDefined(val);
  leading = match[1];

  if (leading) {
    arr = handleDeepProperty(obj, leading, any, false, set ? true : false, true);
  } else {
    arr = obj;
  }

  assertArray(arr);

  trailing = match[4];
  start    = match[2] ? +match[2] : 0;
  end      = match[3] ? +match[3] : arr.length;

  // A range of 0..1 is inclusive, so we need to add 1 to the end. If this
  // pushes the index from -1 to 0, then set it to the full length of the
  // array, otherwise it will return nothing.
  end = end === -1 ? arr.length : end + 1;

  if (set) {
    for (var i = start; i < end; i++) {
      handleDeepProperty(arr, i + trailing, any, false, true, false, val);
    }
  } else {
    arr = arr.slice(start, end);

    // If there are trailing properties, then they need to be mapped for each
    // element in the array.
    if (trailing) {
      if (trailing.charAt(0) === HALF_WIDTH_PERIOD) {
        // Need to chomp the period if one is trailing after the range. We
        // can't do this at the regex level because it will be required if
        // we're setting the value as it needs to be concatentated together
        // with the array index to be set.
        trailing = trailing.slice(1);
      }
      return map(arr, function(el) {
        return handleDeepProperty(el, trailing);
      });
    }
  }
  return arr;
}
function handleArrayIndexRange(obj, key, any, val) {
  var match, start, end, leading, trailing, arr, set;
  match = key.match(PROPERTY_RANGE_REG);
  if (!match) {
    return;
  }

  set = isDefined(val);
  leading = match[1];

  if (leading) {
    arr = handleDeepProperty(obj, leading, any, false, set ? true : false, true);
  } else {
    arr = obj;
  }

  assertArray(arr);

  trailing = match[4];
  start    = match[2] ? +match[2] : 0;
  end      = match[3] ? +match[3] : arr.length;

  // A range of 0..1 is inclusive, so we need to add 1 to the end. If this
  // pushes the index from -1 to 0, then set it to the full length of the
  // array, otherwise it will return nothing.
  end = end === -1 ? arr.length : end + 1;

  if (set) {
    for (var i = start; i < end; i++) {
      handleDeepProperty(arr, i + trailing, any, false, true, false, val);
    }
  } else {
    arr = arr.slice(start, end);

    // If there are trailing properties, then they need to be mapped for each
    // element in the array.
    if (trailing) {
      if (trailing.charAt(0) === HALF_WIDTH_PERIOD) {
        // Need to chomp the period if one is trailing after the range. We
        // can't do this at the regex level because it will be required if
        // we're setting the value as it needs to be concatentated together
        // with the array index to be set.
        trailing = trailing.slice(1);
      }
      return map(arr, function(el) {
        return handleDeepProperty(el, trailing);
      });
    }
  }
  return arr;
}
function handleArrayIndexRange ( obj , key , any , val ) { var match , start , end , leading , trailing , arr , set ; match = key . match ( PROPERTY_RANGE_REG ) ; if ( ! match ) { return ; } set = isDefined ( val ) ; leading = match [ 1 ] ; if ( leading ) { arr = handleDeepProperty ( obj , leading , any , false , set ? true : false , true ) ; } else { arr = obj ; } assertArray ( arr ) ; trailing = match [ 4 ] ; start = match [ 2 ] ? + match [ 2 ] : 0 ; end = match [ 3 ] ? + match [ 3 ] : arr . length ; // A range of 0..1 is inclusive, so we need to add 1 to the end. If this // pushes the index from -1 to 0, then set it to the full length of the // array, otherwise it will return nothing. end = end === - 1 ? arr . length : end + 1 ; if ( set ) { for ( var i = start ; i < end ; i ++ ) { handleDeepProperty ( arr , i + trailing , any , false , true , false , val ) ; } } else { arr = arr . slice ( start , end ) ; // If there are trailing properties, then they need to be mapped for each // element in the array. if ( trailing ) { if ( trailing . charAt ( 0 ) === HALF_WIDTH_PERIOD ) { // Need to chomp the period if one is trailing after the range. We // can't do this at the regex level because it will be required if // we're setting the value as it needs to be concatentated together // with the array index to be set. trailing = trailing . slice ( 1 ) ; } return map ( arr , function ( el ) { return handleDeepProperty ( el , trailing ) ; } ) ; } } return arr ; }
Get object property with support for 0..1 style range notation.
Get object property with support for 0 .. 1 style range notation .