-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtoken.utils.ts
More file actions
29 lines (23 loc) · 830 Bytes
/
token.utils.ts
File metadata and controls
29 lines (23 loc) · 830 Bytes
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
export class TokenUtils {
static tokenValidateRegex: RegExp = /^([a-z0-9]{1,4}-)?[A-Za-z0-9]{3,10}-[a-fA-F0-9]{6}$/;
static nftValidateRegex: RegExp = /^([a-z0-9]{1,4}-)?[A-Za-z0-9]{3,10}-[a-fA-F0-9]{6}-[a-fA-F0-9]{2,}$/;
static isToken(identifier: string): boolean {
return this.tokenValidateRegex.test(identifier);
}
static isCollection(identifier: string): boolean {
return this.tokenValidateRegex.test(identifier);
}
static isNft(identifier: string): boolean {
return this.nftValidateRegex.test(identifier);
}
static isSovereignIdentifier(identifier: string): boolean {
const numParts = identifier.split("-").length;
if (this.isCollection(identifier)) {
return numParts === 3;
}
if (this.isNft(identifier)) {
return numParts === 4;
}
return false;
}
}