Added node-modules

This commit is contained in:
Dobie Wollert
2014-09-14 07:04:16 -04:00
parent 663941bf57
commit 6a92348cf5
4870 changed files with 670395 additions and 0 deletions

40
node_modules/piler/lib/serialize.coffee generated vendored Normal file
View File

@ -0,0 +1,40 @@
# Remove last comma from string
removeTrailingComma = (s) ->
s.trim().replace(/,$/, "")
# Map of functions that can convert various Javascript objects to strings.
types =
function: (fn) -> "#{ fn }"
string: (s) -> JSON.stringify s # Knows how to correctly serialize strings to String literals
number: (n) -> n.toString()
boolean: (n) -> n.toString()
object: (obj) ->
# typeof reports array as object
return this._array obj if Array.isArray obj
code = "{"
code += "\"#{ k }\": #{ codeFrom v }," for k, v of obj
removeTrailingComma(code) + "}"
_array: (array) ->
code = "["
code += " #{ codeFrom v }," for v in array
removeTrailingComma(code) + "]"
# Generates code string from given object. Works for numbers, strings, regexes
# and even functions. Does not handle circular references.
exports.stringify = codeFrom = (obj) ->
types[typeof obj]?(obj)
if require.main is module
console.log exports.stringify
foo: 1
bar:
lol: ":D"
hah: 2