Skip to content

Commit 7fcfeff

Browse files
committed
docs(semver): add comprehensive JSDoc to validateParsedVersion function
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 6394660 commit 7fcfeff

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/semver.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,30 @@ export function parseVersion(version) {
3838
/**
3939
* Validates that a value is a valid ParsedVersion object.
4040
*
41-
* @param {unknown} value - The value to validate
42-
* @param {string} paramName - The parameter name for error messages
43-
* @throws {TypeError} If value is not a valid ParsedVersion object
41+
* This internal helper ensures that values passed to version comparison functions
42+
* conform to the expected ParsedVersion structure with numeric major, minor, and
43+
* patch properties. It provides descriptive error messages when validation fails.
44+
*
45+
* @param {unknown} value - The value to validate as a ParsedVersion object
46+
* @param {string} paramName - The parameter name used in error messages for context
47+
* @returns {void} Returns nothing if validation passes
48+
* @throws {TypeError} If value is null or undefined
49+
* @throws {TypeError} If value is not an object
50+
* @throws {TypeError} If value lacks numeric major, minor, or patch properties
51+
*
52+
* @example
53+
* // Valid ParsedVersion - passes silently
54+
* validateParsedVersion({ major: 1, minor: 2, patch: 3 }, "version")
55+
*
56+
* @example
57+
* // Null value - throws TypeError
58+
* validateParsedVersion(null, "a")
59+
* // Throws: "compareVersions: a must be a ParsedVersion object, got null"
60+
*
61+
* @example
62+
* // Missing properties - throws TypeError
63+
* validateParsedVersion({ major: 1 }, "b")
64+
* // Throws: "compareVersions: b must have numeric major, minor, and patch properties"
4465
*/
4566
function validateParsedVersion(value, paramName) {
4667
if (value === null || value === undefined) {

0 commit comments

Comments
 (0)