Query npmjs registry via api

前端 未结 10 1548
走了就别回头了
走了就别回头了 2020-12-23 13:51

I find I\'m often unsatisfied with the ordering and expressiveness of searches on https://www.npmjs.com/. I guess there should be a way to programmatically query the server

10条回答
  •  生来不讨喜
    2020-12-23 14:56

    You can find the documentation for the official public NPM registry API at the following GitHub repository: https://github.com/npm/registry

    The documentation for the search endpoint can be found here: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search

    The following query parameters are accepted: text, size, quality, popularity, maintenance

    curl -sL 'https://registry.npmjs.org/-/v1/search?text=react-native&size=5' | jq
    

    Here we're using curl to make the API request, and jq to format the JSON response. The following output is returned:

    {
      "objects": [
        {
          "package": {
            "name": "react-native",
            "scope": "unscoped",
            "version": "0.62.2",
            "description": "A framework for building native apps using React",
            "date": "2020-04-08T17:08:19.985Z",
            "links": {
              "npm": "https://www.npmjs.com/package/react-native",
              "homepage": "https://github.com/facebook/react-native#readme",
              "repository": "https://github.com/facebook/react-native",
              "bugs": "https://github.com/facebook/react-native/issues"
            },
            "publisher": {
              "username": "react-native-bot",
              "email": "opensource+react-native-bot@fb.com"
            },
            "maintainers": [
              {
                "username": "cpojer",
                "email": "christoph.pojer@gmail.com"
              },
              {
                "username": "fb",
                "email": "opensource+npm@fb.com"
              },
              {
                "username": "grabbou",
                "email": "grabbou@gmail.com"
              },
              {
                "username": "hectorramos",
                "email": "hector@hectorramos.com"
              },
              {
                "username": "react-native-bot",
                "email": "opensource+react-native-bot@fb.com"
              }
            ]
          },
          "flags": {
            "unstable": true
          },
          "score": {
            "final": 0.4604636166574407,
            "detail": {
              "quality": 0.5886895871400879,
              "popularity": 0.47768592528213616,
              "maintenance": 0.3333333333333333
            }
          },
          "searchScore": 100000.47
        },
        {
          "package": {
            "name": "react-native-svg",
            "scope": "unscoped",
            "version": "12.1.0",
            "description": "SVG library for react-native",
            "keywords": [
              "react-component",
              "react-native",
              "ios",
              "android",
              "SVG",
              "ART",
              "VML",
              "gradient"
            ],
            "date": "2020-04-09T23:50:28.358Z",
            "links": {
              "npm": "https://www.npmjs.com/package/react-native-svg",
              "homepage": "https://github.com/react-native-community/react-native-svg",
              "repository": "https://github.com/react-native-community/react-native-svg",
              "bugs": "https://github.com/react-native-community/react-native-svg/issues"
            },
            "publisher": {
              "username": "msand",
              "email": "msand@abo.fi"
            },
            "maintainers": [
              {
                "username": "brentvatne",
                "email": "brentvatne@gmail.com"
              },
              {
                "username": "dustin.savery",
                "email": "dustin.savery@gmail.com"
              },
              {
                "username": "magicismight",
                "email": "master@horcrux.cn"
              },
              {
                "username": "msand",
                "email": "msand@abo.fi"
              }
            ]
          },
          "score": {
            "final": 0.5244501419238121,
            "detail": {
              "quality": 0.9582364654638059,
              "popularity": 0.34375010176572474,
              "maintenance": 0.3333333333333333
            }
          },
          "searchScore": 0.031369504
        },
        {
          "package": {
            "name": "react-native-device-info",
            "scope": "unscoped",
            "version": "5.6.1",
            "description": "Get device information using react-native",
            "keywords": [
              "react-component",
              "react-native",
              "ios",
              "android",
              "windows",
              "device",
              "events",
              "cocoapod"
            ],
            "date": "2020-05-27T18:33:11.715Z",
            "links": {
              "npm": "https://www.npmjs.com/package/react-native-device-info",
              "homepage": "https://github.com/react-native-community/react-native-device-info#readme",
              "repository": "https://github.com/react-native-community/react-native-device-info",
              "bugs": "https://github.com/react-native-community/react-native-device-info/issues"
            },
            "author": {
              "name": "Rebecca Hughes",
              "email": "rebecca@learnium.net",
              "url": "https://github.com/rebeccahughes"
            },
            "publisher": {
              "username": "mikehardy",
              "email": "npmjs@mikehardy.net"
            },
            "maintainers": [
              {
                "username": "gantman",
                "email": "gantman+npm@gmail.com"
              },
              {
                "username": "jeroenbourgois",
                "email": "info@jeroenbourgois.be"
              },
              {
                "username": "lilach",
                "email": "i.am.red@gmail.com"
              },
              {
                "username": "machour",
                "email": "machour@gmail.com"
              },
              {
                "username": "rebeccahughes",
                "email": "rebeccahughes1@outlook.com"
              }
            ]
          },
          "score": {
            "final": 0.5102794746987024,
            "detail": {
              "quality": 0.9614895473985808,
              "popularity": 0.3004741251784613,
              "maintenance": 0.3333333333333333
            }
          },
          "searchScore": 0.016712856
        },
        {
          "package": {
            "name": "css-to-react-native",
            "scope": "unscoped",
            "version": "3.0.0",
            "description": "Convert CSS text to a React Native stylesheet object",
            "keywords": [
              "styled-components",
              "React",
              "ReactNative",
              "styles",
              "CSS"
            ],
            "date": "2019-10-10T17:46:00.297Z",
            "links": {
              "npm": "https://www.npmjs.com/package/css-to-react-native",
              "homepage": "https://github.com/styled-components/css-to-react-native#readme",
              "repository": "https://github.com/styled-components/css-to-react-native",
              "bugs": "https://github.com/styled-components/css-to-react-native/issues"
            },
            "author": {
              "name": "Jacob Parker"
            },
            "publisher": {
              "username": "jacobp100",
              "email": "jacobparker1992@gmail.com"
            },
            "maintainers": [
              {
                "username": "jacobp100",
                "email": "jacobparker1992@gmail.com"
              },
              {
                "username": "kristerkari",
                "email": "krister@sent.at"
              },
              {
                "username": "mxstbr",
                "email": "npm@mxstbr.com"
              }
            ]
          },
          "score": {
            "final": 0.4836548888489432,
            "detail": {
              "quality": 0.8524860977159072,
              "popularity": 0.39264581380833835,
              "maintenance": 0.25852292771786467
            }
          },
          "searchScore": 0.013077582
        },
        {
          "package": {
            "name": "react-native-elements",
            "scope": "unscoped",
            "version": "2.0.4",
            "description": "React Native Elements & UI Toolkit",
            "keywords": [
              "react-native",
              "reactjs",
              "reactnative",
              "bootstrap"
            ],
            "date": "2020-06-30T02:30:34.882Z",
            "links": {
              "npm": "https://www.npmjs.com/package/react-native-elements",
              "homepage": "https://react-native-elements.github.io/react-native-elements/",
              "repository": "https://github.com/react-native-elements/react-native-elements",
              "bugs": "https://github.com/react-native-elements/react-native-elements/issues"
            },
            "author": {
              "name": "Nader Dabit & Monte Thakkar"
            },
            "publisher": {
              "username": "flyingcircle",
              "email": "jeremyelijah@live.com"
            },
            "maintainers": [
              {
                "username": "dabit3",
                "email": "dabit3@gmail.com"
              },
              {
                "username": "iroachie",
                "email": "kroach.work@gmail.com"
              },
              {
                "username": "monte9",
                "email": "mthakkar@mail.sfsu.edu"
              }
            ]
          },
          "score": {
            "final": 0.4921277780507845,
            "detail": {
              "quality": 0.9218028296308819,
              "popularity": 0.28262932141386665,
              "maintenance": 0.3333333333333333
            }
          },
          "searchScore": 0.011005878
        }
      ],
      "total": 26290,
      "time": "Wed Jul 08 2020 05:02:14 GMT+0000 (UTC)"
    }
    

提交回复
热议问题