Comments

# This is a single line comment
/* This is a
multi line comment */

Numbers

42
42km
3.754km_2
16~BadFace
36~azertyuiop0123456789

Strings and interpolation

''
''''''
""
""""""
'Foo \' bar
	baz'
'''Foo \''' bar
	bar'''
"Foo #bar \"
	#{2 + 2}\""
"""#foobar \""" #{ if /test/ == 'test' then 3 else 4}
	baz"""

Regex

/foobar/ig
//
^foo # foo
[bar]*bA?z # barbaz
//m

Full example

# example from Str.ls

split = (sep, str) -->
  str.split sep

join = (sep, xs) -->
  xs.join sep

lines = (str) ->
  return [] unless str.length
  str.split '\n'

unlines = (.join '\n')

words = (str) ->
  return [] unless str.length
  str.split /[ ]+/

unwords = (.join ' ')

chars = (.split '')

unchars = (.join '')

reverse = (str) ->
  str.split '' .reverse!.join ''

repeat = (n, str) -->
  result = ''
  for til n
    result += str
  result

capitalize = (str) ->
  (str.char-at 0).to-upper-case! + str.slice 1

camelize = (.replace /[-_]+(.)?/g, (, c) -> (c ? '').to-upper-case!)

# convert camelCase to camel-case, and setJSON to set-JSON
dasherize = (str) ->
    str
      .replace /([^-A-Z])([A-Z]+)/g, (, lower, upper) ->
         "#{lower}-#{if upper.length > 1 then upper else upper.to-lower-case!}"
      .replace /^([A-Z]+)/, (, upper) ->
         if upper.length > 1 then "#upper-" else upper.to-lower-case!

module.exports = {
  split, join, lines, unlines, words, unwords, chars, unchars, reverse,
  repeat, capitalize, camelize, dasherize,
}