mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:40:43 +00:00
refactor: share human list formatting
This commit is contained in:
@@ -1,18 +1,6 @@
|
|||||||
|
import { formatHumanList } from "../shared/human-list.js";
|
||||||
import type { ChannelApprovalNativePlannedTarget } from "./approval-native-delivery.js";
|
import type { ChannelApprovalNativePlannedTarget } from "./approval-native-delivery.js";
|
||||||
|
|
||||||
function formatHumanList(values: readonly string[]): string {
|
|
||||||
if (values.length === 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (values.length === 1) {
|
|
||||||
return values[0];
|
|
||||||
}
|
|
||||||
if (values.length === 2) {
|
|
||||||
return `${values[0]} or ${values[1]}`;
|
|
||||||
}
|
|
||||||
return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function describeApprovalDeliveryDestination(params: {
|
export function describeApprovalDeliveryDestination(params: {
|
||||||
channelLabel: string;
|
channelLabel: string;
|
||||||
deliveredTargets: readonly ChannelApprovalNativePlannedTarget[];
|
deliveredTargets: readonly ChannelApprovalNativePlannedTarget[];
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||||
import type { InteractiveReply, InteractiveReplyButton } from "../interactive/payload.js";
|
import type { InteractiveReply, InteractiveReplyButton } from "../interactive/payload.js";
|
||||||
|
import { formatHumanList } from "../shared/human-list.js";
|
||||||
import {
|
import {
|
||||||
normalizeOptionalLowercaseString,
|
normalizeOptionalLowercaseString,
|
||||||
normalizeOptionalString,
|
normalizeOptionalString,
|
||||||
@@ -63,19 +64,6 @@ export type ExecApprovalUnavailableReplyParams = {
|
|||||||
sentApproverDms?: boolean;
|
sentApproverDms?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function formatHumanList(values: readonly string[]): string {
|
|
||||||
if (values.length === 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (values.length === 1) {
|
|
||||||
return values[0];
|
|
||||||
}
|
|
||||||
if (values.length === 2) {
|
|
||||||
return `${values[0]} or ${values[1]}`;
|
|
||||||
}
|
|
||||||
return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveNativeExecApprovalClientList(params?: { excludeChannel?: string }): string {
|
function resolveNativeExecApprovalClientList(params?: { excludeChannel?: string }): string {
|
||||||
return formatHumanList(
|
return formatHumanList(
|
||||||
listNativeExecApprovalClientLabels({
|
listNativeExecApprovalClientLabels({
|
||||||
|
|||||||
12
src/shared/human-list.ts
Normal file
12
src/shared/human-list.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export function formatHumanList(values: readonly string[]): string {
|
||||||
|
if (values.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (values.length === 1) {
|
||||||
|
return values[0];
|
||||||
|
}
|
||||||
|
if (values.length === 2) {
|
||||||
|
return `${values[0]} or ${values[1]}`;
|
||||||
|
}
|
||||||
|
return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user