{"id":32618840,"url":"https://github.com/kapersoft/npmsearch-api","last_synced_at":"2025-10-30T17:58:18.181Z","repository":{"id":57004394,"uuid":"125428771","full_name":"kapersoft/npmsearch-api","owner":"kapersoft","description":"Search for NPM packages using npmsearch.com API","archived":false,"fork":false,"pushed_at":"2018-03-28T15:33:16.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-15T17:36:51.077Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kapersoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-15T21:35:57.000Z","updated_at":"2018-03-28T15:33:17.000Z","dependencies_parsed_at":"2022-08-21T13:50:50.143Z","dependency_job_id":null,"html_url":"https://github.com/kapersoft/npmsearch-api","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kapersoft/npmsearch-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapersoft%2Fnpmsearch-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapersoft%2Fnpmsearch-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapersoft%2Fnpmsearch-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapersoft%2Fnpmsearch-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kapersoft","download_url":"https://codeload.github.com/kapersoft/npmsearch-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapersoft%2Fnpmsearch-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281853653,"owners_count":26573096,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-30T17:57:35.508Z","updated_at":"2025-10-30T17:58:18.164Z","avatar_url":"https://github.com/kapersoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Search for NPM packages using npmsearch.com API\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/kapersoft/npmsearch-api.svg?style=flat-square)](https://packagist.org/packages/kapersoft/npmsearch-api)\n[![Build Status](https://img.shields.io/travis/kapersoft/npmsearch-api/master.svg?style=flat-square)](https://travis-ci.org/kapersoft/npmsearch-api)\n[![StyleCI](https://styleci.io/repos/125428771/shield?branch=master)](https://styleci.io/repos/125428771)\n[![Quality Score](https://img.shields.io/scrutinizer/g/kapersoft/npmsearch-api.svg?style=flat-square)](https://scrutinizer-ci.com/g/kapersoft/npmsearch-api)\n[![Total Downloads](https://img.shields.io/packagist/dt/kapersoft/npmsearch-api.svg?style=flat-square)](https://packagist.org/packages/kapersoft/npmsearch-api)\n\nThis 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).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require kapersoft/npmsearch-api\n```\n\n## Usage\n\nFirst you initiate the NpmSearch object.\n\n``` php\n// Initiate NpmSearch\n$npmSearch = new Kapersoft\\NpmSearch\\NpmSearch();\n```\n\nIf 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.\n\n``` php\n// Create Guzzle HTTP Client\n$guzzleClient = new \\GuzzleHttp\\Client();\n\n// Initiate NpmSearch with custom URL and Guzzle HTTP Client\n$npmSearch = new Kapersoft\\NpmSearch\\NpmSearch('https://my-own-npmsearch-api/query', $guzzleClient);\n```\n\n### Search packages\n\nYou can search packages using the `search`-method:\n\n``` php\n// Search for kapersoft\n$npmSearch-\u003esearch('kapersoft');\n```\n\nThe result is converted to an array that looks like this:\n\n``` php\narray:4 [\n  \"results\" =\u003e array:1 [\n    0 =\u003e array:8 [\n      \"maintainers\" =\u003e array:1 [\n        0 =\u003e \"kapersoft\"\n      ]\n      \"score\" =\u003e array:1 [\n        0 =\u003e 0\n      ]\n      \"author\" =\u003e array:1 [\n        0 =\u003e \"kapersoft\"\n      ]\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"npo\"\n      ]\n      \"description\" =\u003e array:1 [\n        0 =\u003e \"CLI utility to watch NPO streams in QuickTime Player\"\n      ]\n      \"version\" =\u003e array:1 [\n        0 =\u003e \"1.2.0\"\n      ]\n      \"rating\" =\u003e array:1 [\n        0 =\u003e 0\n      ]\n      \"modified\" =\u003e array:1 [\n        0 =\u003e \"2018-02-11T22:22:18.543Z\"\n      ]\n    ]\n  ]\n  \"total\" =\u003e 1\n  \"size\" =\u003e 10\n  \"from\" =\u003e \"0\"\n]\n```\n\n### Specify fields\n\nBy default the result will include all fields except `readme`. You can specify the fields in the `$fields` property of the `NpmSearch`-object.\n\nFor example:\n\n``` php\n// Search for jquery with field 'name' returned in the result\n$npmsSearch-\u003efields = ['name'];\n$npmSearch-\u003esearch('jquery');\n```\n\nWill return this result:\n\n``` php\narray:4 [\n  \"results\" =\u003e array:10 [\n    0 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"makeup-jquery\"\n      ]\n    ]\n    1 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"egis-jquery-qrcode\"\n      ]\n    ]\n    2 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"eslint-plugin-jquery\"\n      ]\n    ]\n    3 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"kd-shim-jquery-mousewheel\"\n      ]\n    ]\n    4 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"jquery-joint-colorbox\"\n      ]\n    ]\n    5 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"apta-jquery\"\n      ]\n    ]\n    6 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"jquery-shim\"\n      ]\n    ]\n    7 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"eslint-plugin-various\"\n      ]\n    ]\n    8 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"makeup-ebay\"\n      ]\n    ]\n    9 =\u003e array:1 [\n      \"name\" =\u003e array:1 [\n        0 =\u003e \"jquery-cycle-2\"\n      ]\n    ]\n  ]\n  \"total\" =\u003e 33208\n  \"size\" =\u003e 10\n  \"from\" =\u003e \"0\"\n]\n```\n\n### Paging\n\nBy default the first 10 results will be returned. If you want to query more packages, you can specify the `$start` and `$rows` parameters:\n\n``` php\n// Search for jquery packages 100 to 105\n$npmSearch-\u003esearch('jquery', 100, 5);\n```\n\n### Extended search methods\n\nThere are also extended search methods next the default `search`-method mentioned above. You can search for example for packages by author:\n\n``` php\n// Search for packages by author 'npm'\n$npmSearch-\u003esearchByAuthor('npm');\n```\n\nOf course the `$start` and `$rows` parameters are also available for these methods:\n\n``` php\n// Search for packages by author 'npm' from 15 to 25\n$npmSearch-\u003esearchByAuthor('npm', 15, 10);\n```\n\n### Advanced search options\n\nIn 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:\n\n``` php\n// Search for packages using a regular expression\n$npmSearch-\u003esearch('name:/joh?n(ath[oa]n)/');\n```\n\n### Available search methods\n\nBelow the complete list of all search methods:\n\n- `search($q, $start = 0, $rows = 10)`\n- `searchByAuthor($author, $start = 0, $rows = 10)`\n- `searchByCreated($created, $start = 0, $rows = 10)`\n- `searchByDependencies($dependencies, $start = 0, $rows = 10)`\n- `searchByDescription($Description, $start = 0, $rows = 10)`\n- `searchByDevDependencies($devDependencies, $start = 0, $rows = 10)`\n- `searchByHomepage($homepage, $start = 0, $rows = 10)`\n- `searchByKeywords($keywords, $start = 0, $rows = 10)`\n- `searchByMaintainers($maintainers, $start = 0, $rows = 10)`\n- `searchByModified($modified, $start = 0, $rows = 10)`\n- `searchByName($name, $start = 0, $rows = 10)`\n- `searchByRating($rating, $start = 0, $rows = 10)` - computed rating as per [bin/ratings.js](https://github.com/nodesource/npmsearch/blob/master/bin/rating.js)\n- `searchByReadme($readme, $start = 0, $rows = 10)`\n- `searchByRepository($repository, $start = 0, $rows = 10)`\n- `searchByScripts($scripts, $start = 0, $rows = 10)`\n- `searchByTimes($times, $start = 0, $rows = 10)`\n- `searchByVersion($version, $start = 0, $rows = 10)`\n\n## Testing\n\nIn the `/tests`-folder is one test defined:\n\n- `NpmSearchTest.php` tests the `Kapersoft\\NpmSearch\\NpmSearch-class` using mock Guzzle objects;\n\nYou can run the tests in your terminal:\n\n``` bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email kapersoft@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Jan Willem Kaper](https://github.com/kapersoft)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.txt) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapersoft%2Fnpmsearch-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkapersoft%2Fnpmsearch-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapersoft%2Fnpmsearch-api/lists"}