npq 3.3.0 → 3.4.0
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.
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const BaseMarshall = require('./baseMarshall')
|
|
4
|
+
const { marshallCategories } = require('./constants')
|
|
5
|
+
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const levenshtein = require('fast-levenshtein')
|
|
8
|
+
const topPackagesRawJSON = require(path.join(__dirname, '../../data/top-packages.json'))
|
|
9
|
+
|
|
10
|
+
const MARSHALL_NAME = 'typosquatting'
|
|
11
|
+
|
|
12
|
+
class Marshall extends BaseMarshall {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options)
|
|
15
|
+
this.name = MARSHALL_NAME
|
|
16
|
+
this.categoryId = marshallCategories.PackageHealth.id
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
title() {
|
|
20
|
+
return 'Checking for typosquatting'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
validate(pkg) {
|
|
24
|
+
let levenshteinDistance = null
|
|
25
|
+
let similarPackages = []
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
for (const popularPackageNameInRepository of topPackagesRawJSON) {
|
|
28
|
+
levenshteinDistance = levenshtein.get(pkg.packageName, popularPackageNameInRepository)
|
|
29
|
+
|
|
30
|
+
if (levenshteinDistance < 3) {
|
|
31
|
+
similarPackages.push(popularPackageNameInRepository)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (similarPackages.length > 0) {
|
|
36
|
+
return reject(
|
|
37
|
+
new Error(
|
|
38
|
+
`Package name could be a typosquatting attempt for popular package(s): ${similarPackages.join(
|
|
39
|
+
', '
|
|
40
|
+
)}`
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return resolve([])
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = Marshall
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npq",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "marshall your npm/npm package installs with high quality and class 🎖",
|
|
5
5
|
"bin": {
|
|
6
6
|
"npq": "./bin/npq.js",
|
|
@@ -170,6 +170,7 @@
|
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
172
|
"dependencies": {
|
|
173
|
+
"fast-levenshtein": "^3.0.0",
|
|
173
174
|
"glob": "^10.3.10",
|
|
174
175
|
"inquirer": "^8.2.6",
|
|
175
176
|
"kleur": "^4.1.5",
|