Skip to content

Commit 9a9d92c

Browse files
authored
🐛 fix: docs command crashes when select menu options text is longer than 100 chars (#47)
1 parent 61b530e commit 9a9d92c

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/commands/docs/baseline.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { features as data } from 'web-features';
1111
import { fuzzySearch } from '../../util/fuzzy-search.js';
1212
import type { ProviderConfig } from './types.js';
1313
import { createBaseConfig, getBaselineFeatures } from './utils.js';
14+
import { clampText } from '../../util/text.js';
1415

1516
export type FeatureData = {
1617
name: string;
@@ -72,11 +73,8 @@ export const baselineProvider: ProviderConfig<FeatureItem> = {
7273
.setMaxValues(1)
7374
.addOptions(
7475
...data.map((feature) => ({
75-
label: feature.name.length > 100 ? `${feature.name.slice(0, 97)}...` : feature.name,
76-
description:
77-
feature.description.length > 100
78-
? `${feature.description.slice(0, 97)}...`
79-
: feature.description,
76+
label: clampText(feature.name, 100),
77+
description: clampText(feature.description, 100),
8078
value: feature.key,
8179
}))
8280
)

src/commands/docs/mdn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const mdnProvider: ProviderConfig<SearchItem> = {
5656
.setMaxValues(Math.min(5, data.size))
5757
.addOptions(
5858
...data.map((doc) => ({
59-
label: doc.title.length > 100 ? `${doc.title.slice(0, 97)}...` : doc.title,
60-
description: doc.summary.length > 100 ? `${doc.summary.slice(0, 97)}...` : doc.summary,
59+
label: clampText(doc.title, 100),
60+
description: clampText(doc.summary, 100),
6161
value: doc.slug,
6262
}))
6363
)

src/commands/docs/npm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const npmProvider: ProviderConfig<SearchItem> = {
6464
...data.map((pkg) =>
6565
new StringSelectMenuOptionBuilder()
6666
.setLabel(pkg.name)
67-
.setDescription(pkg.description)
67+
.setDescription(clampText(pkg.description, 100))
6868
.setValue(pkg.name)
6969
)
7070
)

0 commit comments

Comments
 (0)