Skip to content

Instantly share code, notes, and snippets.

@tjphilli
Created April 13, 2016 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjphilli/33875f9b9c4e5265c847ca0b74bc827d to your computer and use it in GitHub Desktop.
Save tjphilli/33875f9b9c4e5265c847ca0b74bc827d to your computer and use it in GitHub Desktop.
Methods to select sublayers of a given layer using substrings
# This method will return the first resulting child layer containing a specified substring
Layer.prototype.childContaining = (str) ->
for layer in @children
return layer if layer.name.indexOf(str) != -1
return -1
# This method will return an array of child layers containing a specified substring
Layer.prototype.childrenContaining = (str) ->
layers = []
for layer in @children
layers.push(layer) if layer.name.indexOf(str) != -1
return layers
# This method will return the first resulting child layer whose name begins with a specified string
Layer.prototype.childStartingWith = (str) ->
for layer in @children
return layer if layer.name.indexOf(str) == 0
return -1
# This method will return an array of child layers whose names begin with a specified string
Layer.prototype.childrenStartingWith = (str) ->
layers = []
for layer in @children
layers.push(layer) if layer.name.indexOf(str) == 0
return layers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment