This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A basic example of how Ruby's constantize _could_ work in JS | |
// See https://apidock.com/rails/String/constantize | |
function constantize (str) { | |
if (typeof str !== 'string') { | |
throw new TypeError('must pass in type of string'); | |
} | |
if (str.match(/\W|\d/)) { | |
throw new SyntaxError('must pass in a valid Javascript name'); | |
} |