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-hq/sketch-file-format-ts

v6.5.0

Published

TypeScript types for the Sketch File Format

Downloads

29,741

Readme

Sketch File Format TS

Contains TypeScript types automatically generated from the Sketch File Format JSON Schemas.

Overview

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

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'

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
    }
  })
}

Development

Following is further information for making changes to how the types are generated.

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.

Please note that the latest version of the schemas is referenced directly within the monorepo and not using aliases.

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