From 7f3118c5254a88a575f6f6ec2e5ed0855dc51bcf Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 22 Jan 2021 14:46:02 +0000 Subject: [PATCH] fix(core): update --- package.json | 2 +- test/test.domain.ts | 5 +++++ ts/smartstring.domain.ts | 10 ++++++---- ts/smartstring.plugins.ts | 8 +------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c652c2e..6721620 100644 --- a/package.json +++ b/package.json @@ -56,4 +56,4 @@ "browserslist": [ "last 1 chrome versions" ] -} +} \ No newline at end of file diff --git a/test/test.domain.ts b/test/test.domain.ts index dcca6ef..91cceee 100644 --- a/test/test.domain.ts +++ b/test/test.domain.ts @@ -29,4 +29,9 @@ tap.test('testDomain2 expect be a basic domain', async () => { console.log(testDomain2); }); +tap.test('should parse complex domains', async () => { + testDomain2 = new smartstring.Domain('https://sub1.sub2.lossless.com/some/path:5431'); + console.log(testDomain2); +}); + tap.start(); diff --git a/ts/smartstring.domain.ts b/ts/smartstring.domain.ts index 361cb07..8b19ffa 100644 --- a/ts/smartstring.domain.ts +++ b/ts/smartstring.domain.ts @@ -16,7 +16,12 @@ export class Domain { public port; public nodeParsedUrl: plugins.url.UrlWithStringQuery; constructor(domainStringArg: string) { - const regexMatches = this._domainRegex(domainStringArg); + // lets do the node standard stuff first + this.nodeParsedUrl = plugins.url.parse(domainStringArg); + this.port = this.nodeParsedUrl.port; + + // lets do the rest after + const regexMatches = this._domainRegex(domainStringArg.replace(this.nodeParsedUrl.path, '')); this.fullName = ''; for (let i = 1; i <= 5; i++) { if (regexMatches[i - 1]) { @@ -38,9 +43,6 @@ export class Domain { this.topLevel = this.level1; this.domainName = this.level2; this.subDomain = this.level3; - - this.nodeParsedUrl = plugins.url.parse(domainStringArg); - this.port = this.nodeParsedUrl.port; } // helper functions diff --git a/ts/smartstring.plugins.ts b/ts/smartstring.plugins.ts index e84f3df..da26261 100644 --- a/ts/smartstring.plugins.ts +++ b/ts/smartstring.plugins.ts @@ -15,10 +15,4 @@ const normalizeNewline = require('normalize-newline'); const randomatic = smartenvInstance.getSafeNodeModule('randomatic'); const cryptoRandomString = smartenvInstance.getSafeNodeModule('crypto-random-string'); -export { - jsBase64, - stripIndent, - normalizeNewline, - randomatic, - cryptoRandomString -} \ No newline at end of file +export { jsBase64, stripIndent, normalizeNewline, randomatic, cryptoRandomString };