All Projects â†’ oscarotero â†’ Node Sketch

oscarotero / Node Sketch

Licence: mit
💎 Javascript library to manipulate sketch files

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Sketch

Overrideit Sketchplugin
Overrideit is sketch plugin that allow designers to search in overridelist and overrides dropdowns, and with many other features.
Stars: ✭ 113 (-58.61%)
Mutual labels:  sketchapp, sketch
Sketchcontentsync
Sync sketch files with google docs.
Stars: ✭ 270 (-1.1%)
Mutual labels:  sketchapp, sketch
Sketch Json
Transform sketch files to json and json to sketch files
Stars: ✭ 113 (-58.61%)
Mutual labels:  sketchapp, sketch
Sketch Foundation Kit
💎 The Foundation for Sites template for Sketch 3.
Stars: ✭ 1,011 (+270.33%)
Mutual labels:  sketchapp, sketch
sketch-data-faker
A Sketch plugin providing 130+ types of smart placeholder content for your mockups from Faker.js and other sources.
Stars: ✭ 62 (-77.29%)
Mutual labels:  sketch, sketchapp
Persiansupplier
Sketch Plugin for supplying dynamic persian data.
Stars: ✭ 46 (-83.15%)
Mutual labels:  sketchapp, sketch
Sketch Batch Create Symbols
A plugin for Sketch to convert selected layers to individual symbols.
Stars: ✭ 134 (-50.92%)
Mutual labels:  sketchapp, sketch
Sketch Find And Replace
Sketch plugin to do a find and replace on text within layers
Stars: ✭ 693 (+153.85%)
Mutual labels:  sketchapp, sketch
SketchStrap
SketchStrap - Bootstrap customizer
Stars: ✭ 42 (-84.62%)
Mutual labels:  sketch, sketchapp
Sketchcrapp
SketchCrapp - Crack your Sketch.app in seconds :) Supports MacOS Big Sur.
Stars: ✭ 218 (-20.15%)
Mutual labels:  sketchapp, sketch
React Sketchapp Starter Kit
Initial Setup for React Sketchapp Project
Stars: ✭ 27 (-90.11%)
Mutual labels:  sketchapp, sketch
autopdfexporter-sketch-plugin
A Sketch Plugin to auto-export all '[S]' Prefix artboards to a single pdf, no slices needed! Plugin auto creates slices from prefixed Artboards and exports them into a single page-sorted pdf file.
Stars: ✭ 16 (-94.14%)
Mutual labels:  sketch, sketchapp
Sketch Web Viewer
View and inspect Sketch 43 files in browser
Stars: ✭ 853 (+212.45%)
Mutual labels:  sketchapp, sketch
Notes
A sketch plugin for taking notes
Stars: ✭ 87 (-68.13%)
Mutual labels:  sketchapp, sketch
Sketch Commands
A collection of script commands for Sketch.app
Stars: ✭ 826 (+202.56%)
Mutual labels:  sketchapp, sketch
Data Populator
A plugin for Sketch and Adobe XD to populate your design mockups with meaningful data. Goodbye Lorem Ipsum. Hello JSON.
Stars: ✭ 1,665 (+509.89%)
Mutual labels:  sketchapp, sketch
Sync.sketchplugin
Keep your design team in sync!
Stars: ✭ 357 (+30.77%)
Mutual labels:  sketchapp, sketch
Html Sketchapp Cli
Quickly generate Sketch libraries from HTML documents and living style guides, powered by html-sketchapp
Stars: ✭ 631 (+131.14%)
Mutual labels:  sketchapp, sketch
Paddy Sketch Plugin
Automated padding, spacing and alignment for your Sketch layers
Stars: ✭ 2,219 (+712.82%)
Mutual labels:  sketchapp, sketch
sketch-dark-mode
Generate a dark mode version of any Sketch document, the right way.
Stars: ✭ 58 (-78.75%)
Mutual labels:  sketch, sketchapp

💎 node-sketch

Javascript library to manipulate sketch files

Build Status

Install

npm install node-sketch

Example:

const ns = require('node-sketch');

async function run() {
    const sketch = await ns.read(__dirname + '/design.sketch');

    //Search the symbol named 'button'
    const buttonSymbol = sketch.symbolsPage.get('symbolMaster', 'button');

    //Search all instances of a symbol named 'old-button' and replace it with 'button'
    const firstPage = sketch.pages[0];
    
    firstPage
        .getAll('symbolInstance', instance => instance.symbolMaster.name === 'old-button')
        .forEach(instance => instance.symbolMaster = buttonSymbol);

    //Save the result
    sketch.save('modified-design.sketch')
        .then(console.log('File saved!!'));
}

run();

API

Two classes are used to manage sketch files:

Sketch

Represents the sketch file and contains all data (pages, symbols, styles, shapes, etc). Contains the method .save() to create a sketch file with the result.

const ns = require('node-sketch');

ns.read('input.sketch').then(sketch => {
    sketch.document           // document data
    sketch.meta               // meta data
    sketch.user               // user data
    sketch.pages              // array with all pages
    sketch.symbolsPage        // the Symbols page
    sketch.layerStyles        // array with the layer styles
    sketch.textStyles         // array with the text styles
    sketch.colors             // array containing the colors stored in the color palette
    sketch.gradients          // array containing the gradients stored in the gradient palette
    sketch.symbols            // array with all symbols stored in the document

    sketch.foreignSymbols     // array with the symbols loaded from external libraries
    sketch.foreignLayerStyles // array with the layer styles loaded from external libraries
    sketch.foreignTextStyles  // array with the text styles loaded from external libraries

    sketch.save('output.sketch');
});

Node

It's the base class used by all other elements. Any page, symbol, color, etc is an instance of this class.

const symbolsPage = sketch.symbolsPage;

console.log(symbolsPage instanceof Node); //true 

//It include useful methods to search an inner node by class:
const button = symbolsPage.get('symbolMaster');

//by class and name
const button = symbolsPage.get('symbolMaster', 'button');

//by class and callback
const button = symbolsPage.get('symbolMaster', symbol => symbol.name === 'button');

//Just a callback
const button = symbolsPage.get(node => node._class === 'symbolMaster' && node.name === 'button');

//And the same than above but returning all inner nodes instead just the first:
const allSymbols = symbolsPage.getAll('symbolMaster');

There are other classes extending Node to provide special funcionalities in some nodes, like Style or SymbolInstance.

JSON Scheme

Technically, the sketch format consist in a zip with some json files. To manipulate a sketch file with this library, you need to know the scheme of json. You can use this code to read and extract a sketch file into a directory, in order to inspect the json scheme:

const ns = require('../');

ns.read('demo.sketch').then(sketch => sketch.saveDir('demo'));

Here you can see an example of extracted file

CLI

Starting from v0.14.0, the command node-sketch was included to use the library from CLI. You only need a file named node-sketch.js exporting the function to manipulate a sketch file. For example:

module.exports = sketch => {
    //Convert the text style names to uppercase
    sketch.textStyles.forEach(textStyle => {
        textStyle.name = textStyle.name.toUpperCase();
    })
}

To execute this script with the sketch file my-styles.sketch, run node-sketch my-styles.sketch. By default, the file is readed, but not saved. If you want to override the file with the modifications, run node-sketch my-styles.sketch --save.

And to execute a script file with a different name, use the --script argument: node-sketch my-styles.sketch --script=my-script.js --save.


See the API detailed

Or build it locally with npm run docs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].