Skip to content

Commit

Permalink
Merge pull request #103 from jgarber623/update-npm-search-engine
Browse files Browse the repository at this point in the history
Update npm search engine to npms.io
  • Loading branch information
willfarrell authored Jan 4, 2017
2 parents 4507d69 + 97ffd65 commit 172dd60
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
Binary file modified Package Managers.alfredworkflow
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Package Managers ([Download v3.13](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.13/Package.Managers.alfredworkflow))
# Package Managers ([Download v3.14](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.14/Package.Managers.alfredworkflow))

Package Repo Search

Expand Down
55 changes: 19 additions & 36 deletions src/Npm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,30 @@
class Npm extends Repo
{
protected $id = 'npm';
protected $url = 'https://www.npmjs.com';
protected $search_url = 'https://www.npmjs.com/search?q=';

public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
protected $url = 'https://npms.io';
protected $search_url = 'https://api.npms.io/v2/search?q=';
public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}
$this->pkgs = $this->cache->get_query_regex(
$this->pkgs = $this->cache->get_query_json(
$this->id,
$query,
"{$this->search_url}{$query}",
'/<div class="package-details">([\s\S]*?)<\/div>/i'
"{$this->search_url}{$query}&size={$this->max_return}"
);

foreach($this->pkgs as $pkg) {

// make params
preg_match('/<a class="name" href="[\s\S]*?">([\s\S]*?)<\/a>/i', $pkg, $matches);
$title = trim(strip_tags($matches[1]));

//preg_match('/<a class="author" href="[\s\S]*?">([\s\S]*?)<\/a>/i', $pkg, $matches);
//$author = trim(strip_tags($matches[1]));

preg_match('/<p class="description">([\s\S]*?)<\/p>/i', $pkg, $matches);

$description = html_entity_decode(trim(strip_tags($matches[1])));

foreach($this->pkgs->results as $pkg) {
$p = $pkg->package;
$name = $p->name;

//preg_match('/<span class="stars"><i class="icon-star"></i>([\s\S]*?)<\/span>/i', $pkg, $matches);
//$stars = trim(strip_tags($matches[1]));

preg_match('/<span class="version">([\s\S]*?)<\/span>/i', $pkg, $matches);
$version = trim(strip_tags($matches[1]));

$this->cache->w->result(
$title,
$this->makeArg($title, "{$this->url}/package/{$title}"),
"{$title} ~ {$version}", //.' by '.$author,
$description,
$this->id,
$this->makeArg($name, $p->links->npm, "{$p->name}: {$p->version}"),
$name,
$p->description,
"icon-cache/{$this->id}.png"
);

Expand All @@ -55,12 +39,11 @@ public function search($query)
break;
}
}



$this->noResults($query, "{$this->search_url}{$query}");

return $this->xml();
}
}
}

// Test code, uncomment to debug this script from the command-line
Expand Down

0 comments on commit 172dd60

Please sign in to comment.