lib/index.js
/**
 * Delete a property by a dot path.
 * If target container is an object, the property is deleted.
 * If target container is an array, the index is deleted.
 * If target container is undefined, nothing is deleted.
 * @param obj The object to evaluate.
 * @param prop The path to the property or index that should be deleted.
 */
Delete a property by a dot path.
If target container is an object, the property is deleted.
If target container is an array, the index is deleted.
If target container is undefined, nothing is deleted.
@param obj The object to evaluate.
@param prop The path to the property or index that should be deleted.
Delete a property by a dot path . If target container is an object the property is deleted . If target container is an array the index is deleted . If target container is undefined nothing is deleted . @param obj The object to evaluate . @param prop The path to the property or index that should be deleted .
function _delete(obj, prop) {
	prop = typeof prop === 'number' ? propToArray(prop.toString()) : typeof prop === 'string' ? propToArray(prop) : prop;
	const deletePropImmutableRec = (obj, prop, i) => {
		let clone, head = prop[i];
		if (obj === null || typeof obj !== 'object' ||
			!Array.isArray(obj) && obj[head] === undefined) {
			return obj;
		}
		if (prop.length - 1 > i) {
			if (Array.isArray(obj)) {
				head = getArrayIndex(head, obj);
				clone = obj.slice();
			} else {
				clone = Object.assign({}, obj);
			}
			clone[head] = deletePropImmutableRec(obj[head], prop, i + 1);
			return clone;
		}
		if (Array.isArray(obj)) {
			head = getArrayIndex(head, obj);
			clone = [].concat(obj.slice(0, head), obj.slice(head + 1));
		} else {
			clone = Object.assign({}, obj);
			delete clone[head];
		}
		return clone;
	};
	return deletePropImmutableRec(obj, prop, 0);
}
function _delete ( obj , prop ) { prop = typeof prop === 'number' ? propToArray ( prop . toString ( ) ) : typeof prop === 'string' ? propToArray ( prop ) : prop ; const deletePropImmutableRec = ( obj , prop , i ) => { let clone , head = prop [ i ] ; if ( obj === null || typeof obj !== 'object' || ! Array . isArray ( obj ) && obj [ head ] === undefined ) { return obj ; } if ( prop . length - 1 > i ) { if ( Array . isArray ( obj ) ) { head = getArrayIndex ( head , obj ) ; clone = obj . slice ( ) ; } else { clone = Object . assign ( { } , obj ) ; } clone [ head ] = deletePropImmutableRec ( obj [ head ] , prop , i + 1 ) ; return clone ; } if ( Array . isArray ( obj ) ) { head = getArrayIndex ( head , obj ) ; clone = [ ] . concat ( obj . slice ( 0 , head ) , obj . slice ( head + 1 ) ) ; } else { clone = Object . assign ( { } , obj ) ; delete clone [ head ] ; } return clone ; } ; return deletePropImmutableRec ( obj , prop , 0 ) ; }
Delete a property by a dot path.
Delete a property by a dot path .