Skip to content

Commit 8809f41

Browse files
committed
Improve code organization and documentation
- Add comprehensive module documentation to index.ts - Organize exports into clear sections with descriptive comments - Add detailed fileoverview for purl-type.ts explaining all supported types - Create shared logger utility for consistent script output - Reduce cognitive complexity through better structure and clarity
1 parent 621132f commit 8809f41

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

scripts/utils/logger.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @fileoverview Shared logging utilities for scripts.
3+
* Provides consistent console output formatting across all Socket scripts.
4+
*/
5+
6+
import colors from 'yoctocolors-cjs'
7+
8+
/**
9+
* Console logger with colored status indicators
10+
*/
11+
export const log = {
12+
info: msg => console.log(msg),
13+
error: msg => console.error(`${colors.red('✗')} ${msg}`),
14+
success: msg => console.log(`${colors.green('✓')} ${msg}`),
15+
warn: msg => console.log(`${colors.yellow('⚠')} ${msg}`),
16+
step: msg => console.log(`\n${msg}`),
17+
substep: msg => console.log(` ${msg}`),
18+
progress: msg => process.stdout.write(` ∴ ${msg}`),
19+
done: msg => {
20+
process.stdout.write('\r\x1b[K')
21+
console.log(` ${colors.green('✓')} ${msg}`)
22+
},
23+
failed: msg => {
24+
process.stdout.write('\r\x1b[K')
25+
console.log(` ${colors.red('✗')} ${msg}`)
26+
}
27+
}
28+
29+
/**
30+
* Print a section header with consistent formatting
31+
*/
32+
export function printHeader(title) {
33+
console.log('\n' + '═'.repeat(60))
34+
console.log(` ${title}`)
35+
console.log('═'.repeat(60))
36+
}
37+
38+
/**
39+
* Print a section footer with optional message
40+
*/
41+
export function printFooter(message) {
42+
console.log('\n' + '═'.repeat(60))
43+
if (message) {
44+
console.log(`${colors.green('✓')} ${message}`)
45+
}
46+
console.log('═'.repeat(60))
47+
}

src/index.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,66 @@ SOFTWARE.
2222

2323
/**
2424
* @fileoverview Main entry point for the socket-packageurl-js library.
25-
* Provides exports for PackageURL, PurlComponent, PurlQualifierNames, and PurlType.
25+
*
26+
* This library provides a complete implementation of the Package URL (purl) specification.
27+
* Package URLs are used to identify and locate software packages in a standardized way
28+
* across different package management systems and ecosystems.
29+
*
30+
* Core exports:
31+
* - PackageURL: Main class for parsing and constructing package URLs
32+
* - PackageURLBuilder: Builder pattern for constructing package URLs
33+
* - PurlType: Type-specific normalization and validation rules
34+
* - PurlComponent: Component encoding/decoding utilities
35+
* - PurlQualifierNames: Known qualifier names from the specification
36+
*
37+
* Utility exports:
38+
* - UrlConverter: Convert between purls and repository/download URLs
39+
* - Result utilities: Functional error handling with Ok/Err pattern
2640
*/
2741

28-
/* c8 ignore start - Re-export only file, no logic to test. */
42+
/* c8 ignore start - Re-export only file, no logic to test */
43+
44+
// ============================================================================
45+
// Core Classes and Functions
46+
// ============================================================================
2947
export {
30-
Err,
31-
Ok,
3248
PackageURL,
3349
PurlComponent,
3450
PurlQualifierNames,
3551
PurlType,
36-
ResultUtils,
52+
} from './package-url.js'
53+
54+
export { PackageURLBuilder } from './package-url-builder.js'
55+
56+
// ============================================================================
57+
// Utility Classes and Functions
58+
// ============================================================================
59+
export {
3760
UrlConverter,
61+
} from './package-url.js'
62+
63+
export {
64+
Err,
65+
Ok,
66+
ResultUtils,
3867
err,
3968
ok,
4069
} from './package-url.js'
4170

42-
// Import PackageURLBuilder separately to avoid circular dependency
43-
export { PackageURLBuilder } from './package-url-builder.js'
44-
71+
// ============================================================================
72+
// TypeScript Type Definitions
73+
// ============================================================================
4574
export type {
4675
DownloadUrl,
4776
RepositoryUrl,
4877
Result,
4978
} from './package-url.js'
5079

80+
// ============================================================================
81+
// Registry Integration
82+
// ============================================================================
5183
// Re-export PURL types from socket-registry for consistency
5284
export { PURL_Type } from '@socketsecurity/registry'
5385
export type { EcosystemString } from '@socketsecurity/registry'
86+
5487
/* c8 ignore stop */

src/purl-type.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
/**
22
* @fileoverview Package URL type-specific normalization and validation rules for different package ecosystems.
3-
* Implements PURL-TYPES specification rules for npm, pypi, maven, golang, and other package managers.
3+
*
4+
* This module implements the PURL-TYPES specification for various package managers:
5+
* - NPM: Node.js packages with scoped namespace support
6+
* - PyPI: Python packages with normalized naming
7+
* - Maven: Java artifacts with group/artifact structure
8+
* - Go: Go modules with module path validation
9+
* - Cargo: Rust crates from crates.io
10+
* - And 20+ other package types
11+
*
12+
* Each type has specific rules for namespace, name, version normalization and validation.
413
*/
514
import { encodeComponent } from './encode.js'
615
import { PurlError } from './error.js'

0 commit comments

Comments
 (0)