mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 02:10:24 +00:00
refactor: consolidate duplicate utility functions (#12439)
* refactor: consolidate duplicate utility functions - Add escapeRegExp to src/utils.ts and remove 10 local duplicates - Rename bash-tools clampNumber to clampWithDefault (different signature) - Centralize formatError calls to use formatErrorMessage from infra/errors.ts - Re-export formatErrorMessage from cli/cli-utils.ts to preserve API * refactor: consolidate remaining escapeRegExp duplicates * refactor: consolidate sleep, stripAnsi, and clamp duplicates
This commit is contained in:
10
src/utils.ts
10
src/utils.ts
@@ -21,6 +21,16 @@ export function clampInt(value: number, min: number, max: number): number {
|
||||
return clampNumber(Math.floor(value), min, max);
|
||||
}
|
||||
|
||||
/** Alias for clampNumber (shorter, more common name) */
|
||||
export const clamp = clampNumber;
|
||||
|
||||
/**
|
||||
* Escapes special regex characters in a string so it can be used in a RegExp constructor.
|
||||
*/
|
||||
export function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
export type WebChannel = "web";
|
||||
|
||||
export function assertWebChannel(input: string): asserts input is WebChannel {
|
||||
|
||||
Reference in New Issue
Block a user