func (n *NPMLookup) isAvailableInPublic(pkgname string, retry int) bool {
	if retry > 3 {
		fmt.Printf(" [W] Maximum number of retries exhausted for package: %s\n", pkgname)
		return false
	}
	if n.Verbose {
		fmt.Print("Checking: https://registry.npmjs.org/" + pkgname + "/ : ")
	}
	resp, err := http.Get("https://registry.npmjs.org/" + pkgname + "/")
	if err != nil {
		fmt.Printf(" [W] Error when trying to request https://registry.npmjs.org/"+pkgname+"/ : %s\n", err)
		return false
	}
	defer resp.Body.Close()
	if n.Verbose {
		fmt.Printf("%s\n", resp.Status)
	}
	if resp.StatusCode == http.StatusOK {
		npmResp := NpmResponse{}
		body, _ := ioutil.ReadAll(resp.Body)
		_ = json.Unmarshal(body, &npmResp)
		if npmResp.NotAvailable() {
			if n.Verbose {
				fmt.Printf("[W] Package %s was found, but all its versions are unpublished, making anyone able to takeover the namespace.\n", pkgname)
			}
			return false
		}
		return true
	} else if resp.StatusCode == 429 {
		fmt.Printf(" [!] Server responded with 429 (Too many requests), throttling and retrying...\n")
		time.Sleep(10 * time.Second)
		retry = retry + 1
		n.isAvailableInPublic(pkgname, retry)
	}
	return false
}
// isAvailableInPublic determines if an npm package exists in the public npm package repository.
//
// Returns true if the package exists in the public npm package repository.
isAvailableInPublic determines if an npm package exists in the public npm package repository.

Returns true if the package exists in the public npm package repository.
// isAvailableInPublic determines if an npm package exists in the public npm package repository . // // Returns true if the package exists in the public npm package repository .
func (n *NPMLookup) isAvailableInPublic(pkgname string, retry int) bool {
	if retry > 3 {
		fmt.Printf(" [W] Maximum number of retries exhausted for package: %s\n", pkgname)
		return false
	}
	if n.Verbose {
		fmt.Print("Checking: https://registry.npmjs.org/" + pkgname + "/ : ")
	}
	resp, err := http.Get("https://registry.npmjs.org/" + pkgname + "/")
	if err != nil {
		fmt.Printf(" [W] Error when trying to request https://registry.npmjs.org/"+pkgname+"/ : %s\n", err)
		return false
	}
	defer resp.Body.Close()
	if n.Verbose {
		fmt.Printf("%s\n", resp.Status)
	}
	if resp.StatusCode == http.StatusOK {
		npmResp := NpmResponse{}
		body, _ := ioutil.ReadAll(resp.Body)
		_ = json.Unmarshal(body, &npmResp)
		if npmResp.NotAvailable() {
			if n.Verbose {
				fmt.Printf("[W] Package %s was found, but all its versions are unpublished, making anyone able to takeover the namespace.\n", pkgname)
			}
			return false
		}
		return true
	} else if resp.StatusCode == 429 {
		fmt.Printf(" [!] Server responded with 429 (Too many requests), throttling and retrying...\n")
		time.Sleep(10 * time.Second)
		retry = retry + 1
		n.isAvailableInPublic(pkgname, retry)
	}
	return false
}
func ( n * NPMLookup ) isAvailableInPublic ( pkgname string , retry int ) bool { if retry > 3 { fmt . Printf ( " \n " , pkgname ) return false } if n . Verbose { fmt . Print ( " " + pkgname + " " ) } resp , err := http . Get ( " " + pkgname + " " ) if err != nil { fmt . Printf ( " " + pkgname + " \n " , err ) return false } defer resp . Body . Close ( ) if n . Verbose { fmt . Printf ( " \n " , resp . Status ) } if resp . StatusCode == http . StatusOK { npmResp := NpmResponse { } body , _ := ioutil . ReadAll ( resp . Body ) _ = json . Unmarshal ( body , & npmResp ) if npmResp . NotAvailable ( ) { if n . Verbose { fmt . Printf ( " \n " , pkgname ) } return false } return true } else if resp . StatusCode == 429 { fmt . Printf ( " \n " ) time . Sleep ( 10 * time . Second ) retry = retry + 1 n . isAvailableInPublic ( pkgname , retry ) } return false }
isAvailableInPublic determines if an npm package exists in the public npm package repository.
isAvailableInPublic determines if an npm package exists in the public npm package repository .