actually these four lines could be reduced to one

    resolved = resolved.replace(/^(resource|file)\:\/([^\/])/, '$1://$2');