-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added WebsiteUrl and functions
- added WebsiteUrl and related types and functions - fixed readEmailDomainFromUrlOrEmailAddress() domain parsing issue - fixed slashPathType()
- Loading branch information
Showing
10 changed files
with
384 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { readEmailDomainFromUrlOrEmailAddress } from './domain'; | ||
|
||
describe('readDomainFromUrlOrEmailAddress()', () => { | ||
it('should read the email domain from a url', () => { | ||
const domain = 'dereekb.com'; | ||
const testUrl = `https://${domain}/test/place/1`; | ||
const result = readEmailDomainFromUrlOrEmailAddress(testUrl); | ||
|
||
expect(result).toBe(domain); | ||
}); | ||
|
||
it('should ignore the www in the domain', () => { | ||
const domain = 'dereekb.com'; | ||
const testUrl = `https://www.${domain}/test/place/1`; | ||
const result = readEmailDomainFromUrlOrEmailAddress(testUrl); | ||
|
||
expect(result).toBe(domain); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { splitJoinRemainder } from './string'; | ||
|
||
describe('splitJoinRemainder()', () => { | ||
it('should handle having a single value', () => { | ||
const values = ['a']; | ||
const string = values.join(','); | ||
|
||
const result = splitJoinRemainder(string, ',', 3); | ||
expect(result[0]).toBe(values[0]); | ||
}); | ||
|
||
it('should split the value up to the limit (1) and join the remainder', () => { | ||
const values = ['a,b,c,d,e']; | ||
const string = values.join(','); | ||
|
||
const result = splitJoinRemainder(string, ',', 1); | ||
expect(result[0]).toBe(values[0]); | ||
}); | ||
|
||
it('should split the value up to the limit (2) and join the remainder', () => { | ||
const values = ['a', 'b,c,d,e']; | ||
const string = values.join(','); | ||
|
||
const result = splitJoinRemainder(string, ',', 2); | ||
expect(result[0]).toBe(values[0]); | ||
expect(result[1]).toBe(values[1]); | ||
}); | ||
|
||
it('should split the value up to the limit (3) and join the remainder', () => { | ||
const values = ['a', 'b', 'c,d,e']; | ||
const string = values.join(','); | ||
|
||
const result = splitJoinRemainder(string, ',', 3); | ||
expect(result[0]).toBe(values[0]); | ||
expect(result[1]).toBe(values[1]); | ||
expect(result[2]).toBe(values[2]); | ||
}); | ||
|
||
it('should split the value up to the limit (8) and join the remainder', () => { | ||
const values = ['a', 'b', 'c', 'd', 'e']; | ||
const string = values.join(','); | ||
|
||
const result = splitJoinRemainder(string, ',', 8); | ||
expect(result[0]).toBe(values[0]); | ||
expect(result[1]).toBe(values[1]); | ||
expect(result[2]).toBe(values[2]); | ||
expect(result[3]).toBe(values[3]); | ||
expect(result[4]).toBe(values[4]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { isolateWebsitePathFunction, removeHttpFromUrl, websiteDomainAndPathPairFromWebsiteUrl, websitePathAndQueryPair, websitePathFromWebsiteDomainAndPath, websitePathFromWebsiteUrl } from './url'; | ||
|
||
const domain = 'dereekb.com'; | ||
|
||
describe('isolateWebsitePathFunction()', () => { | ||
describe('function', () => { | ||
const pathInner = '/hello/world'; | ||
const basePath = '/test'; | ||
const path = `${basePath}${pathInner}`; | ||
const fullUrl = `https://${domain}${path}`; | ||
|
||
const isolateFn = isolateWebsitePathFunction(); | ||
|
||
it('should isolate the path from the input', () => { | ||
const result = isolateFn(fullUrl); | ||
expect(result).toBe(path); | ||
}); | ||
|
||
it('should retain any query parameters', () => { | ||
const query = '?test=true'; | ||
const result = isolateFn(fullUrl + query); | ||
expect(result).toBe(path + query); | ||
}); | ||
|
||
describe('ignoredBasePath', () => { | ||
const isolateFn = isolateWebsitePathFunction({ | ||
ignoredBasePath: 'test' | ||
}); | ||
|
||
it('should isolate the path from the input without the base path', () => { | ||
const result = isolateFn(fullUrl); | ||
expect(result).toBe(pathInner); | ||
}); | ||
}); | ||
|
||
describe('removeQueryParameters', () => { | ||
const isolateFn = isolateWebsitePathFunction({ | ||
removeQueryParameters: true | ||
}); | ||
|
||
it('should isolate the path from the input without the query parameters', () => { | ||
const result = isolateFn(fullUrl + '?test=true'); | ||
expect(result).toBe(path); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('websitePathAndQueryPair()', () => { | ||
it('should return the website path from the input url', () => { | ||
const path = '/test/hello/world'; | ||
const query = '?hello=world'; | ||
|
||
const result = websitePathAndQueryPair(`${path}${query}`); | ||
expect(result.path).toBe(path); | ||
expect(result.query).toBe(query); | ||
}); | ||
}); | ||
|
||
describe('websitePathFromWebsiteUrl()', () => { | ||
it('should return the website path from the input url', () => { | ||
const path = '/test/hello/world'; | ||
const result = websitePathFromWebsiteUrl(`https://${domain}${path}`); | ||
expect(result).toBe(path); | ||
}); | ||
}); | ||
|
||
describe('websiteDomainAndPathPairFromWebsiteUrl()', () => { | ||
it('should return the website path from the input url', () => { | ||
const path = '/test/hello/world'; | ||
const result = websiteDomainAndPathPairFromWebsiteUrl(`https://${domain}${path}`); | ||
expect(result.domain).toBe(domain); | ||
expect(result.path).toBe(path); | ||
}); | ||
}); | ||
|
||
describe('websitePathFromWebsiteDomainAndPath()', () => { | ||
it('should return the website path from the domain', () => { | ||
const path = '/test/hello/world'; | ||
const result = websitePathFromWebsiteDomainAndPath(`${domain}${path}`); | ||
expect(result).toBe(path); | ||
}); | ||
|
||
it('should return only a slash if the input is a domain', () => { | ||
const result = websitePathFromWebsiteDomainAndPath(domain); | ||
expect(result).toBe('/'); | ||
}); | ||
}); | ||
|
||
describe('removeHttpFromUrl()', () => { | ||
const domain = 'dereekb.com'; | ||
|
||
it('should remove http:// from the string', () => { | ||
const result = removeHttpFromUrl(`http://${domain}`); | ||
expect(result).toBe(domain); | ||
}); | ||
|
||
it('should remove https:// from the string', () => { | ||
const result = removeHttpFromUrl(`https://${domain}`); | ||
expect(result).toBe(domain); | ||
}); | ||
}); |
Oops, something went wrong.