Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

[Build, Compiler, Refactor] Upgrade typescript and add optional-chaining and nullish-coalescing #4604

Merged
merged 5 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tests/reports
mattermost-webapp.iml
.vscode/
junit.xml
coverage

# disable folders generated by Cypress
e2e/node_modules
Expand Down
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const config = {
'@babel/proposal-object-rest-spread',
'react-hot-loader/babel',
'babel-plugin-typescript-to-proptypes',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator'
],
};

Expand Down
54 changes: 46 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@
"reselect": "4.0.0",
"semver": "6.3.0",
"superagent": "5.1.0",
"typescript": "3.6.4",
"typescript": "3.7.4",
"xregexp": "4.2.4",
"zen-observable": "0.8.14"
},
"devDependencies": {
"@babel/cli": "7.6.4",
"@babel/core": "7.6.4",
"@babel/plugin-proposal-class-properties": "7.5.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.7.4",
"@babel/plugin-proposal-object-rest-spread": "7.6.2",
"@babel/plugin-proposal-optional-chaining": "7.7.5",
"@babel/plugin-syntax-dynamic-import": "7.2.0",
"@babel/preset-env": "7.6.3",
"@babel/preset-react": "7.6.3",
Expand Down
28 changes: 14 additions & 14 deletions utils/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
export const ytRegex = /(?:http|https):\/\/(?:www\.|m\.)?(?:(?:youtube\.com\/(?:(?:v\/)|(?:(?:watch|embed\/watch)(?:\/|.*v=))|(?:embed\/)|(?:user\/[^/]+\/u\/[0-9]\/)))|(?:youtu\.be\/))([^#&?]*)/;

export function handleYoutubeTime(link) {
const timeRegex = /[\\?&](t|start|time_continue)=([0-9]+h)?([0-9]+m)?([0-9]+s?)/;
const timeRegex = /[\\?&](t|time|start|time_continue)=([0-9]+h)?([0-9]+m)?([0-9]+s?)/;

const time = link.match(timeRegex);
if (!time || !time[0]) {
if (!time?.[0]) {
return '';
}

const hours = time[2] ? time[2].match(/([0-9]+)h/) : null;
const minutes = time[3] ? time[3].match(/([0-9]+)m/) : null;
const seconds = time[4] ? time[4].match(/([0-9]+)s?/) : null;
const hours = time[2]?.match(/([0-9]+)h/) ?? null;
const minutes = time[3]?.match(/([0-9]+)m/) ?? null;
const seconds = time[4]?.match(/([0-9]+)s?/) ?? null;

let ticks = 0;
let startSeconds = 0;

if (hours && hours[1]) {
ticks += parseInt(hours[1], 10) * 3600;
if (hours?.[1]) {
startSeconds += parseInt(hours[1], 10) * 3600;
}

if (minutes && minutes[1]) {
ticks += parseInt(minutes[1], 10) * 60;
if (minutes?.[1]) {
startSeconds += parseInt(minutes[1], 10) * 60;
}

if (seconds && seconds[1]) {
ticks += parseInt(seconds[1], 10);
if (seconds?.[1]) {
startSeconds += parseInt(seconds[1], 10);
}

return '&start=' + ticks.toString();
return `&start=${startSeconds}`;
}

export function getVideoId(link) {
Expand All @@ -39,4 +39,4 @@ export function getVideoId(link) {
}

return match[1];
}
}
26 changes: 23 additions & 3 deletions utils/youtube.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {handleYoutubeTime} from 'utils/youtube';

describe('Utils.YOUTUBE', () => {
test('should correctly parse youtube start time formats', () => {
for (const youtube of [
for (const {link, time} of [
{
link: 'https://www.youtube.com/watch?time_continue=490&v=xqCoNej8Zxo',
time: '&start=490',
Expand All @@ -18,8 +18,28 @@ describe('Utils.YOUTUBE', () => {
link: 'https://www.youtube.com/watch?t=490&v=xqCoNej8Zxo',
time: '&start=490',
},
{
link: 'https://www.youtube.com/watch?time=490&v=xqCoNej8Zxo',
time: '&start=490',
},
{
link: 'https://www.youtube.com/watch?time=8m10s&v=xqCoNej8Zxo',
time: '&start=490',
},
{
link: 'https://www.youtube.com/watch?time=1h8m10s&v=xqCoNej8Zxo',
time: '&start=4090',
},
{
link: 'https://www.youtube.com/watch?v=xqCoNej8Zxo',
time: '',
},
{
link: 'https://www.youtube.com/watch?time=&v=xqCoNej8Zxo',
time: '',
},
]) {
expect(handleYoutubeTime(youtube.link)).toEqual(youtube.time);
expect(handleYoutubeTime(link)).toEqual(time);
}
});
});
});