@@ -16,18 +16,27 @@ import { isNonEmptyString } from './strings.js'
1616// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
1717const encodeComponent = globalThis . encodeURIComponent
1818
19+ /**
20+ * Encode package name component for URL.
21+ */
1922function encodeName ( name : unknown ) : string {
2023 return isNonEmptyString ( name )
2124 ? encodeComponent ( name ) . replaceAll ( '%3A' , ':' )
2225 : ''
2326}
2427
28+ /**
29+ * Encode package namespace component for URL.
30+ */
2531function encodeNamespace ( namespace : unknown ) : string {
2632 return isNonEmptyString ( namespace )
2733 ? encodeComponent ( namespace ) . replaceAll ( '%3A' , ':' ) . replaceAll ( '%2F' , '/' )
2834 : ''
2935}
3036
37+ /**
38+ * Encode qualifier parameter key or value.
39+ */
3140function encodeQualifierParam ( param : unknown ) : string {
3241 if ( isNonEmptyString ( param ) ) {
3342 // Replace spaces with %20's so they don't get converted to plus signs.
@@ -47,6 +56,9 @@ function encodeQualifierParam(param: unknown): string {
4756 return ''
4857}
4958
59+ /**
60+ * Encode qualifiers object as URL query string.
61+ */
5062function encodeQualifiers ( qualifiers : unknown ) : string {
5163 if ( isObject ( qualifiers ) ) {
5264 // Sort this list of qualifier strings lexicographically.
@@ -70,12 +82,18 @@ function encodeQualifiers(qualifiers: unknown): string {
7082 return ''
7183}
7284
85+ /**
86+ * Encode subpath component for URL.
87+ */
7388function encodeSubpath ( subpath : unknown ) : string {
7489 return isNonEmptyString ( subpath )
7590 ? encodeComponent ( subpath ) . replaceAll ( '%2F' , '/' )
7691 : ''
7792}
7893
94+ /**
95+ * Encode package version component for URL.
96+ */
7997function encodeVersion ( version : unknown ) : string {
8098 return isNonEmptyString ( version )
8199 ? encodeComponent ( version ) . replaceAll ( '%3A' , ':' )
0 commit comments