-
Notifications
You must be signed in to change notification settings - Fork 126
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
129568b
commit f59a309
Showing
6 changed files
with
55 additions
and
4 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,9 @@ | ||
const getLink = str => { | ||
const containsLink = str.match(/\(https?:(.*)\)/); | ||
|
||
return containsLink ? containsLink[0].replace('(', '').replace(')', '') : ''; | ||
}; | ||
|
||
module.exports = { | ||
getLink | ||
}; |
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,18 @@ | ||
/* eslint-env mocha */ | ||
const {expect} = require('chai'); | ||
const {getLink} = require('../lib/string-utils'); | ||
|
||
describe('stringUtils module', () => { | ||
describe('getLink method', () => { | ||
it('should return the url from a string', () => { | ||
const str = `Consider lazy - loading offscreen and hidden images after all critical resources | ||
have finished loading to lower time to interactive. [Learn more](https://web.dev/offscreen-images).`; | ||
expect(getLink(str)).to.eql('https://web.dev/offscreen-images'); | ||
}); | ||
it('should return an empty string when it does not contain an url', () => { | ||
const str = `Consider lazy - loading offscreen and hidden images after all critical resources | ||
have finished loading to lower time to interactive.`; | ||
expect(getLink(str)).to.eql(''); | ||
}); | ||
}); | ||
}); |