Browse Source

Updates String.pluralize options

main
Eric Amodio 3 years ago
parent
commit
4038c3cca6
5 changed files with 23 additions and 14 deletions
  1. +1
    -4
      src/commands/git/branch.ts
  2. +1
    -1
      src/commands/git/search.ts
  3. +16
    -4
      src/system/string.ts
  4. +4
    -4
      src/views/nodes/contributorNode.ts
  5. +1
    -1
      src/views/nodes/searchResultsNode.ts

+ 1
- 4
src/commands/git/branch.ts View File

@ -353,10 +353,7 @@ export class BranchGitCommand extends QuickCommand {
}
context.title = getTitle(
Strings.pluralize('Branch', state.references.length, {
number: '',
plural: 'Branches',
}).trim(),
Strings.pluralize('Branch', state.references.length, { only: true, plural: 'Branches' }),
state.subcommand,
);

+ 1
- 1
src/commands/git/search.ts View File

@ -189,7 +189,7 @@ export class SearchGitCommand extends QuickCommand {
log == null
? `No results for ${state.pattern}`
: `${Strings.pluralize('result', log.count, {
number: log.hasMore ? `${log.count}+` : undefined,
format: c => (log.hasMore ? `${c}+` : undefined),
})} for ${state.pattern}`,
picked: context.commit?.ref,
showInSideBarCommand: new ActionQuickPickItem(

+ 16
- 4
src/system/string.ts View File

@ -345,13 +345,25 @@ export function padRightOrTruncate(s: string, max: number, padding?: string, wid
export function pluralize(
s: string,
count: number,
options?: { infix?: string; number?: string; plural?: string; zero?: string },
options?: {
/** Controls the character/string between the count and the string */
infix?: string;
/** Formats the count */
format?: (count: number) => string | undefined;
/** Controls if only the string should be included */
only?: boolean;
/** Controls the plural version of the string */
plural?: string;
/** Controls the string for a zero value */
zero?: string;
},
) {
if (options == null) return `${count} ${s}${count === 1 ? emptyStr : 's'}`;
return `${
count === 0 ? (options.zero != null ? options.zero : count) : options.number != null ? options.number : count
}${options.infix ?? ' '}${count === 1 ? s : options.plural ?? `${s}s`}`;
const suffix = count === 1 ? s : options.plural ?? `${s}s`;
if (options.only) return suffix;
return `${count === 0 ? options.zero ?? count : options.format?.(count) ?? count}${options.infix ?? ' '}${suffix}`;
}
// Removes \ / : * ? " < > | and C0 and C1 control codes

+ 4
- 4
src/views/nodes/contributorNode.ts View File

@ -112,11 +112,11 @@ export class ContributorNode extends ViewNode
const stats =
this.contributor.stats != null
? `\\\n${Strings.pluralize('file', this.contributor.stats.files, {
number: numberFormatter.format(this.contributor.stats.files),
format: numberFormatter.format,
})} changed, ${Strings.pluralize('addition', this.contributor.stats.additions, {
number: numberFormatter.format(this.contributor.stats.additions),
format: numberFormatter.format,
})}, ${Strings.pluralize('deletion', this.contributor.stats.deletions, {
number: numberFormatter.format(this.contributor.stats.deletions),
format: numberFormatter.format,
})}`
: '';
@ -128,7 +128,7 @@ export class ContributorNode extends ViewNode
})")__ \\\nLast commit ${this.contributor.formatDateFromNow()} (${this.contributor.formatDate()})\n\n${Strings.pluralize(
'commit',
this.contributor.count,
{ number: numberFormatter.format(this.contributor.count) },
{ format: numberFormatter.format },
)}${stats}`,
);

+ 1
- 1
src/views/nodes/searchResultsNode.ts View File

@ -244,7 +244,7 @@ export class SearchResultsNode extends ViewNode implements
label.resultsType === undefined ? { singular: 'result', plural: 'results' } : label.resultsType;
return `${Strings.pluralize(resultsType.singular, count, {
number: log?.hasMore ?? false ? `${count}+` : undefined,
format: c => (log?.hasMore ? `${c}+` : undefined),
plural: resultsType.plural,
zero: 'No',
})} ${label.label}`;

Loading…
Cancel
Save