All Projects → sketch-hq → sketch-file-format-ts

sketch-hq / sketch-file-format-ts

Licence: MIT License
TypeScript types for the Sketch File Format

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sketch-file-format-ts

sketch-json-cli
Transform sketch files to json and json to sketch files
Stars: ✭ 13 (-69.05%)
Mutual labels:  sketch
Fusion360WrapSketch
Wrap sketch curves around a cylinder
Stars: ✭ 33 (-21.43%)
Mutual labels:  sketch
storybook-addons-abstract
Storybook addon for linking Abstract layer and collection shares to stories. Example:
Stars: ✭ 63 (+50%)
Mutual labels:  sketch
finastra-design-kit
The Finastra Design Kit includes customised Design UI kit, components UI kit, icons, fonts, persona template, etc.
Stars: ✭ 23 (-45.24%)
Mutual labels:  sketch
sketch-markup-listify
Sketch plugin for convert and copy text layers into HTML lists.
Stars: ✭ 31 (-26.19%)
Mutual labels:  sketch
instance-locator
Sketch plugin to locate instances of a symbol
Stars: ✭ 34 (-19.05%)
Mutual labels:  sketch
sketch-dark-mode
Generate a dark mode version of any Sketch document, the right way.
Stars: ✭ 58 (+38.1%)
Mutual labels:  sketch
sketch-find-and-replace-text
Find and replace text throughout your Sketch document
Stars: ✭ 41 (-2.38%)
Mutual labels:  sketch
Material-icons-sketch-library-with-color-overrides
This is a collection of all material icons from Google. The Sketch file contains icons as symbols with color overrides, so you can easily change their colors. Black and white colors are available by default, but you can add your own ones on the Colors page. All icons are set to exportable directly on the symbols page, so they will be exportable …
Stars: ✭ 13 (-69.05%)
Mutual labels:  sketch
safari
Safari Dark/Light theme for Sketch
Stars: ✭ 28 (-33.33%)
Mutual labels:  sketch
Chromata
A color plugin for Sketch
Stars: ✭ 15 (-64.29%)
Mutual labels:  sketch
sketch-plugin
Design your next Atlassian app with our component libraries and suite of Sketch tools 💎
Stars: ✭ 51 (+21.43%)
Mutual labels:  sketch
sketch-search-everywhere
A Sketch plugin for searching layer and selecting it.
Stars: ✭ 53 (+26.19%)
Mutual labels:  sketch
boring-avatars
Boring avatars is a tiny JavaScript React library that generates custom, SVG-based avatars from any username and color palette.
Stars: ✭ 3,582 (+8428.57%)
Mutual labels:  sketch
kironroy.github.io
Portfolio
Stars: ✭ 14 (-66.67%)
Mutual labels:  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 (-61.9%)
Mutual labels:  sketch
nudge-resize-sketch-plugin
Sketch Plugin to quickly resize a layer with keyboard shortcuts
Stars: ✭ 25 (-40.48%)
Mutual labels:  sketch
Sketch-Plugin
Plugin to share artboards directly via WeTransfer. Share the link easily with your colleagues and friends.
Stars: ✭ 39 (-7.14%)
Mutual labels:  sketch
set-sketch-paper
SetSketch: Filling the Gap between MinHash and HyperLogLog
Stars: ✭ 23 (-45.24%)
Mutual labels:  sketch
sketch-git-hooks
Easy trick how to enjoy Git versioning for Sketch files thanks to Git Hooks
Stars: ✭ 12 (-71.43%)
Mutual labels:  sketch

Sketch File Format TS

⚠️ This repository has been merged into the sketch-document monorepo which contains both JSON Schema and TypeScript types. The latest npm package is published to @sketch-hq/sketch-file-format-ts

TypeScript types for the Sketch File Format

Overview

This repo contains TypeScript types automatically generated from the Sketch File Format JSON Schemas.

Types are maintained and exported for each Sketch File Format major version. See usage instructions below for more information.

Use cases

  • Strongly type objects representing Sketch documents, or fragments of Sketch documents in TypeScript projects

Related projects

Usage

Add the npm module using npm or yarn

npm install @sketch-hq/sketch-file-format-ts

Types for the latest file format are on the default export

import FileFormat from '@sketch-hq/sketch-file-format-ts'

Types for historical file formats are accessible via named exports

import { FileFormat1, FileFormat2 } from '@sketch-hq/sketch-file-format-ts'

Read about how file format versions map to Sketch document versions here

Examples

Create a typed layer blur object

import FileFormat from '@sketch-hq/sketch-file-format-ts'

const blur: FileFormat.Blur = {
  _class: 'blur',
  isEnabled: false,
  center: '{0.5, 0.5}',
  motionAngle: 0,
  radius: 10,
  saturation: 1,
  type: FileFormat.BlurType.Gaussian,
}

Layer types can be narrowed using discriminate properties on the helper union types like AnyLayer

import FileFormat from '@sketch-hq/sketch-file-format-ts'

const mapLayers = (layers: FileFormat.AnyLayer[]) => {
  return layers.map((layer) => {
    switch (layer._class) {
      case 'bitmap':
      // type narrowed to Bitmap layers
      case 'star':
      // type narrowed to Star layers
    }
  })
}

Work with representations of Sketch files that could have a range of document versions

import {
  FileFormat1,
  FileFormat2,
  FileFormat3,
} from '@sketch-hq/sketch-file-format-ts'

const processDocumentContents = (
  contents: FileFormat1.Contents | FileFormat2.Contents | FileFormat3.Contents,
) => {
  if (contents.meta.version === 119) {
    // type narrowed to file format v1, i.e. Sketch documents with version 119
  }
}

Development

This section of the readme is related to developing the file format spec. If you just want to consume the schemas you can safely ignore this.

Approach

The scripts/generate.ts ingests the file format JSON Schema, and generates type definitions using the TypeScript compiler API.

We depend on multiple major versions of the schemas in package.json using yarn aliases, and generate types for each one. This means that users that have to implement multiple versions of the file format don't need to manually manage multiple versions of this package.

Scripts

Script Description
yarn build Builds the project into the dist folder
yarn test Build script unit tests
yarn format-check Checks the repo with Prettier

Workflows

Conventional commits

Try and use the conventional commits convention when writing commit messages.

Changing how the types are generated

  1. Update scripts/generate.ts
  2. Unit test your changes
  3. Determine the semver bump type and call yarn changeset to create an intent to release your changes (read more about changesets here).
  4. Open a PR to main

Adding or updating a file format version

  1. Use the yarn aliases syntax to add new schema version
  2. Use exact semvers, for example to update or add v3 of the schemas as 3.4.3 run,
    yarn add @sketch-hq/sketch-file-format-3@npm:@sketch-hq/[email protected]
  3. If the schema version is new to the repo you'll also need to update the index.ts to export the types, and scripts/generate.ts to generate the new types
  4. Open a PR to main

Release

  1. Merge the release PR maintained by the changesets GitHub Action.
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].