lib/Project.js
function multiproject (pointer, target, path) {
            var pointerType = getTypeStr (pointer);
            var mainTarget;
            if (target)
                mainTarget = target;
            else
                if (pointerType == 'object')
                    target = {};
                else if (pointerType == 'array') {
                    target = [];
                    var remainingPath = path.slice (i);
                    for (var i in pointer) {
                        var found = multiproject (pointer[i], target[i], remainingPath);
                        if (found !== undefined)
                            target[i] = found;
                    }
                    return target;
                } else
                    return;

            for (var i=0,j=path.length-1; i<j; i++) {
                var pathStep = path[i];
                if (pathStep == '$')
                    throw new Error (
                        'cannot use the positional operator inside another Array'
                    );

                if (pointerType == 'array') {
                    if (!mainTarget) mainTarget = target;
                    var remainingPath = path.slice (i);
                    for (var k in pointer) {
                        var found = multiproject (pointer[k], target[k], remainingPath);
                        if (found !== undefined)
                            target[k] = found;
                    }
                    return mainTarget;
                } else if (pointerType != 'object')
                    return mainTarget; // if there's path left, we must be a container type

                if (!Object.hasOwnProperty.call (pointer, pathStep))
                    return mainTarget; // not found
                if (!mainTarget) mainTarget = target;
                pointer = pointer[pathStep];
                pointerType = getTypeStr (pointer);

                if (Object.hasOwnProperty.call (target, pathStep))
                    target = target[pathStep];
                else
                    if (pointerType == 'object')
                        target = target[pathStep] = {};
                    else
                        target = target[pathStep] = [];
            }

            var finalStep = path[path.length-1];
            if (!mainTarget) mainTarget = target;

            if (pointerType == 'array') {
                for (var k in pointer) {
                    var found = multiproject (pointer[k], target[k], [ finalStep ]);
                    if (found !== undefined)
                        target[k] = found;
                }
                return mainTarget;
            } else if (pointerType != 'object')
                return mainTarget;

            if (Object.hasOwnProperty.call (pointer, finalStep)) {
                target[finalStep] = pointer[finalStep];
                if (!mainTarget) mainTarget = target;
            }
            return mainTarget;
        }
function multiproject (pointer, target, path) {
            var pointerType = getTypeStr (pointer);
            var mainTarget;
            if (target)
                mainTarget = target;
            else
                if (pointerType == 'object')
                    target = {};
                else if (pointerType == 'array') {
                    target = [];
                    var remainingPath = path.slice (i);
                    for (var i in pointer) {
                        var found = multiproject (pointer[i], target[i], remainingPath);
                        if (found !== undefined)
                            target[i] = found;
                    }
                    return target;
                } else
                    return;

            for (var i=0,j=path.length-1; i<j; i++) {
                var pathStep = path[i];
                if (pathStep == '$')
                    throw new Error (
                        'cannot use the positional operator inside another Array'
                    );

                if (pointerType == 'array') {
                    if (!mainTarget) mainTarget = target;
                    var remainingPath = path.slice (i);
                    for (var k in pointer) {
                        var found = multiproject (pointer[k], target[k], remainingPath);
                        if (found !== undefined)
                            target[k] = found;
                    }
                    return mainTarget;
                } else if (pointerType != 'object')
                    return mainTarget; // if there's path left, we must be a container type

                if (!Object.hasOwnProperty.call (pointer, pathStep))
                    return mainTarget; // not found
                if (!mainTarget) mainTarget = target;
                pointer = pointer[pathStep];
                pointerType = getTypeStr (pointer);

                if (Object.hasOwnProperty.call (target, pathStep))
                    target = target[pathStep];
                else
                    if (pointerType == 'object')
                        target = target[pathStep] = {};
                    else
                        target = target[pathStep] = [];
            }

            var finalStep = path[path.length-1];
            if (!mainTarget) mainTarget = target;

            if (pointerType == 'array') {
                for (var k in pointer) {
                    var found = multiproject (pointer[k], target[k], [ finalStep ]);
                    if (found !== undefined)
                        target[k] = found;
                }
                return mainTarget;
            } else if (pointerType != 'object')
                return mainTarget;

            if (Object.hasOwnProperty.call (pointer, finalStep)) {
                target[finalStep] = pointer[finalStep];
                if (!mainTarget) mainTarget = target;
            }
            return mainTarget;
        }
function multiproject ( pointer , target , path ) { var pointerType = getTypeStr ( pointer ) ; var mainTarget ; if ( target ) mainTarget = target ; else if ( pointerType == 'object' ) target = { } ; else if ( pointerType == 'array' ) { target = [ ] ; var remainingPath = path . slice ( i ) ; for ( var i in pointer ) { var found = multiproject ( pointer [ i ] , target [ i ] , remainingPath ) ; if ( found !== undefined ) target [ i ] = found ; } return target ; } else return ; for ( var i = 0 , j = path . length - 1 ; i < j ; i ++ ) { var pathStep = path [ i ] ; if ( pathStep == '$' ) throw new Error ( 'cannot use the positional operator inside another Array' ) ; if ( pointerType == 'array' ) { if ( ! mainTarget ) mainTarget = target ; var remainingPath = path . slice ( i ) ; for ( var k in pointer ) { var found = multiproject ( pointer [ k ] , target [ k ] , remainingPath ) ; if ( found !== undefined ) target [ k ] = found ; } return mainTarget ; } else if ( pointerType != 'object' ) return mainTarget ; // if there's path left, we must be a container type if ( ! Object . hasOwnProperty . call ( pointer , pathStep ) ) return mainTarget ; // not found if ( ! mainTarget ) mainTarget = target ; pointer = pointer [ pathStep ] ; pointerType = getTypeStr ( pointer ) ; if ( Object . hasOwnProperty . call ( target , pathStep ) ) target = target [ pathStep ] ; else if ( pointerType == 'object' ) target = target [ pathStep ] = { } ; else target = target [ pathStep ] = [ ] ; } var finalStep = path [ path . length - 1 ] ; if ( ! mainTarget ) mainTarget = target ; if ( pointerType == 'array' ) { for ( var k in pointer ) { var found = multiproject ( pointer [ k ] , target [ k ] , [ finalStep ] ) ; if ( found !== undefined ) target [ k ] = found ; } return mainTarget ; } else if ( pointerType != 'object' ) return mainTarget ; if ( Object . hasOwnProperty . call ( pointer , finalStep ) ) { target [ finalStep ] = pointer [ finalStep ] ; if ( ! mainTarget ) mainTarget = target ; } return mainTarget ; }
in case we traverse any Arrays during this projection
in case we traverse any Arrays during this projection