-
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
#lang racket/base
|
||||
|
||||
(require racket/string
|
||||
racket/port
|
||||
json
|
||||
)
|
||||
|
||||
(provide while
|
||||
until
|
||||
get-lib-path
|
||||
do-for
|
||||
esc-quote
|
||||
esc-double-quote
|
||||
fromJson
|
||||
mk-js-array
|
||||
js-code
|
||||
list-of-kv?
|
||||
)
|
||||
|
||||
(define-syntax while
|
||||
@@ -61,4 +71,47 @@
|
||||
[else
|
||||
(error (format "Install the shared library: ~a" lib))]
|
||||
)))
|
||||
|
||||
(define (esc-quote str)
|
||||
(string-replace str "'" "\\'"))
|
||||
|
||||
(define (esc-double-quote str)
|
||||
(string-replace str "\"" "\\\""))
|
||||
|
||||
(define (fromJson str)
|
||||
(with-input-from-string str read-json))
|
||||
|
||||
(define (mk-js-array l)
|
||||
(if (list? l)
|
||||
(string-append "[ " (string-join (map (λ (e) (format "'~a'"
|
||||
(esc-quote (format "~a" e)))) l) ", ") " ]")
|
||||
(format "[ '~a' ]" (esc-quote (format "~a" l)))
|
||||
)
|
||||
)
|
||||
|
||||
(define (js-code . a)
|
||||
(define (code* l)
|
||||
(if (null? l)
|
||||
""
|
||||
(string-append (car l) "\n" (code* (cdr l)))
|
||||
)
|
||||
)
|
||||
(code* a))
|
||||
|
||||
|
||||
(define (list-of-kv? l)
|
||||
(define (kv? e)
|
||||
(let ((e (car l)))
|
||||
(and (list? e)
|
||||
(= (length e) 2)
|
||||
(symbol? (car e)))))
|
||||
(define (all-kv? l)
|
||||
(if (null? l)
|
||||
#t
|
||||
(if (kv? (car e))
|
||||
(all-kv? (cdr l))
|
||||
#f)))
|
||||
(if (list? l)
|
||||
(all-kv? l)
|
||||
#f))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user