This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do (String) -> | |
String::contains or= (searchString, position = 0) -> @toString().indexOf(searchString) >= position | |
String::startsWith or= (searchString, position = 0) -> @toString.toString().indexOf(searchString) >= position | |
String::endsWith or= (searchString, position = @length) -> @toString().lastIndexOf(searchString) is position - searchString.length | |
String::repeat or= (count) -> | |
newString = '' | |
newString += @toString() for [1..count] | |
newString | |
String::toArray or= -> @toString().split '' | |
String::reverse or= -> @toArray().reverse().join '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bind = (func, context) -> -> func.apply(context, arguments) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toQueryString = (obj) -> | |
queryArray = [] | |
for key, value of obj | |
queryArray.push "#{key}=#{value}" | |
queryArray.join('&') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chainedOp = (obj) -> | |
result = {} | |
resultFunc = (i) -> | |
if Array.isArray obj | |
(result[i] = -> @) for i in obj | |
else | |
for key, value of obj | |
if typeof value is 'function' | |
result[key] = (args... ) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do (root = if exports? and module.exports? then module.exports else @) -> | |
class root.StringReader | |
constructor: (@input) -> | |
@buffer = "" | |
@reset() | |
readUntil: (character, omitCharacter = false, notFoundFn) -> | |
loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StringReader | |
buffer = "" | |
constructor: (@input) -> | |
@reset() | |
readUntil: (character, omitCharacter = false, notFoundFn) -> | |
loop | |
if @end() | |
notFoundFn(buffer) if notFoundFn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1 | |
# Adding properteies to Component instances | |
console.log '--- Example 1 ---' | |
comp1 = new Component('comp1') | |
comp1.test = -> console.log 'Comp1' | |
comp2 = new Component('comp2') | |
comp2.test = -> console.log 'Comp2' | |
myEntity = new Entity('myEntity') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StringReader | |
buffer = "" | |
constructor: (@input) -> | |
@reset() | |
readUntil: (character, omitCharacter = false) -> | |
loop | |
break if @currentIndex is @input.length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
path = require 'path' | |
coffeeScript = require 'coffee-script' | |
convertCSON = (csonObject) -> | |
return unless csonObject? | |
completeObject = | |
"csonObject = { | |
#{csonObject} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entity | |
componentList = {} | |
constructor: (@name = @constructor.name) -> | |
get: (componentName) -> | |
if componentName | |
componentList[componentName] | |
else | |
Object.keys componentList |