-
-
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
1 parent
b9bb4c8
commit 724e0ab
Showing
7 changed files
with
79 additions
and
2 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,20 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { curry } from "../deps.ts"; | ||
import { link as _link } from "../uncurry/string/link.ts"; | ||
|
||
/** | ||
* Returns an `<a>` HTML element and sets the href attribute value. | ||
* @param url - href url string | ||
* @param val - Any `String` | ||
* @returns The result of `val.link(url)` | ||
* | ||
* @example | ||
* ```ts | ||
* link('https://google.com', 'google') // '<a href="https://google.com">google</a>' | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
const link = curry(_link); | ||
|
||
export { link }; |
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,9 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { link } from "./link.ts"; | ||
import { assertEqualsType } from "../dev_deps.ts"; | ||
|
||
Deno.test("link", () => { | ||
assertEqualsType<(val: string) => string>(link("")); | ||
assertEqualsType<string>(link("")("")); | ||
assertEqualsType<string>(link("", "")); | ||
}); |
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,27 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
|
||
/** | ||
* @internal | ||
*/ | ||
type Link<T extends string, U extends string> = `\<a href="${T}">${U}\</a>`; | ||
/** | ||
* Returns an `<a>` HTML element and sets the href attribute value. | ||
* @param url - href url string | ||
* @param val - Any `String` | ||
* @returns The result of `val.link(url)` | ||
* | ||
* @example | ||
* ```ts | ||
* link('https://google.com', 'google') // '<a href="https://google.com">google</a>' | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
const link = <T extends string, U extends string>( | ||
url: T, | ||
val: U, | ||
): Link<T, U> => val.link(url) as Link<T, U>; | ||
|
||
export { link }; | ||
export type { Link }; |
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,18 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { assertEquals } from "../../dev_deps.ts"; | ||
import { link } from "./link.ts"; | ||
|
||
Deno.test("link", () => { | ||
const table: [string, string, string][] = [ | ||
["", "", '<a href=""></a>'], | ||
["abc", "", '<a href="abc"></a>'], | ||
["abc", "efg", '<a href="abc">efg</a>'], | ||
]; | ||
table.forEach(([pos, val, expected]) => { | ||
assertEquals( | ||
link(pos, val), | ||
expected, | ||
`link(${pos}, ${val}) -> ${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