PHP code example of kapersoft / npmsearch-api

1. Go to this page and download the library: Download kapersoft/npmsearch-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kapersoft / npmsearch-api example snippets

 php
// Initiate NpmSearch
$npmSearch = new Kapersoft\NpmSearch\NpmSearch();
 php
// Search for kapersoft
$npmSearch->search('kapersoft');
 php
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"
]
 php
// Search for jquery with field 'name' returned in the result
$npmsSearch->fields = ['name'];
$npmSearch->search('jquery');
 php
// Search for packages by author 'npm'
$npmSearch->searchByAuthor('npm');
 php
// Search for packages using a regular expression
$npmSearch->search('name:/joh?n(ath[oa]n)/');