libnpmfund 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,11 +15,13 @@ function normalizeFunding (funding) {
15
15
  // Is the value of a `funding` property of a `package.json`
16
16
  // a valid type+url for `npm fund` to display?
17
17
  function isValidFunding (funding) {
18
- if (!funding)
18
+ if (!funding) {
19
19
  return false
20
+ }
20
21
 
21
- if (Array.isArray(funding))
22
+ if (Array.isArray(funding)) {
22
23
  return funding.every(f => !Array.isArray(f) && isValidFunding(f))
24
+ }
23
25
 
24
26
  try {
25
27
  var parsed = new URL(funding.url || funding)
@@ -30,8 +32,9 @@ function isValidFunding (funding) {
30
32
  if (
31
33
  parsed.protocol !== 'https:' &&
32
34
  parsed.protocol !== 'http:'
33
- )
35
+ ) {
34
36
  return false
37
+ }
35
38
 
36
39
  return Boolean(parsed.host)
37
40
  }
@@ -53,8 +56,9 @@ function readTree (tree, opts) {
53
56
 
54
57
  function tracked (name, version) {
55
58
  const key = String(name) + String(version)
56
- if (seen.has(key))
59
+ if (seen.has(key)) {
57
60
  return true
61
+ }
58
62
 
59
63
  seen.add(key)
60
64
  }
@@ -89,30 +93,36 @@ function readTree (tree, opts) {
89
93
 
90
94
  function getFundingDependencies (tree) {
91
95
  const edges = tree && tree.edgesOut && tree.edgesOut.values()
92
- if (!edges)
96
+ if (!edges) {
93
97
  return empty()
98
+ }
94
99
 
95
100
  const directDepsWithFunding = Array.from(edges).map(edge => {
96
- if (!edge || !edge.to)
101
+ if (!edge || !edge.to) {
97
102
  return empty()
103
+ }
98
104
 
99
105
  const node = edge.to.target || edge.to
100
- if (!node.package)
106
+ if (!node.package) {
101
107
  return empty()
108
+ }
102
109
 
103
- if (filterSet && filterSet.size > 0 && !filterSet.has(node))
110
+ if (filterSet && filterSet.size > 0 && !filterSet.has(node)) {
104
111
  return empty()
112
+ }
105
113
 
106
114
  const { name, funding, version } = node.package
107
115
 
108
116
  // avoids duplicated items within the funding tree
109
- if (tracked(name, version))
117
+ if (tracked(name, version)) {
110
118
  return empty()
119
+ }
111
120
 
112
121
  const fundingItem = {}
113
122
 
114
- if (version)
123
+ if (version) {
115
124
  fundingItem.version = version
125
+ }
116
126
 
117
127
  attachFundingInfo(fundingItem, funding)
118
128
 
@@ -126,8 +136,9 @@ function readTree (tree, opts) {
126
136
  (res, { node, fundingItem }, i) => {
127
137
  if (!fundingItem ||
128
138
  fundingItem.length === 0 ||
129
- !node)
139
+ !node) {
130
140
  return res
141
+ }
131
142
 
132
143
  // recurse
133
144
  const transitiveDependencies = node.edgesOut &&
@@ -136,17 +147,18 @@ function readTree (tree, opts) {
136
147
 
137
148
  // if we're only counting items there's no need
138
149
  // to add all the data to the resulting object
139
- if (countOnly)
150
+ if (countOnly) {
140
151
  return null
152
+ }
141
153
 
142
154
  if (hasDependencies(transitiveDependencies)) {
143
155
  fundingItem.dependencies =
144
156
  retrieveDependencies(transitiveDependencies)
145
157
  }
146
158
 
147
- if (isValidFunding(fundingItem.funding))
159
+ if (isValidFunding(fundingItem.funding)) {
148
160
  res[node.package.name] = fundingItem
149
- else if (hasDependencies(fundingItem.dependencies)) {
161
+ } else if (hasDependencies(fundingItem.dependencies)) {
150
162
  res[_trailingDependencies] =
151
163
  Object.assign(
152
164
  empty(),
@@ -170,11 +182,13 @@ function readTree (tree, opts) {
170
182
  (tree && tree.name)
171
183
  result.name = name || (tree && tree.path)
172
184
 
173
- if (tree && tree.package && tree.package.version)
185
+ if (tree && tree.package && tree.package.version) {
174
186
  result.version = tree.package.version
187
+ }
175
188
 
176
- if (tree && tree.package && tree.package.funding)
189
+ if (tree && tree.package && tree.package.funding) {
177
190
  result.funding = normalizeFunding(tree.package.funding)
191
+ }
178
192
 
179
193
  result.dependencies = retrieveDependencies(treeDependencies)
180
194
  }
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "libnpmfund",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
+ "main": "lib/index.js",
4
5
  "files": [
5
- "index.js"
6
+ "bin",
7
+ "lib"
6
8
  ],
7
9
  "description": "Programmatic API for npm fund",
8
10
  "repository": "https://github.com/npm/libnpmfund",
@@ -15,7 +17,7 @@
15
17
  "fund",
16
18
  "gitfund"
17
19
  ],
18
- "author": "npm Inc. <support@npmjs.com>",
20
+ "author": "GitHub Inc.",
19
21
  "contributors": [
20
22
  {
21
23
  "name": "Ruy Adorno",
@@ -26,29 +28,20 @@
26
28
  "license": "ISC",
27
29
  "scripts": {
28
30
  "eslint": "eslint",
29
- "lint": "npm run eslint -- index.js test.js",
31
+ "lint": "eslint '**/*.js'",
30
32
  "lintfix": "npm run lint -- --fix",
31
33
  "posttest": "npm run lint",
32
34
  "test": "tap",
33
35
  "snap": "tap",
34
36
  "preversion": "npm test",
35
37
  "postversion": "npm publish",
36
- "prepublishOnly": "git push origin --follow-tags"
38
+ "prepublishOnly": "git push origin --follow-tags",
39
+ "postlint": "npm-template-check"
37
40
  },
38
41
  "tap": {
39
42
  "check-coverage": true
40
43
  },
41
- "standard": {
42
- "ignore": [
43
- "/tap-snapshots/"
44
- ]
45
- },
46
44
  "devDependencies": {
47
- "eslint": "^7.26.0",
48
- "eslint-plugin-import": "^2.22.1",
49
- "eslint-plugin-node": "^11.1.0",
50
- "eslint-plugin-promise": "^5.1.0",
51
- "eslint-plugin-standard": "^5.0.0",
52
45
  "tap": "^15.0.9"
53
46
  },
54
47
  "dependencies": {
@@ -56,5 +49,8 @@
56
49
  },
57
50
  "engines": {
58
51
  "node": "^12.13.0 || ^14.15.0 || >=16"
52
+ },
53
+ "templateOSS": {
54
+ "version": "2.4.1"
59
55
  }
60
56
  }