isRTL.coffee library to determine if a text is of right-to-left direction I just wrote this tiny library called isRTL.coffee to determine the direction of the text. Is there any better way of doing this?

rtlChars = '\u0600-\u06FF' # Arabic - Range

rtlChars += '\u0750-\u077F' # Arabic Supplement - Range

rtlChars += '\uFB50-\uFDFF' # Arabic Presentation Forms-A - Range

rtlChars += '\uFE70-\uFEFF' # Arabic Presentation Forms-B - Range

reRTL = new RegExp "^[#{rtlChars}]"

window.isRTL = (value) -&gt;
    if value.match reRTL
        true
    else
        false
Yep, it's possible to improve. You can simply do:

window.isRTL = (value) -&gt;
    reRTL.test value


Another way to improve is the way you declare your special characters. Right now, it's confusing between the = and +=. Here is another way:

rtlChars = [
    '\u0600-\u06FF' # Arabic - Range
    '\u0750-\u077F' # Arabic Supplement - Range
    '\uFB50-\uFDFF' # Arabic Presentation Forms-A - Range
    '\uFE70-\uFEFF' # Arabic Presentation Forms-B - Range
].join("")

reRTL = new RegExp "^[#{rtlChars}]"


This way, adding a new character is simply adding a line in an array.