-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformat.ts
57 lines (47 loc) · 1.68 KB
/
format.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright © 2022 The Radicle Design System Contributors
//
// This file is part of radicle-design-system, distributed under the GPLv3
// with Radicle Linking Exception. For full terms see the included
// LICENSE file.
// dayjs(1632733193970).format(TRANSACTION_TIMESTAMP_FORMAT) ->
// 27 Sep 2021 at 10:59
export const TRANSACTION_TIMESTAMP_FORMAT = "D MMM YYYY [at] HH:mm";
export function shorten(
value: string,
beginningLength: number,
endingLength?: number
): string {
const beginning = value.slice(0, beginningLength);
const ending = value.slice(-(endingLength ?? beginningLength));
return `${beginning}…${ending}`;
}
// rad:git:hnrkjhtohoe3u9mmtqgc6apbzomwwpos9h7ky ->
// hnrkjhto…pos9h7ky
export function shortProjectId(value: string): string {
return shorten(value.replace("rad:git:", ""), 8);
}
// hyyo6u8rhnuswory4c6symx471yseke74oq1myfesoig7zggcixejy ->
// hyyo6u8r…ggcixejy
export function shortPeerId(value: string): string {
return shorten(value, 8);
}
// 0xA66A5686D5c3A42C0b6c76FEd05e58C6bc851E9f ->
// 0xa66a56…851e9f
export function shortEthAddress(value: string): string {
return shorten(value.toLowerCase(), 8, 6);
}
export const shortEthTx = shortEthAddress;
// hynewpywqj6x4mxgj7sojhue3erucyexiyhobxx4du9w66hxhbfqbw@seedling.radicle.xyz:12345 ->
// hynewpyw…[email protected]:12345
export function shortSeedAddress(value: string): string {
const match = value.match(/^(.{54})@(.*)$/);
if (match && match[1] && match[2]) {
return `${shortPeerId(match[1])}@${match[2]}`;
}
return value;
}
// 07e57974a3b0aa77a92c2a605c72523c6f996215 ->
// 07e5797
export function shortCommitHash(value: string): string {
return value.slice(0, 7);
}