generated from sapphiredev/sapphire-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jeroen Claassens <support@favware.tech>
- Loading branch information
1 parent
3eb5175
commit 46c5b49
Showing
9 changed files
with
56 additions
and
42 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
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
/** | ||
* Tries parse a string to a {@link URL} object | ||
* @param value The possible URL to parse | ||
* @returns an URL object if it was a valid URL or `null` if it was not. | ||
*/ | ||
export function tryParseURL(value: string): URL | null { | ||
try { | ||
return new URL(value); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
export { tryParseURL as parseURL }; |
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
packages/utilities/tests/tryParse.test.ts → ...ages/utilities/tests/tryParseJSON.test.ts
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { tryParse } from '../src'; | ||
import { tryParseJSON } from '../src'; | ||
|
||
describe('tryParse', () => { | ||
describe('tryParseJSON', () => { | ||
test('GIVEN basic THEN returns expected', () => { | ||
const source = '{"a":4,"b":6}'; | ||
const expected = { a: 4, b: 6 }; | ||
expect(tryParse(source)).toEqual(expected); | ||
expect(tryParseJSON(source)).toEqual(expected); | ||
}); | ||
|
||
test('GIVEN invalid THEN returns expected', () => { | ||
const source = '{"a":4,"b:6}'; | ||
const expected = '{"a":4,"b:6}'; | ||
expect(tryParse(source)).toEqual(expected); | ||
expect(tryParseJSON(source)).toEqual(expected); | ||
}); | ||
}); |
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,12 @@ | ||
import { URL } from 'url'; | ||
import { tryParseURL } from '../src'; | ||
|
||
describe('tryParseURL', () => { | ||
test('GIVEN valid URL THEN returns URL', () => { | ||
expect(tryParseURL('https://skyra.pw')).toStrictEqual(new URL('https://skyra.pw')); | ||
}); | ||
|
||
test('GIVEN invalid url THEN returns null', () => { | ||
expect(tryParseURL('thisisnotaurl')).toBeNull(); | ||
}); | ||
}); |
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