diff --git a/.verb.md b/.verb.md index 2f1b5ce..1d4283b 100644 --- a/.verb.md +++ b/.verb.md @@ -54,6 +54,35 @@ $ yarn add {%= name %} ## API +_Generated using [docks](http://npm.im/docks)._ + +### [src/index.js](/src/index.js) + +#### [packageJson](/src/index.js#L26) +Get package metadata from the Unpkg instead of NPM registry. +Optionally you can pass `endpoint` function and return the build +the registry url. See the second test in `test/index.js`. + +**Params** +- `packageName` **{string}** the package name, supports `pkg-name@1.2.2` and `pkg-name@next` +- `endpoint` **{function}** like `(name, tag) => url` + +**Returns** +- `object` package metadata object + +**Examples** +```javascript +import packageJson from '@tunnckocore/package-json'; + +async function main() { + console.log(await packageJson('eslint')); + console.log(await packageJson('package-json@4.0.0')); + console.log(await packageJson('ava@next')); +} + +main().catch(console.error); +``` + **[back to top](#thetop)** diff --git a/README.md b/README.md new file mode 100644 index 0000000..687a48e --- /dev/null +++ b/README.md @@ -0,0 +1,216 @@ +# @tunnckocore/package-json [![npm version][npmv-img]][npmv-url] [![github release][ghrelease-img]][ghrelease-url] [![License][license-img]][license-url] + +> Simple and fast getting of latest package.json metadata for a npm module, using axios and unpkg as a source, because npm registry is basically slow + +Please consider following this project's author, [Charlike Mike Reagent](https://github.com/tunnckoCore), and :star: the project to show your :heart: and support. + +
+ +[![Code style][codestyle-img]][codestyle-url] +[![CircleCI linux build][linuxbuild-img]][linuxbuild-url] +[![CodeCov coverage status][codecoverage-img]][codecoverage-url] +[![DavidDM dependency status][dependencies-img]][dependencies-url] +[![Renovate App Status][renovateapp-img]][renovateapp-url] +[![Make A Pull Request][prs-welcome-img]][prs-welcome-url] +[![Semantically Released][new-release-img]][new-release-url] + +If you have any _how-to_ kind of questions, please read the [Contributing Guide](./CONTRIBUTING.md) and [Code of Conduct](./CODE_OF_CONDUCT.md) documents. +For bugs reports and feature requests, [please create an issue][open-issue-url] or ping +[@tunnckoCore](https://twitter.com/tunnckoCore) at Twitter. + +[![Become a Patron][patreon-img]][patreon-url] +[![Conventional Commits][ccommits-img]][ccommits-url] +[![NPM Downloads Weekly][downloads-weekly-img]][npmv-url] +[![NPM Downloads Monthly][downloads-monthly-img]][npmv-url] +[![NPM Downloads Total][downloads-total-img]][npmv-url] +[![Share Love Tweet][shareb]][shareu] + +Project is [semantically](https://semver.org) & automatically released on [CircleCI](https://circleci.com) with [new-release][] and its [New Release](https://github.com/apps/new-release) GitHub App. + + + +## Table of Contents + +- [Install](#install) +- [API](#api) + * [src/index.js](#srcindexjs) + + [packageJson](#packagejson) +- [See Also](#see-also) +- [Contributing](#contributing) + * [Follow the Guidelines](#follow-the-guidelines) + * [Support the project](#support-the-project) + * [OPEN Open Source](#open-open-source) + * [Wonderful Contributors](#wonderful-contributors) +- [License](#license) + +_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ + +## Install + +This project requires [**Node.js**](https://nodejs.org) **^8.11.0 || >=10.13.0**. Install it using +[**yarn**](https://yarnpkg.com) or [**npm**](https://npmjs.com). +_We highly recommend to use Yarn when you think to contribute to this project._ + +```bash +$ yarn add @tunnckocore/package-json +``` + +## API + + +_Generated using [docks](http://npm.im/docks)._ + +### [src/index.js](/src/index.js) + +#### [packageJson](/src/index.js#L26) +Get package metadata from the Unpkg instead of NPM registry. +Optionally you can pass `endpoint` function and return the build +the registry url. See the second test in `test/index.js`. + +**Params** +- `packageName` **{string}** the package name, supports `pkg-name@1.2.2` and `pkg-name@next` +- `endpoint` **{function}** like `(name, tag) => url` + +**Returns** +- `object` package metadata object + +**Examples** +```javascript +import packageJson from '@tunnckocore/package-json'; + +async function main() { + console.log(await packageJson('eslint')); + console.log(await packageJson('package-json@4.0.0')); + console.log(await packageJson('ava@next')); +} + +main().catch(console.error); +``` + + + +**[back to top](#thetop)** + +## See Also + +Some of these projects are used here or were inspiration for this one, others are just related. So, thanks for your +existance! +- [@tunnckocore/config](https://www.npmjs.com/package/@tunnckocore/config): All the configs for all the tools, in one place | [homepage](https://github.com/tunnckoCoreLabs/config "All the configs for all the tools, in one place") +- [@tunnckocore/create-project](https://www.npmjs.com/package/@tunnckocore/create-project): Create and scaffold a new project, its GitHub repository and… [more](https://github.com/tunnckoCoreLabs/create-project) | [homepage](https://github.com/tunnckoCoreLabs/create-project "Create and scaffold a new project, its GitHub repository and contents") +- [@tunnckocore/execa](https://www.npmjs.com/package/@tunnckocore/execa): Thin layer on top of [execa][] that allows executing multiple… [more](https://github.com/tunnckoCoreLabs/execa) | [homepage](https://github.com/tunnckoCoreLabs/execa "Thin layer on top of [execa][] that allows executing multiple commands in parallel or in sequence") +- [@tunnckocore/scripts](https://www.npmjs.com/package/@tunnckocore/scripts): Universal and minimalist scripts & tasks runner. | [homepage](https://github.com/tunnckoCoreLabs/scripts "Universal and minimalist scripts & tasks runner.") +- [@tunnckocore/update](https://www.npmjs.com/package/@tunnckocore/update): Update a repository with latest templates from `charlike`. | [homepage](https://github.com/tunnckoCoreLabs/update "Update a repository with latest templates from `charlike`.") +- [asia](https://www.npmjs.com/package/asia): Blazingly fast, magical and minimalist testing framework, for Today and… [more](https://github.com/olstenlarck/asia#readme) | [homepage](https://github.com/olstenlarck/asia#readme "Blazingly fast, magical and minimalist testing framework, for Today and Tomorrow") +- [charlike](https://www.npmjs.com/package/charlike): Small & fast project scaffolder with sane defaults. Supports hundreds… [more](https://github.com/tunnckoCoreLabs/charlike) | [homepage](https://github.com/tunnckoCoreLabs/charlike "Small & fast project scaffolder with sane defaults. Supports hundreds of template engines through the @JSTransformers API or if you want custom `render` function passed through options") +- [docks](https://www.npmjs.com/package/docks): Extensible system for parsing and generating documentation. It just freaking… [more](https://github.com/tunnckoCore/docks) | [homepage](https://github.com/tunnckoCore/docks "Extensible system for parsing and generating documentation. It just freaking works!") +- [gitcommit](https://www.npmjs.com/package/gitcommit): Lightweight and joyful `git commit` replacement. Conventional Commits compliant. | [homepage](https://github.com/tunnckoCore/gitcommit "Lightweight and joyful `git commit` replacement. Conventional Commits compliant.") + +**[back to top](#thetop)** + +## Contributing + +### Follow the Guidelines + +Please read the [Contributing Guide](./CONTRIBUTING.md) and [Code of Conduct](./CODE_OF_CONDUCT.md) documents for advices. +For bugs reports and feature requests, [please create an issue][open-issue-url] or ping +[@tunnckoCore](https://twitter.com/tunnckoCore) at Twitter. + +### Support the project + +[Become a Partner or Sponsor?][patreon-url] :dollar: Check the **Partner**, **Sponsor** or **Omega-level** tiers! :tada: You can get your company logo, link & name on this file. It's also rendered on package page in [npmjs.com][npmv-url] and [yarnpkg.com](https://yarnpkg.com/en/package/@tunnckocore/package-json) sites too! :rocket: + +Not financial support? Okey! [Pull requests](https://github.com/tunnckoCoreLabs/contributing#opening-a-pull-request), stars and all kind of [contributions](https://opensource.guide/how-to-contribute/#what-it-means-to-contribute) are always +welcome. :sparkles: + +### OPEN Open Source + +This project is following [OPEN Open Source](http://openopensource.org) model + +> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is built on collective efforts and it's not strongly guarded by its founders. + +There are a few basic ground-rules for its contributors + +1. Any **significant modifications** must be subject to a pull request to get feedback from other contributors. +2. [Pull requests](https://github.com/tunnckoCoreLabs/contributing#opening-a-pull-request) to get feedback are _encouraged_ for any other trivial contributions, but are not required. +3. Contributors should attempt to adhere to the prevailing code-style and development workflow. + +### Wonderful Contributors + +Thanks to the hard work of these wonderful people this project is alive! It follows the +[all-contributors](https://github.com/kentcdodds/all-contributors) specification. +Don't hesitate to add yourself to that list if you have made any contribution! ;) [See how, +here](https://github.com/jfmengels/all-contributors-cli#usage). + + + +| [
Charlike Mike Reagent](https://tunnckocore.com)
[💻](https://github.com/tunnckoCoreLabs/package-json/commits?author=tunnckoCore "Code") [📖](https://github.com/tunnckoCoreLabs/package-json/commits?author=tunnckoCore "Documentation") [💬](#question-tunnckoCore "Answering Questions") [👀](#review-tunnckoCore "Reviewed Pull Requests") [🔍](#fundingFinding-tunnckoCore "Funding Finding") | +| :---: | + + + +Consider showing your [support](#support-the-project) to them. :sparkling_heart: + +## License + +Copyright (c) 2018-present, [Charlike Mike Reagent](https://tunnckocore.com) `` & [contributors](#wonderful-contributors). +Released under the [Apache-2.0 License][license-url]. + + + +[npmv-url]: https://www.npmjs.com/package/@tunnckocore/package-json +[npmv-img]: https://badgen.net/npm/v/@tunnckocore/package-json?icon=npm + +[ghrelease-url]: https://github.com/tunnckoCoreLabs/package-json/releases/latest +[ghrelease-img]: https://badgen.net/github/release/tunnckoCoreLabs/package-json?icon=github + +[license-url]: https://github.com/tunnckoCoreLabs/package-json/blob/master/LICENSE +[license-img]: https://badgen.net/npm/license/@tunnckocore/package-json + + + +[codestyle-url]: https://github.com/airbnb/javascript +[codestyle-img]: https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb + +[linuxbuild-url]: https://circleci.com/gh/tunnckoCoreLabs/package-json/tree/master +[linuxbuild-img]: https://badgen.net/circleci/github/tunnckoCoreLabs/package-json/master?label=build&icon=circleci + +[codecoverage-url]: https://codecov.io/gh/tunnckoCoreLabs/package-json +[codecoverage-img]: https://badgen.net/codecov/c/github/tunnckoCoreLabs/package-json?icon=codecov + +[dependencies-url]: https://david-dm.org/tunnckoCoreLabs/package-json +[dependencies-img]: https://badgen.net/david/dep/tunnckoCoreLabs/package-json?label=deps + +[ccommits-url]: https://conventionalcommits.org/ +[ccommits-img]: https://badgen.net/badge/conventional%20commits/v1.0.0/dfb317 +[new-release-url]: https://ghub.io/new-release +[new-release-img]: https://badgen.net/badge/semantically/released/05c5ff + +[downloads-weekly-img]: https://badgen.net/npm/dw/@tunnckocore/package-json +[downloads-monthly-img]: https://badgen.net/npm/dm/@tunnckocore/package-json +[downloads-total-img]: https://badgen.net/npm/dt/@tunnckocore/package-json + +[renovateapp-url]: https://renovatebot.com +[renovateapp-img]: https://badgen.net/badge/renovate/enabled/green +[prs-welcome-img]: https://badgen.net/badge/PRs/welcome/green +[prs-welcome-url]: http://makeapullrequest.com +[paypal-donate-url]: https://paypal.me/tunnckoCore/10 +[paypal-donate-img]: https://badgen.net/badge/$/support/purple +[patreon-url]: https://www.patreon.com/bePatron?u=5579781 +[patreon-img]: https://badgen.net/badge/patreon/tunnckoCore/F96854?icon=patreon +[patreon-sponsor-img]: https://badgen.net/badge/become/a%20sponsor/F96854?icon=patreon + +[shareu]: https://twitter.com/intent/tweet?text=https://github.com/tunnckoCoreLabs/package-json&via=tunnckoCore +[shareb]: https://badgen.net/badge/twitter/share/1da1f2?icon=twitter +[open-issue-url]: https://github.com/tunnckoCoreLabs/package-json/issues/new + +[execa]: https://github.com/sindresorhus/execa +[new-release]: https://github.com/tunnckoCore/new-release +[semantic-release]: https://github.com/semantic-release/semantic-release \ No newline at end of file diff --git a/src/index.js b/src/index.js index ad958ea..a30dd6f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,28 @@ import parse from 'parse-package-name'; import axios from 'axios'; -// packageName: String, endpoint: (name: String, tag: String = 'latest'): String => {} +/** + * Get package metadata from the Unpkg instead of NPM registry. + * Optionally you can pass `endpoint` function and return the build + * the registry url. See the second test in `test/index.js`. + * + * @example + * import packageJson from '@tunnckocore/package-json'; + * + * async function main() { + * console.log(await packageJson('eslint')); + * console.log(await packageJson('package-json@4.0.0')); + * console.log(await packageJson('ava@next')); + * } + * + * main().catch(console.error); + * + * @name packageJson + * @param {string} packageName the package name, supports `pkg-name@1.2.2` and `pkg-name@next` + * @param {function} endpoint like `(name, tag) => url` + * @returns {object} package metadata object + * @public + */ export default async function packageJson(packageName, endpoint) { const { name, version } = parse(packageName); const tag = version === '' ? 'latest' : version;