Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Replace typeof === "string" with util.isString globally
Browse files Browse the repository at this point in the history
  • Loading branch information
Coriou committed May 22, 2019
1 parent 113ed2a commit e3f4a9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ exports.formatDuration = function (seconds) {
}
return parts.reverse().join(':');
};

/**
* Checks wether str is a string or not
*
* @param {String} str
* @return {Boolean}
*/
exports.isString = str => typeof str === "string";
6 changes: 3 additions & 3 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function processData(data, options, stream) {
const ytdl = module.exports = function (videoUrl, args, options) {
const stream = streamify({ superCtor: http.ClientResponse, readable: true, writable: false });

if (typeof videoUrl !== 'string') {
if (!util.isString(videoUrl)) {
processData(videoUrl, options, stream);
return stream;
}
Expand Down Expand Up @@ -188,7 +188,7 @@ function call(urls, args1, args2, options = {}, callback) {


if (urls !== null) {
if (typeof urls === 'string') {
if (util.isString(urls)) {
urls = [urls];
}

Expand Down Expand Up @@ -239,7 +239,7 @@ ytdl.exec = function exec(url, args, options, callback) {
*/
function parseInfo(data) {
// Youtube-dl might return just an url as a string when using the "-g" or "--get-url" flag
if (typeof data === "string" && data.startsWith("http"))
if (util.isString(data) && data.startsWith("http"))
data = JSON.stringify({url: data});

const info = JSON.parse(data);
Expand Down

0 comments on commit e3f4a9d

Please sign in to comment.