How do you convert the following code to ES6:
const uu = require('url-unshort')();
try {
const url = await uu.expand('https://on.soundcloud.com/EC23');
if (url)
console.log(`Original url is: ${url}`);
else
console.log('This url can\'t be expanded');
} catch (err) {
console.log(err);
}
This snippet is from https://github.com/nodeca/url-unshort, a node package that unshorts links. However, the import/require part made me stumble.
const uu = require('url-unshort')();
I have seen require('')
and import { } from pkg
alone and have used them. But it's my first time to see a require('')
and then besides it another ()
.
To add to my confusion, I think url-unshort
has no modules inside of the package that I can extract using import { } from 'url-unshort'
. I did try the following:
import * as uu from 'url-unshort';
But I think I'm missing a step because it doesn't work still.