mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
fork refine
This commit is contained in:
29
packages/cli/src/utils/text/index.test.tsx
Normal file
29
packages/cli/src/utils/text/index.test.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { removeANSIColors, uppercaseFirstChar } from ".";
|
||||
|
||||
describe("uppercaseFirstChar", () => {
|
||||
it("should return the string with the first character capitalized", () => {
|
||||
const str = "hello world";
|
||||
const result = uppercaseFirstChar(str);
|
||||
expect(result).toEqual("Hello world");
|
||||
});
|
||||
|
||||
it("should return an empty string if the input is empty", () => {
|
||||
const str = "";
|
||||
const result = uppercaseFirstChar(str);
|
||||
expect(result).toEqual("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeANSIColors", () => {
|
||||
it("should remove ANSI color codes from the string", () => {
|
||||
const str = "\u001b[31mHello \u001b[32mworld\u001b[0m";
|
||||
const result = removeANSIColors(str);
|
||||
expect(result).toEqual("Hello world");
|
||||
});
|
||||
|
||||
it("should return the original string if it does not contain any ANSI color codes", () => {
|
||||
const str = "Hello world";
|
||||
const result = removeANSIColors(str);
|
||||
expect(result).toEqual(str);
|
||||
});
|
||||
});
|
||||
10
packages/cli/src/utils/text/index.ts
Normal file
10
packages/cli/src/utils/text/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const uppercaseFirstChar = (str: string): string => {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
};
|
||||
|
||||
export const removeANSIColors = (str: string): string => {
|
||||
return str.replace(
|
||||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
||||
"",
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user