Skip to content

Commit a879ea9

Browse files
committed
Upgrade to 0.3.0
1 parent 369057d commit a879ea9

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file. See
44
[standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
55

6+
### [0.3.0] (2025-05-01)
7+
8+
### Add
9+
10+
- Include new static method `isValidDomain`
11+
612
### [0.2.0] (2025-03-30)
713

814
### Change

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ protocol
44
## Installation
55

66
```shell
7-
npm i @creit.tech/sorobandomains-sdk
7+
npx jsr add @creit-tech/sorobandomains-sdk
88
```
9+
> If you are using another tool like Deno, Bun or PNPM; check the installation instructions [here](https://jsr.io/@creit-tech/sorobandomains-sdk).
910
1011
## The SorobanDomainsSDK class
1112

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@creit-tech/sorobandomains-sdk",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "An SDK to easily fetch domains from the sorobandomains.org protocol",
55
"license": "MIT",
66
"author": {

src/sdk.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ describe("Basic logic", (): void => {
2121
const generatedSubNode: string = SorobanDomainsSDK.parseDomain({ domain: "stellar", subDomain: "payments" });
2222
assertEquals(expectedSubNode, generatedSubNode);
2323
});
24+
25+
test("It should validate domains correctly", (): void => {
26+
assertEquals(true, SorobanDomainsSDK.isValidDomain('stellar.xlm'));
27+
assertEquals(true, SorobanDomainsSDK.isValidDomain('dev.stellar.xlm'));
28+
assertEquals(false, SorobanDomainsSDK.isValidDomain('another.dev.stellar.xlm'));
29+
assertEquals(false, SorobanDomainsSDK.isValidDomain('stellar'));
30+
assertEquals(false, SorobanDomainsSDK.isValidDomain('stellar..xlm'));
31+
assertEquals(false, SorobanDomainsSDK.isValidDomain(' stellar.xlm'));
32+
assertEquals(false, SorobanDomainsSDK.isValidDomain('qwertyuiopasdfghjklzxcvbnm.xlm'));
33+
assertEquals(false, SorobanDomainsSDK.isValidDomain('hello-world.xlm'));
34+
assertEquals(false, SorobanDomainsSDK.isValidDomain('steLLar.xlm'));
35+
assertEquals(false, SorobanDomainsSDK.isValidDomain('ste11ar.xlm'));
36+
});
2437
});

src/sdk.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ export class SorobanDomainsSDK {
4444
}
4545
}
4646

47+
/**
48+
* This method validates a domain string follow certain criteria required by the registry contract.
49+
* NOTE: It does not validate wrong TLDs
50+
*
51+
* @param domain {String} - The domain to validate, for example: stellar.xlm
52+
*/
53+
static isValidDomain(domain: string): boolean {
54+
const domainRegex: RegExp = new RegExp('^[a-z]+(\\.[a-z]+)*\\.[a-z]{2,}$');
55+
if (!domainRegex.test(domain)) return false;
56+
const parts: string[] = domain.split('.');
57+
if (parts.length > 3) return false;
58+
return parts.every((part: string): boolean => part.length <= 15);
59+
}
60+
4761
/**
4862
* This function parses the domain you want to use, and it will search it in the contract.
4963
* This function doesn't validate the domain you're providing is a valid one.

0 commit comments

Comments
 (0)