JustalK / PORNHUB-API

A powerful and complete scrapper for the very famous pornhub.com. This javascript module for node give you the possibility, through an API with many options, to scrap any information out of a page or the search page.
MIT License
133 stars 28 forks source link

Fixed (probably) a typo in src/model.js #29

Closed North-West-Wind closed 3 years ago

JustalK commented 3 years ago

Hello,

It's not a typo error. It's the optionnal chaining that has been finally added in the node v14. Our two lines are not doing the same :

const match = datas.VIDEO_NUMBER?.match(/(?<=of )\d+/gi, '');
const match = datas.VIDEO_NUMBER.match(/(?<=of )\d+/gi, '');

The first one :

const match = datas.VIDEO_NUMBER?.match(/(?<=of )\d+/gi, '');

Could be done in node v12 or under like this :

const match = datas.VIDEO_NUMBER === null || datas.VIDEO_NUMBER === undefined ? null : datas.VIDEO_NUMBER.match(/(?<=of )\d+/gi, '');

It tests first that the datas.VIDEO_NUMBER exists and has been defined for applying the match function.

If you want more informations about it : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

Why I am using that instead of the v12 version that could give me a better compatibility ? Because the latest LTS version of Node is v14, so everyone should turn to that version. And also, I wanna try Node v14. I am already coding at my work in Node v14, Node v12 and Node v8 syntax ;)

But nice that someone see it :)

North-West-Wind commented 3 years ago

I created this pr because I'm using Node v12, but now I guess I'll just create my own fork for Node <= 12

JustalK commented 3 years ago

Oh ! I see.

You actually make me rethink about it, I will make it Node v12 and Node v10 compatible over the weekend.

Node v10 is still on until mid next year and Node v12 until April 2022. So after second thoughts, it would be nice to support it too.

JustalK commented 3 years ago

I did not see that you push a correction to your first fix.

const match = datas.VIDEO_NUMBER === null || datas.VIDEO_NUMBER === undefined ? null : datas.VIDEO_NUMBER.match(/(?<=of )\d+/gi, '');
datas.VIDEO_NUMBER = match[0];

It's the idea but it will break. If datas.VIDEO_NUMBER is null. You will give to match a null value. In the next line you will try to access the index 0 of match. Crash.

I fixed it in #30 if you are curious ;)