mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Use String.prototype.repeat
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
159d4c4189
commit
7a7dca1967
@ -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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -62,11 +62,9 @@ export * from "./convertCpu";
|
|||||||
import * as iter from "./iter";
|
import * as iter from "./iter";
|
||||||
import * as array from "./array";
|
import * as array from "./array";
|
||||||
import * as tuple from "./tuple";
|
import * as tuple from "./tuple";
|
||||||
import * as string from "./string";
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
iter,
|
iter,
|
||||||
array,
|
array,
|
||||||
string,
|
|
||||||
tuple,
|
tuple,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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))));
|
|
||||||
}
|
|
||||||
@ -25,7 +25,7 @@ import moment from "moment";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import type { Secret } from "../../../../common/k8s-api/endpoints/secret.api";
|
import type { Secret } from "../../../../common/k8s-api/endpoints/secret.api";
|
||||||
import { prevDefault, string } from "../../../utils";
|
import { prevDefault } from "../../../utils";
|
||||||
import { Icon } from "../../icon";
|
import { Icon } from "../../icon";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -49,7 +49,7 @@ export class ServiceAccountsSecret extends React.Component<Props, State> {
|
|||||||
<>
|
<>
|
||||||
{!showToken && (
|
{!showToken && (
|
||||||
<>
|
<>
|
||||||
<span className="asterisks">{string.repeated("•", 16)}</span>
|
<span className="asterisks">{"•".repeat(16)}</span>
|
||||||
<Icon
|
<Icon
|
||||||
small material="lock_open"
|
small material="lock_open"
|
||||||
tooltip="Show value"
|
tooltip="Show value"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user