index.js
function getNpmData(pkg, npmClient, callback) {

  callback = once(callback);

  // default to latest version
  if (!pkg.version || pkg.version === 'latest') {
    pkg.version = '*';
  }

  npmClient.get(pkg.name, { staleOk: true }, errTo(callback, function(npmPackageInfo) {
    var version;

    version = semver.maxSatisfying(Object.keys(npmPackageInfo.versions), pkg.version);

    // if the version is not found, perhaps the cache is old, force load from registry
    if (!version) {
      npmClient.get(pkg.name, { staleOk: true }, errTo(callback, function(npmPackageInfo) {
        callback(null, npmPackageInfo.versions[version] || null);
      }));
    } else {
      callback(null, npmPackageInfo.versions[version] || null);
    }
  }));
}
function getNpmData(pkg, npmClient, callback) {

  callback = once(callback);

  // default to latest version
  if (!pkg.version || pkg.version === 'latest') {
    pkg.version = '*';
  }

  npmClient.get(pkg.name, { staleOk: true }, errTo(callback, function(npmPackageInfo) {
    var version;

    version = semver.maxSatisfying(Object.keys(npmPackageInfo.versions), pkg.version);

    // if the version is not found, perhaps the cache is old, force load from registry
    if (!version) {
      npmClient.get(pkg.name, { staleOk: true }, errTo(callback, function(npmPackageInfo) {
        callback(null, npmPackageInfo.versions[version] || null);
      }));
    } else {
      callback(null, npmPackageInfo.versions[version] || null);
    }
  }));
}
function getNpmData ( pkg , npmClient , callback ) { callback = once ( callback ) ; // default to latest version if ( ! pkg . version || pkg . version === 'latest' ) { pkg . version = '*' ; } npmClient . get ( pkg . name , { staleOk : true } , errTo ( callback , function ( npmPackageInfo ) { var version ; version = semver . maxSatisfying ( Object . keys ( npmPackageInfo . versions ) , pkg . version ) ; // if the version is not found, perhaps the cache is old, force load from registry if ( ! version ) { npmClient . get ( pkg . name , { staleOk : true } , errTo ( callback , function ( npmPackageInfo ) { callback ( null , npmPackageInfo . versions [ version ] || null ) ; } ) ) ; } else { callback ( null , npmPackageInfo . versions [ version ] || null ) ; } } ) ) ; }
Fetches data from the NPM registry for a package based on its name and version range.
It will find the maximum version that satisfies the range.

@param {Object} pkg - contains version and name of the package
@param {Object} npmClient - instance of npm-pkginfo
@param {Function} callback
Fetches data from the NPM registry for a package based on its name and version range . It will find the maximum version that satisfies the range .