Skip to content

Commit

Permalink
Merge pull request willfarrell#106 from ajliv/definitely-typed
Browse files Browse the repository at this point in the history
Add DefinitelyTyped TypeScript definitions search
  • Loading branch information
willfarrell authored Apr 7, 2017
2 parents 2ce9cee + 0f6a610 commit da47822
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Binary file modified Package Managers.alfredworkflow
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Package Managers ([Download v3.15](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.15/Package.Managers.alfredworkflow))
# Package Managers ([Download v3.16](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.15/Package.Managers.alfredworkflow))

Package Repo Search

Expand All @@ -19,6 +19,7 @@ Quick package/plugin/component (repo) lookup for your favourite package managers
* `composer {query}`: PHP [Composer Packages](https://packagist.org)
* `crates {query}`: [Rust Crates](https://crates.io)
* `docker {query}`: [Docker Images](http://registry.hub.docker.io)
* `dt {query}`: DefinitelyTyped [TypeScript Definitions](http://definitelytyped.org)
* `gems {query}`: [Ruby Gems](http://rubygems.org)
* `gradle {query}`: Java [Gradle Packages](http://www.gradle.org)
* `grunt {query}`: nodeJS task-runner [Grunt Plugins](http://gruntjs.com)
Expand Down
Binary file added icon-cache/dt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon-src/dt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions src/DefinitelyTyped.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
namespace WillFarrell\AlfredPkgMan;

require_once('Cache.php');
require_once('Repo.php');

class DefinitelyTyped extends Repo
{
protected $id = 'dt';
protected $url = 'http://definitelytyped.org';
protected $search_url = 'https://api.npms.io/v2/search?q=scope:types+';

public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}

$this->pkgs = $this->cache->get_query_json(
$this->id,
$query,
"{$this->search_url}{$query}&size={$this->max_return}"
);

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

$this->cache->w->result(
$this->id,
$this->makeArg($name, $p->links->npm, "{$p->name}: {$p->version}"),
$name,
$p->description,
"icon-cache/{$this->id}.png"
);

// only search till max return reached
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
break;
}
}

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

return $this->xml();
}
}

// Test code, uncomment to debug this script from the command-line
// $repo = new DefinitelyTyped();
// echo $repo->search('react');

0 comments on commit da47822

Please sign in to comment.