11cb0ef41Sopenharmony_ci# libnpmfund
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci[![npm version](https://img.shields.io/npm/v/libnpmfund.svg)](https://npm.im/libnpmfund)
41cb0ef41Sopenharmony_ci[![license](https://img.shields.io/npm/l/libnpmfund.svg)](https://npm.im/libnpmfund)
51cb0ef41Sopenharmony_ci[![CI - libnpmfund](https://github.com/npm/cli/actions/workflows/ci-libnpmfund.yml/badge.svg)](https://github.com/npm/cli/actions/workflows/ci-libnpmfund.yml)
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci[`libnpmfund`](https://github.com/npm/libnpmfund) is a Node.js library for
81cb0ef41Sopenharmony_ciretrieving **funding** information for packages installed using
91cb0ef41Sopenharmony_ci[`arborist`](https://github.com/npm/arborist).
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci## Table of Contents
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci* [Example](#example)
141cb0ef41Sopenharmony_ci* [Install](#install)
151cb0ef41Sopenharmony_ci* [Contributing](#contributing)
161cb0ef41Sopenharmony_ci* [API](#api)
171cb0ef41Sopenharmony_ci* [LICENSE](#license)
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci## Example
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci```js
221cb0ef41Sopenharmony_ciconst { read } = require('libnpmfund')
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciconst fundingInfo = await read()
251cb0ef41Sopenharmony_ciconsole.log(
261cb0ef41Sopenharmony_ci  JSON.stringify(fundingInfo, null, 2)
271cb0ef41Sopenharmony_ci)
281cb0ef41Sopenharmony_ci// => {
291cb0ef41Sopenharmony_ci  length: 2,
301cb0ef41Sopenharmony_ci  name: 'foo',
311cb0ef41Sopenharmony_ci  version: '1.0.0',
321cb0ef41Sopenharmony_ci  funding: { url: 'https://example.com' },
331cb0ef41Sopenharmony_ci  dependencies: {
341cb0ef41Sopenharmony_ci    bar: {
351cb0ef41Sopenharmony_ci      version: '1.0.0',
361cb0ef41Sopenharmony_ci      funding: { url: 'http://collective.example.com' }
371cb0ef41Sopenharmony_ci    }
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci```
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci## Install
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci`$ npm install libnpmfund`
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci### Contributing
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciThe npm team enthusiastically welcomes contributions and project participation!
491cb0ef41Sopenharmony_ciThere's a bunch of things you can do if you want to contribute! The
501cb0ef41Sopenharmony_ci[Contributor Guide](https://github.com/npm/cli/blob/latest/CONTRIBUTING.md)
511cb0ef41Sopenharmony_cioutlines the process for community interaction and contribution. Please don't
521cb0ef41Sopenharmony_cihesitate to jump in if you'd like to, or even ask us questions if something
531cb0ef41Sopenharmony_ciisn't clear.
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciAll participants and maintainers in this project are expected to follow the
561cb0ef41Sopenharmony_ci[npm Code of Conduct](https://www.npmjs.com/policies/conduct), and just
571cb0ef41Sopenharmony_cigenerally be excellent to each other.
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ciPlease refer to the [Changelog](CHANGELOG.md) for project history details, too.
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ciHappy hacking!
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci### API
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci##### <a name="fund.read"></a> `> fund.read([opts]) -> Promise<Object>`
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciReads **funding** info from a npm install and returns a promise for a
681cb0ef41Sopenharmony_citree object that only contains packages in which funding info is defined.
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ciOptions:
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci- `countOnly`: Uses the tree-traversal logic from **npm fund** but skips over
731cb0ef41Sopenharmony_ciany obj definition and just returns an obj containing `{ length }` - useful for
741cb0ef41Sopenharmony_cithings such as printing a `6 packages are looking for funding` msg.
751cb0ef41Sopenharmony_ci- `workspaces`: `Array<String>` List of workspaces names to filter for,
761cb0ef41Sopenharmony_cithe result will only include a subset of the resulting tree that includes
771cb0ef41Sopenharmony_cionly the nodes that are children of the listed workspaces names.
781cb0ef41Sopenharmony_ci- `path`, `registry` and more [Arborist](https://github.com/npm/arborist/) options.
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci##### <a name="fund.readTree"></a> `> fund.readTree(tree, [opts]) -> Promise<Object>`
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ciReads **funding** info from a given install tree and returns a tree object
831cb0ef41Sopenharmony_cithat only contains packages in which funding info is defined.
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci- `tree`: An [`arborist`](https://github.com/npm/arborist) tree to be used, e.g:
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci```js
881cb0ef41Sopenharmony_ciconst Arborist = require('@npmcli/arborist')
891cb0ef41Sopenharmony_ciconst { readTree } = require('libnpmfund')
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ciconst arb = new Arborist({ path: process.cwd() })
921cb0ef41Sopenharmony_ciconst tree = await arb.loadActual()
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_cireturn readTree(tree, { countOnly: false })
951cb0ef41Sopenharmony_ci```
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciOptions:
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci- `countOnly`: Uses the tree-traversal logic from **npm fund** but skips over
1001cb0ef41Sopenharmony_ciany obj definition and just returns an obj containing `{ length }` - useful for
1011cb0ef41Sopenharmony_cithings such as printing a `6 packages are looking for funding` msg.
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci##### <a name="fund.normalizeFunding"></a> `> fund.normalizeFunding(funding) -> Object`
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ciFrom a `funding` `<object|string|array>`, retrieves normalized funding objects
1061cb0ef41Sopenharmony_cicontaining a `url` property.
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_cie.g:
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci```js
1111cb0ef41Sopenharmony_cinormalizeFunding('http://example.com')
1121cb0ef41Sopenharmony_ci// => {
1131cb0ef41Sopenharmony_ci  url: 'http://example.com'
1141cb0ef41Sopenharmony_ci}
1151cb0ef41Sopenharmony_ci```
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci##### <a name="fund.isValidFunding"></a> `> fund.isValidFunding(funding) -> Boolean`
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ciReturns `<true>` if `funding` is a valid funding object, e.g:
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci```js
1221cb0ef41Sopenharmony_ciisValidFunding({ foo: 'not a valid funding obj' })
1231cb0ef41Sopenharmony_ci// => false
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ciisValidFunding('http://example.com')
1261cb0ef41Sopenharmony_ci// => true
1271cb0ef41Sopenharmony_ci```
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci## LICENSE
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci[ISC](./LICENSE)
132