node_modules/snyk/dist/cli/535.index.js
/**
 * Parses a string package id (name + optional version) to an object.
 *
 * This method used to be named `moduleToObject`.
 */
Parses a string package id (name + optional version) to an object.
This method used to be named `moduleToObject`.
Parses a string package id ( name + optional version ) to an object . This method used to be named ` moduleToObject ` .
function parsePackageString(nameAndMaybeVersion, versionOrOptions, options) {
    if (!nameAndMaybeVersion) {
        throw new Error('requires string to parse into module');
    }
    let version;
    if (versionOrOptions && !options && typeof versionOrOptions === 'object') {
        options = versionOrOptions;
    }
    else {
        version = versionOrOptions;
    }
    let str = nameAndMaybeVersion;
    if (!version) {
        const fastPath = /^(?:(?:[a-z-]+)|(?:@[a-z-]+\/[a-z-]+)|(?:[a-z-]+\.[.a-z-]+:[a-z-]+))$/;
        if (fastPath.test(str)) {
            return supported(str, { name: str, version: '*' }, options);
        }
    }
    if (version && str.lastIndexOf('@') < 1) {
        debug('appending version onto string');
        str += '@' + version;
    }
    const gitObject = looksLikeUrl(str);
    if (gitObject) {
        return supported(str, fromGitObject(gitObject), options);
    }
    let parts = str.split('@');
    if (str.indexOf('@') === 0) {
        parts = parts.slice(1);
        parts[0] = '@' + parts[0];
    }
    const maybeGitObject = parts[1] && looksLikeUrl(parts[1]);
    if (maybeGitObject) {
        return supported(str, fromGitObject(maybeGitObject), options);
    }
    if (parts.length === 1) {
        parts.push('*');
    }
    const module = {
        name: parts[0],
        version: parts.slice(1).join('@'),
    };
    return supported(str, module, options);
}
function parsePackageString ( nameAndMaybeVersion , versionOrOptions , options ) { if ( ! nameAndMaybeVersion ) { throw new Error ( 'requires string to parse into module' ) ; } let version ; if ( versionOrOptions && ! options && typeof versionOrOptions === 'object' ) { options = versionOrOptions ; } else { version = versionOrOptions ; } let str = nameAndMaybeVersion ; if ( ! version ) { const fastPath = / ^(?:(?:[a-z-]+)|(?:@[a-z-]+\/[a-z-]+)|(?:[a-z-]+\.[.a-z-]+:[a-z-]+))$ / ; if ( fastPath . test ( str ) ) { return supported ( str , { name : str , version : '*' } , options ) ; } } if ( version && str . lastIndexOf ( '@' ) < 1 ) { debug ( 'appending version onto string' ) ; str += '@' + version ; } const gitObject = looksLikeUrl ( str ) ; if ( gitObject ) { return supported ( str , fromGitObject ( gitObject ) , options ) ; } let parts = str . split ( '@' ) ; if ( str . indexOf ( '@' ) === 0 ) { parts = parts . slice ( 1 ) ; parts [ 0 ] = '@' + parts [ 0 ] ; } const maybeGitObject = parts [ 1 ] && looksLikeUrl ( parts [ 1 ] ) ; if ( maybeGitObject ) { return supported ( str , fromGitObject ( maybeGitObject ) , options ) ; } if ( parts . length === 1 ) { parts . push ( '*' ) ; } const module = { name : parts [ 0 ] , version : parts . slice ( 1 ) . join ( '@' ) , } ; return supported ( str , module , options ) ; }
Parses a string package id (name + optional version) to an object.
Parses a string package id ( name + optional version ) to an object .
// first, try the common case; there's no version, and it's a normal package name // foo, foo-bar, @foo/bar, com.example:test // none of these can be URLs, or versions // first try with regular git urls // then the string looks like a url, let's try to parse it // put the scoped package name back together // then as a backup, try pkg@giturl // then the string looks like a url, let's try to parse it // no version