Skip to content

Commit 5b2aa84

Browse files
committed
Fix filterResultsFunction example (#1442).
1 parent 982bd40 commit 5b2aa84

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ The predicate function is only available in .ncurc.js or when importing npm-chec
464464
```js
465465
/**
466466
@param name The name of the dependency.
467-
@param semver A parsed Semver array of the upgraded version.
467+
@param semver A parsed Semver array of the current version.
468468
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
469469
@returns True if the package should be included, false if it should be excluded.
470470
*/
@@ -485,17 +485,17 @@ Filters out upgrades based on a user provided function.
485485
Only available in .ncurc.js or when importing npm-check-updates as a module.
486486

487487
```js
488-
/** Filter out non-major version updates.
489-
@param {string} packageName The name of the dependency.
490-
@param {string} current Current version declaration (may be a range).
491-
@param {SemVer[]} currentSemver Current version declaration in semantic versioning format (may be a range).
492-
@param {string} upgraded Upgraded version.
493-
@param {SemVer} upgradedSemver Upgraded version in semantic versioning format.
494-
@returns {boolean} Return true if the upgrade should be kept, otherwise it will be ignored.
488+
/** Filter out non-major version updates. Note this could also be achieved with --target semver.
489+
@param {string} packageName The name of the dependency.
490+
@param {string} current Current version declaration (may be a range).
491+
@param {SemVer[]} currentVersionSemver Current version declaration in semantic versioning format (may be a range).
492+
@param {string} upgraded Upgraded version.
493+
@param {SemVer} upgradedVersionSemver Upgraded version in semantic versioning format.
494+
@returns {boolean} Return true if the upgrade should be kept, otherwise it will be ignored.
495495
*/
496-
filterResults: (packageName, { current, currentSemver, upgraded, upgradedSemver }) => {
497-
const currentMajor = parseInt(currentSemver[0]?.major, 10)
498-
const upgradedMajor = parseInt(upgradedSemver?.major, 10)
496+
filterResults: (packageName, { current, currentVersionSemver, upgraded, upgradedVersionSemver }) => {
497+
const currentMajor = parseInt(currentVersionSemver[0]?.major, 10)
498+
const upgradedMajor = parseInt(upgradedVersionSemver?.major, 10)
499499
if (currentMajor && upgradedMajor) {
500500
return currentMajor < upgradedMajor
501501
}
@@ -513,12 +513,14 @@ Usage:
513513
514514
Include only versions matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.
515515
516-
The predicate function is only available in .ncurc.js or when importing npm-check-updates as a module, not on the command line. This function is an alias for the filter option function.
516+
`--filterVersion` runs _before_ new versions are fetched, in contrast to `--filterResults` which runs _after_.
517+
518+
The predicate function is only available in .ncurc.js or when importing npm-check-updates as a module, not on the command line. This function is an alias for the `filter` option function.
517519
518520
```js
519521
/**
520522
@param name The name of the dependency.
521-
@param semver A parsed Semver array of the upgraded version.
523+
@param semver A parsed Semver array of the current version.
522524
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
523525
@returns True if the package should be included, false if it should be excluded.
524526
*/
@@ -697,7 +699,7 @@ The predicate function is only available in .ncurc.js or when importing npm-chec
697699
```js
698700
/**
699701
@param name The name of the dependency.
700-
@param semver A parsed Semver array of the upgraded version.
702+
@param semver A parsed Semver array of the current version.
701703
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
702704
@returns True if the package should be excluded, false if it should be included.
703705
*/
@@ -717,12 +719,14 @@ Usage:
717719
718720
The inverse of `--filterVersion`. Exclude versions matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.
719721
722+
`--rejectVersion` runs _before_ new versions are fetched, in contrast to `--filterResults` which runs _after_.
723+
720724
The predicate function is only available in .ncurc.js or when importing npm-check-updates as a module, not on the command line. This function is an alias for the reject option function.
721725
722726
```js
723727
/**
724728
@param name The name of the dependency.
725-
@param semver A parsed Semver array of the upgraded version.
729+
@param semver A parsed Semver array of the current version.
726730
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
727731
@returns True if the package should be excluded, false if it should be included.
728732
*/

src/cli-options.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,21 @@ ${codeInline('filterResults')} runs _after_ new versions are fetched, in contras
135135
Only available in .ncurc.js or when importing npm-check-updates as a module.
136136
137137
${codeBlock(
138-
`${chalk.gray(`/** Filter out non-major version updates.
139-
@param {string} packageName The name of the dependency.
140-
@param {string} current Current version declaration (may be a range).
141-
@param {SemVer[]} currentSemver Current version declaration in semantic versioning format (may be a range).
142-
@param {string} upgraded Upgraded version.
143-
@param {SemVer} upgradedSemver Upgraded version in semantic versioning format.
144-
@returns {boolean} Return true if the upgrade should be kept, otherwise it will be ignored.
138+
`${chalk.gray(`/** Filter out non-major version updates. Note this could also be achieved with --target semver.
139+
@param {string} packageName The name of the dependency.
140+
@param {string} current Current version declaration (may be a range).
141+
@param {SemVer[]} currentVersionSemver Current version declaration in semantic versioning format (may be a range).
142+
@param {string} upgraded Upgraded version.
143+
@param {SemVer} upgradedVersionSemver Upgraded version in semantic versioning format.
144+
@returns {boolean} Return true if the upgrade should be kept, otherwise it will be ignored.
145145
*/`)}
146-
${chalk.green('filterResults')}: (packageName, { current, currentSemver, upgraded, upgradedSemver }) ${chalk.cyan(
146+
${chalk.green('filterResults')}: (packageName, { current, currentVersionSemver, upgraded, upgradedVersionSemver }) ${chalk.cyan(
147147
'=>',
148148
)} {
149-
${chalk.cyan('const')} currentMajor ${chalk.red('=')} parseInt(currentSemver[${chalk.cyan('0')}]?.major, ${chalk.cyan(
149+
${chalk.cyan('const')} currentMajor ${chalk.red('=')} parseInt(currentVersionSemver[${chalk.cyan('0')}]?.major, ${chalk.cyan(
150150
'10',
151151
)})
152-
${chalk.cyan('const')} upgradedMajor ${chalk.red('=')} parseInt(upgradedSemver?.major, ${chalk.cyan('10')})
152+
${chalk.cyan('const')} upgradedMajor ${chalk.red('=')} parseInt(upgradedVersionSemver?.major, ${chalk.cyan('10')})
153153
${chalk.red('if')} (currentMajor ${chalk.red('&&')} upgradedMajor) {
154154
${chalk.red('return')} currentMajor ${chalk.red('<')} upgradedMajor
155155
}
@@ -222,7 +222,7 @@ The predicate function is only available in .ncurc.js or when importing npm-chec
222222
${codeBlock(
223223
`${chalk.gray(`/**
224224
@param name The name of the dependency.
225-
@param semver A parsed Semver array of the upgraded version.
225+
@param semver A parsed Semver array of the current version.
226226
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
227227
@returns True if the package should be included, false if it should be excluded.
228228
*/`)}
@@ -240,14 +240,21 @@ ${chalk.green('filterFunction')}: (name, semver) ${chalk.cyan('=>')} {
240240

241241
/** Extended help for the --filterVersion option. */
242242
const extendedHelpFilterVersionFunction: ExtendedHelp = ({ markdown }) => {
243+
/** If markdown, surround inline code with backticks. */
244+
const codeInline = (code: string) => (markdown ? `\`${code}\`` : code)
245+
243246
return `Include only versions matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.
244247
245-
The predicate function is only available in .ncurc.js or when importing npm-check-updates as a module, not on the command line. This function is an alias for the filter option function.
248+
${codeInline('--filterVersion')} runs _before_ new versions are fetched, in contrast to ${codeInline(
249+
'--filterResults',
250+
)} which runs _after_.
251+
252+
The predicate function is only available in .ncurc.js or when importing npm-check-updates as a module, not on the command line. This function is an alias for the ${codeInline('filter')} option function.
246253
247254
${codeBlock(
248255
`${chalk.gray(`/**
249256
@param name The name of the dependency.
250-
@param semver A parsed Semver array of the upgraded version.
257+
@param semver A parsed Semver array of the current version.
251258
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
252259
@returns True if the package should be included, false if it should be excluded.
253260
*/`)}
@@ -285,7 +292,7 @@ The predicate function is only available in .ncurc.js or when importing npm-chec
285292
${codeBlock(
286293
`${chalk.gray(`/**
287294
@param name The name of the dependency.
288-
@param semver A parsed Semver array of the upgraded version.
295+
@param semver A parsed Semver array of the current version.
289296
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
290297
@returns True if the package should be excluded, false if it should be included.
291298
*/`)}
@@ -310,12 +317,16 @@ const extendedHelpRejectVersionFunction: ExtendedHelp = ({ markdown }) => {
310317
'--filterVersion',
311318
)}. Exclude versions matching the given string, wildcard, glob, comma-or-space-delimited list, /regex/, or predicate function.
312319
320+
${codeInline('--rejectVersion')} runs _before_ new versions are fetched, in contrast to ${codeInline(
321+
'--filterResults',
322+
)} which runs _after_.
323+
313324
The predicate function is only available in .ncurc.js or when importing npm-check-updates as a module, not on the command line. This function is an alias for the reject option function.
314325
315326
${codeBlock(
316327
`${chalk.gray(`/**
317328
@param name The name of the dependency.
318-
@param semver A parsed Semver array of the upgraded version.
329+
@param semver A parsed Semver array of the current version.
319330
(See: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
320331
@returns True if the package should be excluded, false if it should be included.
321332
*/`)}

0 commit comments

Comments
 (0)