From 46d7d68585b789bd88d7214f097fdea63d1e21e4 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 24 Apr 2019 13:07:51 +0200 Subject: [PATCH] Visual Console Refactor: changed a function name Former-commit-id: 3adfb5fbdebe495fbd88d53d7ce93bbdf5ce0876 --- visual_console_client/src/lib.spec.ts | 24 ++++++++++++------------ visual_console_client/src/lib.ts | 14 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/visual_console_client/src/lib.spec.ts b/visual_console_client/src/lib.spec.ts index 459cc5cc39..9c6c976de2 100644 --- a/visual_console_client/src/lib.spec.ts +++ b/visual_console_client/src/lib.spec.ts @@ -2,7 +2,7 @@ import { parseIntOr, stringIsEmpty, notEmptyStringOr, - padLeft, + leftPad, prefixedCssRules, decodeBase64, humanDate, @@ -42,18 +42,18 @@ describe("function notEmptyStringOr", () => { }); }); -describe("function padLeft", () => { +describe("function leftPad", () => { it("should pad properly", () => { - expect(padLeft(1, 2, 0)).toBe("01"); - expect(padLeft(1, 4, 0)).toBe("0001"); - expect(padLeft(1, 4, "0")).toBe("0001"); - expect(padLeft("1", 4, "0")).toBe("0001"); - expect(padLeft(10, 4, 0)).toBe("0010"); - expect(padLeft("bar", 6, "foo")).toBe("foobar"); - expect(padLeft("bar", 11, "foo")).toBe("foofoofobar"); - expect(padLeft("bar", 4, "foo")).toBe("fbar"); - expect(padLeft("bar", 2, "foo")).toBe("ar"); - expect(padLeft("bar", 3, "foo")).toBe("bar"); + expect(leftPad(1, 2, 0)).toBe("01"); + expect(leftPad(1, 4, 0)).toBe("0001"); + expect(leftPad(1, 4, "0")).toBe("0001"); + expect(leftPad("1", 4, "0")).toBe("0001"); + expect(leftPad(10, 4, 0)).toBe("0010"); + expect(leftPad("bar", 6, "foo")).toBe("foobar"); + expect(leftPad("bar", 11, "foo")).toBe("foofoofobar"); + expect(leftPad("bar", 4, "foo")).toBe("fbar"); + expect(leftPad("bar", 2, "foo")).toBe("ar"); + expect(leftPad("bar", 3, "foo")).toBe("bar"); }); }); diff --git a/visual_console_client/src/lib.ts b/visual_console_client/src/lib.ts index cbfc53c831..e746fb7b41 100644 --- a/visual_console_client/src/lib.ts +++ b/visual_console_client/src/lib.ts @@ -82,7 +82,7 @@ export function parseBoolean(value: any): boolean { * @param pad Text to add. * @return Padded text. */ -export function padLeft( +export function leftPad( value: string | number, length: number, pad: string | number = " " @@ -287,10 +287,10 @@ export function decodeBase64(input: string): string { export function humanDate(initialDate: Date | null = null): string { const date = initialDate || new Date(); // Use getDate, getDay returns the week day. - const day = padLeft(date.getDate(), 2, 0); + const day = leftPad(date.getDate(), 2, 0); // The getMonth function returns the month starting by 0. - const month = padLeft(date.getMonth() + 1, 2, 0); - const year = padLeft(date.getFullYear(), 4, 0); + const month = leftPad(date.getMonth() + 1, 2, 0); + const year = leftPad(date.getFullYear(), 4, 0); // Format: 'd/m/Y'. return `${day}/${month}/${year}`; @@ -304,9 +304,9 @@ export function humanDate(initialDate: Date | null = null): string { */ export function humanTime(initialDate: Date | null = null): string { const date = initialDate || new Date(); - const hours = padLeft(date.getHours(), 2, 0); - const minutes = padLeft(date.getMinutes(), 2, 0); - const seconds = padLeft(date.getSeconds(), 2, 0); + const hours = leftPad(date.getHours(), 2, 0); + const minutes = leftPad(date.getMinutes(), 2, 0); + const seconds = leftPad(date.getSeconds(), 2, 0); return `${hours}:${minutes}:${seconds}`; }