From 7a7dca19670783ac06a3760281e5ebe18b1fbdc1 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 25 Oct 2021 10:38:52 -0400 Subject: [PATCH] Use String.prototype.repeat Signed-off-by: Sebastian Malton --- src/common/utils/__tests__/string.test.ts | 38 ---------------- src/common/utils/index.ts | 2 - src/common/utils/string.ts | 45 ------------------- .../+service-accounts/secret.tsx | 4 +- 4 files changed, 2 insertions(+), 87 deletions(-) delete mode 100644 src/common/utils/__tests__/string.test.ts delete mode 100644 src/common/utils/string.ts diff --git a/src/common/utils/__tests__/string.test.ts b/src/common/utils/__tests__/string.test.ts deleted file mode 100644 index d87730d57f..0000000000 --- a/src/common/utils/__tests__/string.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2021 OpenLens Authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -import { string } from "../../utils"; - -describe("string tests", () => { - describe("repeated()", () => { - const table = []; - let acc = ""; - - for (let i = 0; i <= 20; i += 1) { - table.push([acc, i] as const); - acc += "l"; - } - - it.each(table)("should return %p string if times = %i", (output, times) => { - expect(string.repeated("l", times)).toBe(output); - }); - }); -}); diff --git a/src/common/utils/index.ts b/src/common/utils/index.ts index 4ad0d32f72..b39dcd0fae 100644 --- a/src/common/utils/index.ts +++ b/src/common/utils/index.ts @@ -62,11 +62,9 @@ export * from "./convertCpu"; import * as iter from "./iter"; import * as array from "./array"; import * as tuple from "./tuple"; -import * as string from "./string"; export { iter, array, - string, tuple, }; diff --git a/src/common/utils/string.ts b/src/common/utils/string.ts deleted file mode 100644 index 8365f7a11b..0000000000 --- a/src/common/utils/string.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2021 OpenLens Authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/** - * Create a new string that is `times` repetitions of `part` - * @param part The string segment to repeat - * @param times A non-negative count of repetitions. - */ -export function repeated(part: string, times: number): string { - function _repeated(part: string, times: number): string { - switch (times) { - case 0: - return ""; - case 1: - return part; - case 2: - return part + part; - default: - const major = Math.pow(2, Math.floor(Math.log2(times))); - const majorString = _repeated(part, major / 2); - - return majorString + majorString + _repeated(part, times - major); - } - } - - return _repeated(part, Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, Math.round(times)))); -} diff --git a/src/renderer/components/+user-management/+service-accounts/secret.tsx b/src/renderer/components/+user-management/+service-accounts/secret.tsx index 0c44908a2b..f0a182cb60 100644 --- a/src/renderer/components/+user-management/+service-accounts/secret.tsx +++ b/src/renderer/components/+user-management/+service-accounts/secret.tsx @@ -25,7 +25,7 @@ import moment from "moment"; import React from "react"; import type { Secret } from "../../../../common/k8s-api/endpoints/secret.api"; -import { prevDefault, string } from "../../../utils"; +import { prevDefault } from "../../../utils"; import { Icon } from "../../icon"; interface Props { @@ -49,7 +49,7 @@ export class ServiceAccountsSecret extends React.Component { <> {!showToken && ( <> - {string.repeated("•", 16)} + {"•".repeat(16)}