# node-sketch-bridge

> Exposes the macOS APIs needed for generating Sketch files

Latest version **0.2.0** (published 2020-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-sketch-bridge
pnpm add node-sketch-bridge
yarn add node-sketch-bridge
bun add node-sketch-bridge
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-01-20 |
| First published | 2019-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 81.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 2 |
| Author | Devin Abbott |
| Maintainers | dabbott |

## Links

- npm: https://www.npmjs.com/package/node-sketch-bridge
- Repository: https://github.com/Lona/node-sketch-bridge
- Issues: https://github.com/Lona/node-sketch-bridge/issues
- npm.io page: https://npm.io/package/node-sketch-bridge

## Dependencies (1)

- [node-gyp-build](https://npm.io/package/node-gyp-build.md) ^3.3.0

## Recent versions

- 0.2.0 (latest) — 2020-01-20
- 0.1.0 — 2019-11-13
- 0.0.3 — 2019-11-13
- 0.0.2 — 2019-11-13
- 0.0.1 — 2019-11-12

## README

# Node Sketch Bridge

This package exposes the macOS APIs needed for generating Sketch files. It relies on a node native module written in Obj-C.

```
npm install --save node-sketch-bridge
```

## API

### `findFontName`

```js
const { findFontName } = require("node-sketch-bridge");

const fontName = findFontName({
  fontFamily: "Helvetica",
  fontStyle: "italic"
});

console.log(fontName); // "Helvetica-Oblique"
```

:warning: Caveats:

- If the `fontFamily` property is missing, or the requested font is not installed, it will fall back to the default system
  provided by the OS (usually, something from the _San Francisco_ family). The specific font returned changes across
  macOS versions and for different font sizes.

### `createStringMeasurer`

```js
const { createStringMeasurer } = require("node-sketch-bridge");

const size = createStringMeasurer(
  [
    {
      content: "Hello",
      textStyles: {
        fontFamily: "Helvetica",
        fontSize: 16,
        fontWeight: "bold",
        fontStyle: "italic",
        lineHeight: 23,
        letterSpacing: 1,
        textDecoration: "underline",
        textAlign: "left"
      }
    }
  ],
  400
);

console.log(size); // "{ width: ..., height: ... }"
```

:warning: Caveats:

- When the `lineHeight` property is not specified, the default used by this function may be different from what Sketch
  uses by default for certain font families. This might result in a bounding box calculation that is different from
  what Sketch would display. For best results, it's advised to always specify the `lineHeight` explicitly.
- Support for `textTransform` property is missing at the moment. When specified, the requested text transformation
  will not be taken into account when computing the bounding box.

### `makeImageDataFromURL`

```js
const { makeImageDataFromURL } = require("node-sketch-bridge");

const base64EncodedImage = makeImageDataFromURL("https://placekitten.com/200/300");

// The buffer will contain the PNG-encoded image of a kitten. Meow.
const imageBuffer = Buffer.from(base64EncodedImage, "base64");
```

## Development

First, run `npm install`.

To develop in Xcode, you'll need to generate an Xcode project. The following worked for me on Mojave:

```bash
npm install --global node-gyp

node-gyp --python /usr/local/bin/python2 configure -- -f xcode

node-gyp build
```

Then, `open build/binding.xcodeproj`.

## License

MIT

---
_Source: https://npm.io/package/node-sketch-bridge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
