PHPackages                             kapersoft/npmsearch-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. kapersoft/npmsearch-api

ActiveLibrary[Search &amp; Filtering](/categories/search)

kapersoft/npmsearch-api
=======================

Search for NPM packages using npmsearch.com API

1.1.0(8y ago)115MITPHPPHP ^7.0

Since Mar 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/kapersoft/npmsearch-api)[ Packagist](https://packagist.org/packages/kapersoft/npmsearch-api)[ Docs](https://github.com/kapersoft/npmsearch-api)[ RSS](/packages/kapersoft-npmsearch-api/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Search for NPM packages using npmsearch.com API
===============================================

[](#search-for-npm-packages-using-npmsearchcom-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/87163475d79bfb70cbffa6c00f0da4aef99dc5c503e0f57585ea7097158815bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b61706572736f66742f6e706d7365617263682d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kapersoft/npmsearch-api)[![Build Status](https://camo.githubusercontent.com/09d079ef7eedc2b219e1b34d97b1acd2034902b1af1be61189f8ee419d95d37e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6b61706572736f66742f6e706d7365617263682d6170692f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/kapersoft/npmsearch-api)[![StyleCI](https://camo.githubusercontent.com/6d16869659ad40405731285fccc91feadb7e61de5750736df587921e213d5299/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132353432383737312f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/125428771)[![Quality Score](https://camo.githubusercontent.com/6e6c6a8b7103ac646e38b2a4502a55a68c2808fda1669d2cebc7e75982b02d3a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6b61706572736f66742f6e706d7365617263682d6170692e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/kapersoft/npmsearch-api)[![Total Downloads](https://camo.githubusercontent.com/ad044e0170f624742e32bbc4827458fffb2955bb4fc5fad00e0e9cdc2960453c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b61706572736f66742f6e706d7365617263682d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kapersoft/npmsearch-api)

This is an implementation of [npmsearch.com](https://npmsearch.com) API for the PHP programming environment. More information about [npmsearch.com](https://npmsearch.com) and their API can be found at their [GitHub repository](https://github.com/nodesource/npmsearch).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kapersoft/npmsearch-api
```

Usage
-----

[](#usage)

First you initiate the NpmSearch object.

```
// Initiate NpmSearch
$npmSearch = new Kapersoft\NpmSearch\NpmSearch();
```

If you like to use your own [NpmSearch imeplementation](https://github.com/nodesource/npmsearch). You can override the URL of the API in the constructor of `Kapersoft\NpmSearch\NpmSearch`. You can also pass your your own [Guzzle HTTP client](https://github.com/guzzle/guzzle) to the constructor.

```
// Create Guzzle HTTP Client
$guzzleClient = new \GuzzleHttp\Client();

// Initiate NpmSearch with custom URL and Guzzle HTTP Client
$npmSearch = new Kapersoft\NpmSearch\NpmSearch('https://my-own-npmsearch-api/query', $guzzleClient);
```

### Search packages

[](#search-packages)

You can search packages using the `search`-method:

```
// Search for kapersoft
$npmSearch->search('kapersoft');
```

The result is converted to an array that looks like this:

```
array:4 [
  "results" => array:1 [
    0 => array:8 [
      "maintainers" => array:1 [
        0 => "kapersoft"
      ]
      "score" => array:1 [
        0 => 0
      ]
      "author" => array:1 [
        0 => "kapersoft"
      ]
      "name" => array:1 [
        0 => "npo"
      ]
      "description" => array:1 [
        0 => "CLI utility to watch NPO streams in QuickTime Player"
      ]
      "version" => array:1 [
        0 => "1.2.0"
      ]
      "rating" => array:1 [
        0 => 0
      ]
      "modified" => array:1 [
        0 => "2018-02-11T22:22:18.543Z"
      ]
    ]
  ]
  "total" => 1
  "size" => 10
  "from" => "0"
]
```

### Specify fields

[](#specify-fields)

By default the result will include all fields except `readme`. You can specify the fields in the `$fields` property of the `NpmSearch`-object.

For example:

```
// Search for jquery with field 'name' returned in the result
$npmsSearch->fields = ['name'];
$npmSearch->search('jquery');
```

Will return this result:

```
array:4 [
  "results" => array:10 [
    0 => array:1 [
      "name" => array:1 [
        0 => "makeup-jquery"
      ]
    ]
    1 => array:1 [
      "name" => array:1 [
        0 => "egis-jquery-qrcode"
      ]
    ]
    2 => array:1 [
      "name" => array:1 [
        0 => "eslint-plugin-jquery"
      ]
    ]
    3 => array:1 [
      "name" => array:1 [
        0 => "kd-shim-jquery-mousewheel"
      ]
    ]
    4 => array:1 [
      "name" => array:1 [
        0 => "jquery-joint-colorbox"
      ]
    ]
    5 => array:1 [
      "name" => array:1 [
        0 => "apta-jquery"
      ]
    ]
    6 => array:1 [
      "name" => array:1 [
        0 => "jquery-shim"
      ]
    ]
    7 => array:1 [
      "name" => array:1 [
        0 => "eslint-plugin-various"
      ]
    ]
    8 => array:1 [
      "name" => array:1 [
        0 => "makeup-ebay"
      ]
    ]
    9 => array:1 [
      "name" => array:1 [
        0 => "jquery-cycle-2"
      ]
    ]
  ]
  "total" => 33208
  "size" => 10
  "from" => "0"
]
```

### Paging

[](#paging)

By default the first 10 results will be returned. If you want to query more packages, you can specify the `$start` and `$rows` parameters:

```
// Search for jquery packages 100 to 105
$npmSearch->search('jquery', 100, 5);
```

### Extended search methods

[](#extended-search-methods)

There are also extended search methods next the default `search`-method mentioned above. You can search for example for packages by author:

```
// Search for packages by author 'npm'
$npmSearch->searchByAuthor('npm');
```

Of course the `$start` and `$rows` parameters are also available for these methods:

```
// Search for packages by author 'npm' from 15 to 25
$npmSearch->searchByAuthor('npm', 15, 10);
```

### Advanced search options

[](#advanced-search-options)

In the backend [npmsearch.com](https://npmsearch.com) is a proxy to an ElasticSearch server. So you can use [ElasticSearch query string syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax) in the `search`method:

```
// Search for packages using a regular expression
$npmSearch->search('name:/joh?n(ath[oa]n)/');
```

### Available search methods

[](#available-search-methods)

Below the complete list of all search methods:

- `search($q, $start = 0, $rows = 10)`
- `searchByAuthor($author, $start = 0, $rows = 10)`
- `searchByCreated($created, $start = 0, $rows = 10)`
- `searchByDependencies($dependencies, $start = 0, $rows = 10)`
- `searchByDescription($Description, $start = 0, $rows = 10)`
- `searchByDevDependencies($devDependencies, $start = 0, $rows = 10)`
- `searchByHomepage($homepage, $start = 0, $rows = 10)`
- `searchByKeywords($keywords, $start = 0, $rows = 10)`
- `searchByMaintainers($maintainers, $start = 0, $rows = 10)`
- `searchByModified($modified, $start = 0, $rows = 10)`
- `searchByName($name, $start = 0, $rows = 10)`
- `searchByRating($rating, $start = 0, $rows = 10)` - computed rating as per [bin/ratings.js](https://github.com/nodesource/npmsearch/blob/master/bin/rating.js)
- `searchByReadme($readme, $start = 0, $rows = 10)`
- `searchByRepository($repository, $start = 0, $rows = 10)`
- `searchByScripts($scripts, $start = 0, $rows = 10)`
- `searchByTimes($times, $start = 0, $rows = 10)`
- `searchByVersion($version, $start = 0, $rows = 10)`

Testing
-------

[](#testing)

In the `/tests`-folder is one test defined:

- `NpmSearchTest.php` tests the `Kapersoft\NpmSearch\NpmSearch-class` using mock Guzzle objects;

You can run the tests in your terminal:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jan Willem Kaper](https://github.com/kapersoft)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.txt) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

2978d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b282b144777d8ee6a9f1d468dd4fd44e549e337fee20857af65252fa505aeca?d=identicon)[kapersoft](/maintainers/kapersoft)

---

Top Contributors

[![kapersoft](https://avatars.githubusercontent.com/u/13007854?v=4)](https://github.com/kapersoft "kapersoft (20 commits)")

---

Tags

searchpackagepackagesnpmkapersoftnpmsearch-apinpmsearch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kapersoft-npmsearch-api/health.svg)

```
[![Health](https://phpackages.com/badges/kapersoft-npmsearch-api/health.svg)](https://phpackages.com/packages/kapersoft-npmsearch-api)
```

###  Alternatives

[statamic-rad-pack/meilisearch

meilisearch search driver for Statamic

1661.7k](/packages/statamic-rad-pack-meilisearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
