Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): normalize input for poll option #8342

Merged
merged 4 commits into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/docusaurus/bin/docusaurus.mjs
Expand Up @@ -22,6 +22,7 @@ import {
writeTranslations,
writeHeadingIds,
} from '../lib/index.js';
import {normalizePollValue} from './utils.mjs';
import beforeCli from './beforeCli.mjs';

await beforeCli();
Expand Down Expand Up @@ -122,6 +123,7 @@ cli
.option(
'--poll [interval]',
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
normalizePollValue,
)
.option(
'--no-minify',
Expand Down
24 changes: 24 additions & 0 deletions packages/docusaurus/bin/utils.mjs
@@ -0,0 +1,24 @@
/**
mhnaeem marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
*
* @param {string} value
* @returns {boolean|number}
*/
export function normalizePollValue(value) {
if (value === undefined || value === '') {
return false;
}

const parsedIntValue = Number.parseInt(value, 10);
if (!Number.isNaN(parsedIntValue)) {
return parsedIntValue;
}

return value === 'true';
}