psd
Version:
A general purpose Photoshop file parser.
45 lines (31 loc) • 996 B
text/coffeescript
_ = require 'lodash'
module.exports =
root: ->
return @ if
return .root()
isRoot: -> is 0
children: ->
ancestors: ->
return [] if not ? or .isRoot()
return .ancestors().concat []
hasChildren: -> .length > 0
childless: -> not
siblings: ->
return [] unless ?
.children()
nextSibling: ->
return null unless ?
index = .indexOf(@)
[index + 1]
prevSibling: ->
return null unless ?
index = .indexOf(@)
[index - 1]
hasSiblings: -> .length > 1
onlyChild: -> not
descendants: -> _.flatten .map((n) -> n.subtree())
subtree: -> [@].concat
depth: -> .length + 1
path: (asArray = false) ->
path = .map((n) -> n.name).concat([])
if asArray then path else path.join('/')