Node

Node

Abstract class that it's used by all other classes, providing basic functionalities.

Constructor

(abstract) new Node(parent, data)

Source:
Parameters:
Name Type Description
parent Node | Sketch The parent of the element
data Object The raw data from the sketch file

Members

parent

Source:
Returns the parent element

Methods

clone(parent) → {Node}

Source:
Creates a deep clone of this node
Parameters:
Name Type Description
parent Node | undefined The new parent of the clone. If it's not defined use the current parent.
Returns:
Type
Node

detach() → {Node}

Source:
Removes the node from its parent
Returns:
Type
Node

get(type, conditionopt) → {Node|undefined}

Source:
Search and returns the first descendant node that match the type and condition.
Parameters:
Name Type Attributes Description
type String The Node type
condition function | String <optional>
The node name or a callback to be executed on each node that must return true or false. If it's not provided, only the type argument is be used.
Returns:
Type
Node | undefined

getAll(type, conditionopt) → {Array.<Node>}

Source:
Search and returns all descendant nodes matching with the type and condition.
Example
//Get the first page
const page = sketch.pages[0];

//Get all colors found in this page
const colors = page.getAll('color');

//Get all colors with specific values
const blueColors = page.getAll('color', (color) => {
 return color.blue > 0.5 && color.red < 0.33
});
Parameters:
Name Type Attributes Description
type String The Node type
condition function | String <optional>
The node name or a callback to be executed on each node that must return true or false. If it's not provided, only the type argument is be used.
Returns:
Type
Array.<Node>

getParent(typeopt, conditionopt) → {Node|Sketch|undefined}

Source:
Find a node ascendent matching with the type and condition
Parameters:
Name Type Attributes Description
type String <optional>
The node type
condition function | String <optional>
The node name or a callback to be executed on each parent and must return true or false. If it's not provided, only the type argument is be used.
Returns:
Type
Node | Sketch | undefined

getSketch() → {Sketch|undefined}

Source:
Get the sketch element associated with this node
Returns:
Type
Sketch | undefined

push(key, node) → {Node}

Source:
Push a new children in this node
Parameters:
Name Type Description
key string The node key
node Node | Object The node/s to insert
Returns:
The new node inserted
Type
Node

replaceWith(node) → {Node}

Source:
Replace this node with other
Parameters:
Name Type Description
node Node The node to use
Returns:
The new node
Type
Node

set(key, node)

Source:
Add/replace new childrens in this node
Parameters:
Name Type Description
key string The node key
node Node | Object | Array The node/s to insert

toJson() → {Object}

Source:
Returns a json with the node data
Returns:
Type
Object