js_tools.anubis 928 Bytes
/*
 * Created by PyramIDE.
 * User: フランスのトトロ 
 * Date: 18/04/2015
 * Time: 23:21
 * © Calexium 
 */

read tools/basis.anubis

define List(Word8)
  make_js_string
  (
    List(Word8) current,
    List(Word8) so_far
  )
  =
  if current is
  {
    [ ]     then reverse(so_far),
    [h . t] then 
     make_js_string(t, 
                        if h = '\'' then
                           [h . ['\\' . so_far]]
                        else 
                           [h . so_far]
                   )
  }.

/**
 * Convert a string into certified javascript string (I hope)
 */
public define String
  make_js_string
  (
    String str
  )
  =
  implode(make_js_string(explode(str), [])).
  
public define String
  to_js_string
  (
    String str
  )
  =
  "'" + str + "'".
  
public define String
  format_js_function_call
  (
  	String name,
  	List(String) args
  ) =
  name + "(" + concat(args, ",") + ");".