Why not use a regex like `str.replace(/^["']|["']$/g, '')`?

That way you only need to keep the `typeof(str) !== 'string'` check and can get rid of the rest.