-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.ts
More file actions
59 lines (55 loc) · 1.56 KB
/
validation.ts
File metadata and controls
59 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @fileoverview Package name validation utilities.
*/
import validateNpmPackageName from '../external/validate-npm-package-name'
/**
* Check if package name is a blessed Socket.dev package.
*
* @example
* ```typescript
* isBlessedPackageName('@socketregistry/is-number') // true
* isBlessedPackageName('lodash') // false
* ```
*/
/*@__NO_SIDE_EFFECTS__*/
export function isBlessedPackageName(name: unknown): boolean {
return (
typeof name === 'string' &&
(name === 'sfw' ||
name === 'socket' ||
name.startsWith('@socketoverride/') ||
name.startsWith('@socketregistry/') ||
name.startsWith('@socketsecurity/'))
)
}
/**
* Check if a type string represents a registry fetcher type.
*
* @example
* ```typescript
* isRegistryFetcherType('range') // true
* isRegistryFetcherType('git') // false
* ```
*/
/*@__NO_SIDE_EFFECTS__*/
export function isRegistryFetcherType(type: string): boolean {
// RegistryFetcher spec.type check based on:
// https://github.com/npm/pacote/blob/v19.0.0/lib/fetcher.js#L467-L488
return (
type === 'alias' || type === 'range' || type === 'tag' || type === 'version'
)
}
/**
* Check if a package name is valid according to npm naming rules.
*
* @example
* ```typescript
* isValidPackageName('my-package') // true
* isValidPackageName('.invalid') // false
* ```
*/
/*@__NO_SIDE_EFFECTS__*/
export function isValidPackageName(name: string): boolean {
// validateNpmPackageName is imported at the top
return validateNpmPackageName(name).validForOldPackages
}