-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
684 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
/doc | ||
# Compiled output | ||
/dist | ||
/tmp | ||
|
Large diffs are not rendered by default.
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
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
15 changes: 15 additions & 0 deletions
15
projects/fs-validatorts/src/lib/validators/isURLFragmentContained.spec.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isURLFragmentContained } from './isURLFragmentContained'; | ||
|
||
let urlA = 'http://example.com/aa/bb/'; | ||
let urlD = 'http://example.com/aa/bb#fragment'; | ||
let urlE = 'http://example.com/aa/bb?a=1;b=2&c=3'; | ||
|
||
it(`should be true`, () => { | ||
expect(isURLFragmentContained(urlA, '').value).toBeTruthy(); | ||
expect(isURLFragmentContained(urlE, '').value).toBeTruthy(); | ||
expect(isURLFragmentContained(urlD, 'fragment').value).toBeTruthy(); | ||
}); | ||
it(`should be false`, () => { | ||
expect(isURLFragmentContained(urlA, '/').value).toBeFalsy(); | ||
expect(isURLFragmentContained(urlA, '/dd').value).toBeFalsy(); | ||
}); |
67 changes: 67 additions & 0 deletions
67
projects/fs-validatorts/src/lib/validators/isURLFragmentContained.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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { MessageFunctionType, Result } from '../types'; | ||
import { isString } from './isString'; | ||
|
||
export interface IsURLFragmentContainedErrors { | ||
URL_ARGUMENT_NOT_A_STRING: MessageFunctionType; | ||
FRAGMENT_ARGUMENT_NOT_A_STRING: MessageFunctionType; | ||
} | ||
|
||
export const IS_URL_FRAGMENT_CONTAINED_ERRORS: IsURLFragmentContainedErrors = { | ||
URL_ARGUMENT_NOT_A_STRING: (arr?: string[]) => { | ||
return `The URL argument ${arr![0]} is not a string.`; | ||
}, | ||
FRAGMENT_ARGUMENT_NOT_A_STRING: (arr?: string[]) => { | ||
return `The fragment argument ${arr![0]} is not a string.`; | ||
}, | ||
}; | ||
|
||
/** | ||
* Checks whether the `url` path | ||
* contains the `fragment` argument. | ||
* | ||
* Note that if the URL fragment does not | ||
* exist, then Javascript considers | ||
* the fragment to be an empty string or | ||
* ''. | ||
* | ||
* So if the fragment argument is also an | ||
* empty string, the validation result will | ||
* be true as an empty string contains and empty | ||
* string. | ||
* | ||
* Also Note that the validation of the url | ||
* argument should be performed before passing | ||
* the `url` argument to this validation. | ||
* | ||
* ### Example | ||
* ``` | ||
* expect(isURLPathsEqual(urlA, "/aa/bb/").value).toBeTruthy(); | ||
* ``` | ||
* @param url The url string | ||
* @param path The path string | ||
*/ | ||
export function isURLFragmentContained( | ||
url: string, | ||
fragment: string | ||
): Result<boolean | undefined> { | ||
if (!isString(url).value) { | ||
return new Result( | ||
undefined, | ||
IS_URL_FRAGMENT_CONTAINED_ERRORS.URL_ARGUMENT_NOT_A_STRING, | ||
[url] | ||
); | ||
} | ||
if (!isString(fragment).value) { | ||
return new Result( | ||
undefined, | ||
IS_URL_FRAGMENT_CONTAINED_ERRORS.FRAGMENT_ARGUMENT_NOT_A_STRING, | ||
[fragment] | ||
); | ||
} | ||
|
||
const hash = new URL(url).hash; | ||
if (hash) { | ||
return new Result(new URL(url).hash.substring(1).includes(fragment)); | ||
} | ||
return new Result(''.includes(fragment)); | ||
} |
15 changes: 15 additions & 0 deletions
15
projects/fs-validatorts/src/lib/validators/isURLFragmentEqual.spec.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isURLFragmentEqual } from './isURLFragmentEqual'; | ||
|
||
let urlA = 'http://example.com/aa/bb/'; | ||
let urlD = 'http://example.com/aa/bb#fragment'; | ||
let urlE = 'http://example.com/aa/bb?a=1;b=2&c=3'; | ||
|
||
it(`should be true`, () => { | ||
expect(isURLFragmentEqual(urlA, '').value).toBeTruthy(); | ||
expect(isURLFragmentEqual(urlE, '').value).toBeTruthy(); | ||
expect(isURLFragmentEqual(urlD, 'fragment').value).toBeTruthy(); | ||
}); | ||
it(`should be false`, () => { | ||
expect(isURLFragmentEqual(urlA, 'cc').value).toBeFalsy(); | ||
expect(isURLFragmentEqual(urlD, '').value).toBeFalsy(); | ||
}); |
56 changes: 56 additions & 0 deletions
56
projects/fs-validatorts/src/lib/validators/isURLFragmentEqual.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { MessageFunctionType, Result } from '../types'; | ||
import { isString } from './isString'; | ||
|
||
export interface IsURLFragmentEqualErrors { | ||
URL_ARGUMENT_NOT_A_STRING: MessageFunctionType; | ||
FRAGMENT_ARGUMENT_NOT_A_STRING: MessageFunctionType; | ||
} | ||
|
||
export const IS_URL_PATH_EQUAL_ERRORS: IsURLFragmentEqualErrors = { | ||
URL_ARGUMENT_NOT_A_STRING: (arr?: string[]) => { | ||
return `The URL argument ${arr![0]} is not a string.`; | ||
}, | ||
FRAGMENT_ARGUMENT_NOT_A_STRING: (arr?: string[]) => { | ||
return `The fragment argument ${arr![0]} is not a string.`; | ||
}, | ||
}; | ||
|
||
/** | ||
* Checks whether the `url` fragment | ||
* is equal to the `fragment` argument. | ||
* | ||
* Note that the validation of the url | ||
* argument should be performed before passing | ||
* the `url` argument to this validation. | ||
* | ||
* ### Example | ||
* ``` | ||
* expect(isURLFragmentEqual(urlA, "/aa/bb/").value).toBeTruthy(); | ||
* ``` | ||
* @param url The url string | ||
* @param fragment The fragment string | ||
*/ | ||
export function isURLFragmentEqual( | ||
url: string, | ||
fragment: string | ||
): Result<boolean | undefined> { | ||
if (!isString(url).value) { | ||
return new Result( | ||
undefined, | ||
IS_URL_PATH_EQUAL_ERRORS.URL_ARGUMENT_NOT_A_STRING, | ||
[url] | ||
); | ||
} | ||
if (!isString(fragment).value) { | ||
return new Result( | ||
undefined, | ||
IS_URL_PATH_EQUAL_ERRORS.FRAGMENT_ARGUMENT_NOT_A_STRING, | ||
[fragment] | ||
); | ||
} | ||
const hash = new URL(url).hash; | ||
if (hash) { | ||
return new Result(fragment === new URL(url).hash.substring(1)); | ||
} | ||
return new Result(fragment === ''); | ||
} |
22 changes: 22 additions & 0 deletions
22
projects/fs-validatorts/src/lib/validators/isURLPathContained.spec.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { isURLPathContained } from './isURLPathContained'; | ||
|
||
let urlA = 'http://example.com/aa/bb/'; | ||
let urlB = 'http://example.com/'; | ||
let urlC = 'http://example.com'; | ||
let urlD = 'http://example.com/aa/bb#fragment'; | ||
let urlE = 'http://example.com/aa/bb?a=1;b=2&c=3'; | ||
|
||
it(`should be true`, () => { | ||
expect(isURLPathContained(urlA, '/aa/bb/').value).toBeTruthy(); | ||
expect(isURLPathContained(urlA, '/aa/b').value).toBeTruthy(); | ||
expect(isURLPathContained(urlD, '/aa/bb').value).toBeTruthy(); | ||
expect(isURLPathContained(urlD, '/aa/b').value).toBeTruthy(); | ||
expect(isURLPathContained(urlE, '/aa/bb').value).toBeTruthy(); | ||
expect(isURLPathContained(urlE, '/aa/b').value).toBeTruthy(); | ||
expect(isURLPathContained(urlB, '/').value).toBeTruthy(); | ||
expect(isURLPathContained(urlC, '/').value).toBeTruthy(); | ||
}); | ||
it(`should be false`, () => { | ||
expect(isURLPathContained(urlA, '/aa/bb/cc').value).toBeFalsy(); | ||
expect(isURLPathContained(urlA, '/dd').value).toBeFalsy(); | ||
}); |
52 changes: 52 additions & 0 deletions
52
projects/fs-validatorts/src/lib/validators/isURLPathContained.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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { MessageFunctionType, Result } from '../types'; | ||
import { isString } from './isString'; | ||
|
||
export interface IsURLPathContainedErrors { | ||
URL_ARGUMENT_NOT_A_STRING: MessageFunctionType; | ||
PATH_ARGUMENT_NOT_A_STRING: MessageFunctionType; | ||
} | ||
|
||
export const IS_URL_PATH_CONTAINED_ERRORS: IsURLPathContainedErrors = { | ||
URL_ARGUMENT_NOT_A_STRING: (arr?: string[]) => { | ||
return `The URL argument ${arr![0]} is not a string.`; | ||
}, | ||
PATH_ARGUMENT_NOT_A_STRING: (arr?: string[]) => { | ||
return `The paths argument ${arr![0]} is not a string.`; | ||
}, | ||
}; | ||
|
||
/** | ||
* Checks whether the `url` path | ||
* contains the `path` argument. | ||
* | ||
* Note that the validation of the url | ||
* argument should be performed before passing | ||
* the `url` argument to this validation. | ||
* | ||
* ### Example | ||
* ``` | ||
* expect(isURLPathsEqual(urlA, "/aa/bb/").value).toBeTruthy(); | ||
* ``` | ||
* @param url The url string | ||
* @param path The path string | ||
*/ | ||
export function isURLPathContained( | ||
url: string, | ||
path: string | ||
): Result<boolean | undefined> { | ||
if (!isString(url).value) { | ||
return new Result( | ||
undefined, | ||
IS_URL_PATH_CONTAINED_ERRORS.URL_ARGUMENT_NOT_A_STRING, | ||
[url] | ||
); | ||
} | ||
if (!isString(path).value) { | ||
return new Result( | ||
undefined, | ||
IS_URL_PATH_CONTAINED_ERRORS.PATH_ARGUMENT_NOT_A_STRING, | ||
[path] | ||
); | ||
} | ||
return new Result(new URL(url).pathname.includes(path)); | ||
} |
20 changes: 20 additions & 0 deletions
20
projects/fs-validatorts/src/lib/validators/isURLPathEqual.spec.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isURLPathEqual } from "./isURLPathEqual"; | ||
|
||
let urlA = "http://example.com/aa/bb/" | ||
let urlB = "http://example.com/" | ||
let urlC = "http://example.com" | ||
let urlD = 'http://example.com/aa/bb#fragment'; | ||
let urlE = 'http://example.com/aa/bb?a=1;b=2&c=3'; | ||
|
||
|
||
it(`should be true`, () => { | ||
expect(isURLPathEqual(urlA, "/aa/bb/").value).toBeTruthy(); | ||
expect(isURLPathEqual(urlB, "/").value).toBeTruthy(); | ||
expect(isURLPathEqual(urlC, "/").value).toBeTruthy(); | ||
expect(isURLPathEqual(urlD, "/aa/bb").value).toBeTruthy(); | ||
expect(isURLPathEqual(urlE, "/aa/bb").value).toBeTruthy(); | ||
}) | ||
it(`should be false`, () => { | ||
expect(isURLPathEqual(urlA, "/aa/bb/cc").value).toBeFalsy(); | ||
expect(isURLPathEqual(urlC, "").value).toBeFalsy(); | ||
}) |
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
15 changes: 0 additions & 15 deletions
15
projects/fs-validatorts/src/lib/validators/isURLPathsEqual.spec.ts
This file was deleted.
Oops, something went wrong.