npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sketch-to-svg

v1.2.0

Published

Convert layers in a Sketch file to SVG

Downloads

20

Readme

Sketch to SVG

Exports layers from a .sketch file to an svg, without needing Sketch installed.

Usage as a command

Installation

Install globally npm i sketch-to-svg -g

Or install locally npm i sketch-to-svg (or checkout this repo) and then npm link (to enable the sketch-to-svg command in the terminal)

Examples

  • Export all layers on all pages from my-design.sketch into an 'svg-output' folder in the current folder:
    • sketch-to-svg ./my-design.sketch
  • Export all layers on all pages from my-design.sketch into the /specific/svg/location/ folder:
    • sketch-to-svg ./my-design.sketch ./specific/svg/location/
  • Export all layers from 'Page 1' and 'Page 2' from my-design.sketch into an 'svg-output' folder in the current folder:
    • sketch-to-svg -p 'Page 1' -p 'Page 2' ./my-design.sketch

Documentation

Just running sketch-to-svg will output the help:

export svg from sketch

Positionals:
  sketch  path to the sketch file                                       [string]
  output  output folder - defaults to the current folder
                                             [string] [default: "./svg-output/"]

Options:
  --version    Show version number                                     [boolean]
  --help       Show help                                               [boolean]
  --pages, -p  pages to export (default is all pages)```

## Usage as a library

```javascript
/// At the moment you need to pass in a sketch-constructor layer.
const { Sketch } = require('sketch-constructor')

/// Require the library
const svg = require('sketch-to-svg')

// Open the sketch file and pass in the layer you want to extract
let absolutePath = `${process.cwd()}` + "/mysketchfile.sketch"
Sketch
        .fromFile(absolutePath)
        .then(sketch => {
          /// Get the layer you want to extract - this example extracts the first layer in the first page
          let layer = sketch.getPages()[0].layers[0]

          let options = { sketchFilePath: absolutePath, optimizeImageSize: true, optimizeImageSizeFactor: 3 }

          return svg.createFromLayer(layer, options)
        })
        .then(icon => {
          // For this example, we just dump the svg to the console
          console.log(icon.svg)
        })
        .catch(err => {
            console.log("Failed to create svg:", err)
        })

You can see this example in action by checking out the repo and running node example.js.

Development

This is written in Typescript, there's an npm script (build) which will build the library into the dist folder, and a script (npm start) which will run through a few test/example sketch files, exporting them into /out.

If things are going really badly, you can run npm run clobber to start from the start again. This will remove all built code, and all node modules. You'll then have to run npm install again :)