Skip to content

Commit ca9ecc5

Browse files
committed
Update validation call sites to use options pattern
- Change validation calls from boolean params to { throws } options - Update validateRequiredByType and validateEmptyByType calls in type validators
1 parent 5c7dbcb commit ca9ecc5

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/purl-type.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ const PurlType = createHelpersNamespaceObject(
329329
},
330330
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#cran
331331
cran(purl: PurlObject, throws: boolean) {
332-
return validateRequiredByType('cran', 'version', purl.version, throws)
332+
return validateRequiredByType('cran', 'version', purl.version, {
333+
throws,
334+
})
333335
},
334336
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#golang
335337
golang(purl: PurlObject, throws: boolean) {
@@ -356,21 +358,15 @@ const PurlType = createHelpersNamespaceObject(
356358
},
357359
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#maven
358360
maven(purl: PurlObject, throws: boolean) {
359-
return validateRequiredByType(
360-
'maven',
361-
'namespace',
362-
purl.namespace,
361+
return validateRequiredByType('maven', 'namespace', purl.namespace, {
363362
throws,
364-
)
363+
})
365364
},
366365
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#mlflow
367366
mlflow(purl: PurlObject, throws: boolean) {
368-
return validateEmptyByType(
369-
'mlflow',
370-
'namespace',
371-
purl.namespace,
367+
return validateEmptyByType('mlflow', 'namespace', purl.namespace, {
372368
throws,
373-
)
369+
})
374370
},
375371
// Validation based on
376372
// https://github.com/npm/validate-npm-package-name/tree/v6.0.0
@@ -498,7 +494,9 @@ const PurlType = createHelpersNamespaceObject(
498494
},
499495
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#oci
500496
oci(purl: PurlObject, throws: boolean) {
501-
return validateEmptyByType('oci', 'namespace', purl.namespace, throws)
497+
return validateEmptyByType('oci', 'namespace', purl.namespace, {
498+
throws,
499+
})
502500
},
503501
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#pub
504502
pub(purl: PurlObject, throws: boolean) {
@@ -569,12 +567,10 @@ const PurlType = createHelpersNamespaceObject(
569567
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#swift
570568
swift(purl: PurlObject, throws: boolean) {
571569
return (
572-
validateRequiredByType(
573-
'swift',
574-
'namespace',
575-
purl.namespace,
570+
validateRequiredByType('swift', 'namespace', purl.namespace, {
576571
throws,
577-
) && validateRequiredByType('swift', 'version', purl.version, throws)
572+
}) &&
573+
validateRequiredByType('swift', 'version', purl.version, { throws })
578574
)
579575
},
580576
},

0 commit comments

Comments
 (0)