fork refine

This commit is contained in:
Stefan Pejcic
2024-02-05 10:23:04 +01:00
parent 3fffde9a8f
commit 8496a83edb
3634 changed files with 715528 additions and 2 deletions

View 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);
});
});

View 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,
"",
);
};