forked from evcc-io/evcc
-
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.
chore: optimize bundle size (evcc-io#9464)
- Loading branch information
Showing
7 changed files
with
43 additions
and
55 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 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,7 @@ | ||
export default function linkify(text) { | ||
const urlRegex = /https?:\/\/[^\s]+/g; | ||
|
||
return text.replace(urlRegex, function (url) { | ||
return `<a href="${url}" target="_blank">${url}</a>`; | ||
}); | ||
} |
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,25 @@ | ||
import linkify from "./linkify"; | ||
import { describe, expect, test } from "vitest"; | ||
|
||
describe("linkify", () => { | ||
test("should wrap links", () => { | ||
expect(linkify("https://example.com")).eq( | ||
`<a href="https://example.com" target="_blank">https://example.com</a>` | ||
); | ||
}); | ||
test("with surrounding text", () => { | ||
expect(linkify("hello http://foo.bar/ world")).eq( | ||
`hello <a href="http://foo.bar/" target="_blank">http://foo.bar/</a> world` | ||
); | ||
}); | ||
test("with query and hash", () => { | ||
expect(linkify("a http://b.c/?d=e#f g")).eq( | ||
`a <a href="http://b.c/?d=e#f" target="_blank">http://b.c/?d=e#f</a> g` | ||
); | ||
}); | ||
test("with multiple links", () => { | ||
expect(linkify("hello http://foo.bar/ world https://bar.baz/ tadda!")).eq( | ||
`hello <a href="http://foo.bar/" target="_blank">http://foo.bar/</a> world <a href="https://bar.baz/" target="_blank">https://bar.baz/</a> tadda!` | ||
); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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