Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix truncate issue (#825) #828

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/command/packer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import truncate from "just-truncate";

import type { CommandType } from "~/schemas";
import { truncate } from "~/utils";

const abbreviations = ["ip", "asn", "btc", "cve", "eth", "url"];

Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Base64 } from "js-base64";
import jt from "just-truncate";

import type { Scanner, Searcher } from "~/types";

Expand Down Expand Up @@ -43,3 +44,7 @@ export function isSearcher(object: any): object is Searcher {
export function isScanner(object: any): object is Scanner {
return "setAPIKey" in object;
}

export function truncate(s: string, length: number = 32): string {
return jt(s, length);
}
8 changes: 8 additions & 0 deletions tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { truncate } from "~/utils";

test.each([
["a".repeat(32), "a".repeat(32)],
["a".repeat(33), "a".repeat(29) + "..."],
])(".truncate(%s, %s)", (s: string, expected: string) => {
expect(truncate(s)).toBe(expected);
});