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
130 stars 29 forks source link

About src/model.js#datas.VIDEO_NUMBER?.match #31

Closed lclancey closed 3 years ago

lclancey commented 3 years ago

Hi I tryed this module(npm install @justalk/pornhub-api) and didn't work on my machine. Node report an error over here:

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

I double checked your code, and found the latest commit changed this code https://github.com/JustalK/PORNHUB-API/commit/b05a887c1baa09aa57c5ea79eb6c8484cc6318e0 so I too rewrited:

if (datas.VIDEO_NUMBER) {
    const match = datas.VIDEO_NUMBER.match(/(?<=of )\d+/gi, '');
    datas.VIDEO_NUMBER = match[0];
}

now works perfectly. My question is what kinda grammar is this (foo?.bar)? Cause I have never seen this kinda grammar before. Thank you.

JustalK commented 3 years ago

Hello, welcome ! I am always happy to help or answer question ;)

So, actually those codes are similar but work for two different versions of Node. In Node v14, the optionnal chaining has been added (https://nodejs.medium.com/node-js-version-14-available-now-8170d384567e). It's part of the V8.1 Javascript. I have been waiting for this new functions for really long so I got a little bit excited and try it it. If you want some information about it, you can find that here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

I came back on my previous commit because multiple person has been using this package and reporting this error. As Node 12 will still be maintained until April 2022. It might be too early to make use of it.

Now, we are at Node V15 and new functionalities has been added. So you might encounter the logical assignment operators from now : ??= or &&= or ||=