File tree Expand file tree Collapse file tree 5 files changed +36
-2
lines changed
Expand file tree Collapse file tree 5 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 33All 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments