Skip to content

Commit 327709f

Browse files
committed
Add JSDoc documentation to helper functions
1 parent 52c301f commit 327709f

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

src/decode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { PurlError } from './error.js'
1010
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
1111
const decodeComponent = globalThis.decodeURIComponent
1212

13+
/**
14+
* Decode PURL component value from URL encoding.
15+
* @throws {PurlError} When component cannot be decoded.
16+
*/
1317
function decodePurlComponent(comp: string, encodedComponent: string): string {
1418
try {
1519
return decodeComponent(encodedComponent)

src/encode.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,27 @@ import { isNonEmptyString } from './strings.js'
1616
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
1717
const encodeComponent = globalThis.encodeURIComponent
1818

19+
/**
20+
* Encode package name component for URL.
21+
*/
1922
function 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+
*/
2531
function 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+
*/
3140
function 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+
*/
5062
function 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+
*/
7388
function 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+
*/
7997
function encodeVersion(version: unknown): string {
8098
return isNonEmptyString(version)
8199
? encodeComponent(version).replaceAll('%3A', ':')

src/error.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Provides consistent error message formatting for PURL-related exceptions.
44
*/
55

6+
/**
7+
* Format error message for PURL exceptions.
8+
*/
69
function formatPurlErrorMessage(message = ''): string {
710
const { length } = message
811
let formatted = ''

src/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Organizes helper functions by property names with configurable defaults and sorting.
44
*/
55

6+
/**
7+
* Create namespace object organizing helpers by property names.
8+
*/
69
function createHelpersNamespaceObject(
710
helpers: Record<string, Record<string, unknown>>,
811
options_: Record<string, unknown> = {},

src/lang.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Provides type checking predicates for common value validation scenarios.
44
*/
55

6+
/**
7+
* Check if a value is null, undefined, or an empty string.
8+
*/
69
function isNullishOrEmptyString(value: unknown): boolean {
710
return (
811
value === null ||

0 commit comments

Comments
 (0)