├── .circleci └── config.yml ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmignore ├── .prettierignore ├── .vscode ├── launch.json └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package.json ├── src ├── figmaTypes.ts └── index.ts ├── tsconfig.json ├── tsconfig.module.json └── tslint.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # https://circleci.com/docs/2.0/language-javascript/ 2 | version: 2 3 | jobs: 4 | "node-8": 5 | docker: 6 | - image: circleci/node:8 7 | working_directory: ~/typescript-starter 8 | steps: 9 | - checkout 10 | # Download and cache dependencies 11 | - restore_cache: 12 | keys: 13 | - v1-dependencies-{{ checksum "package.json" }} 14 | # fallback to using the latest cache if no exact match is found 15 | - v1-dependencies- 16 | - run: npm install 17 | - save_cache: 18 | paths: 19 | - node_modules 20 | key: v1-dependencies-{{ checksum "package.json" }} 21 | - run: npm test 22 | - run: npx nyc report --reporter=lcov | npx codecov 23 | - run: npm run cov:check 24 | "node-latest": 25 | docker: 26 | - image: circleci/node:latest 27 | working_directory: ~/typescript-starter 28 | steps: 29 | - checkout 30 | - restore_cache: 31 | keys: 32 | - v1-dependencies-{{ checksum "package.json" }} 33 | - v1-dependencies- 34 | - run: npm install 35 | - save_cache: 36 | paths: 37 | - node_modules 38 | key: v1-dependencies-{{ checksum "package.json" }} 39 | - run: npm test 40 | - run: npx nyc report --reporter=lcov | npx codecov 41 | - run: npm run cov:check 42 | 43 | workflows: 44 | version: 2 45 | build: 46 | jobs: 47 | - "node-8" 48 | - "node-latest" -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Example Contributing Guidelines 2 | 3 | This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information. 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **I'm submitting a ...** 2 | [ ] bug report 3 | [ ] feature request 4 | [ ] question about the decisions made in the repository 5 | [ ] question about how to use this project 6 | 7 | * **Summary** 8 | 9 | 10 | 11 | * **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) 2 | 3 | 4 | 5 | * **What is the current behavior?** (You can also link to an open issue here) 6 | 7 | 8 | 9 | * **What is the new behavior (if this is a feature change)?** 10 | 11 | 12 | 13 | * **Other information**: 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | test 4 | src/**.js 5 | 6 | coverage 7 | .nyc_output 8 | *.log 9 | 10 | package-lock.json 11 | yarn.lock 12 | .DS_Store 13 | 14 | .yarn 15 | .pnp.cjs 16 | .pnp.loader.mjs -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | test 3 | tsconfig.json 4 | tsconfig.module.json 5 | tslint.json 6 | .travis.yml 7 | .github 8 | .prettierignore 9 | build/docs 10 | **/*.spec.* 11 | coverage 12 | .nyc_output 13 | *.log 14 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node", 6 | "request": "launch", 7 | "name": "Debug Project", 8 | // we test in `build` to make cleanup fast and easy 9 | "cwd": "${workspaceFolder}/build", 10 | // Replace this with your project root. If there are multiple, you can 11 | // automatically run the currently visible file with: "program": ${file}" 12 | "program": "${workspaceFolder}/src/cli/cli.ts", 13 | // "args": ["--no-install"], 14 | "outFiles": ["${workspaceFolder}/build/main/**/*.js"], 15 | "skipFiles": [ 16 | "/**/*.js", 17 | "${workspaceFolder}/node_modules/**/*.js" 18 | ], 19 | "preLaunchTask": "npm: build", 20 | "stopOnEntry": true, 21 | "smartStep": true, 22 | "runtimeArgs": ["--nolazy"], 23 | "env": { 24 | "TYPESCRIPT_STARTER_REPO_URL": "${workspaceFolder}" 25 | }, 26 | "console": "externalTerminal" 27 | }, 28 | { 29 | /// Usage: set appropriate breakpoints in a *.spec.ts file, then open the 30 | // respective *.spec.js file to run this task. Once a breakpoint is hit, 31 | // the debugger will open the source *.spec.ts file for debugging. 32 | "type": "node", 33 | "request": "launch", 34 | "name": "Debug Visible Compiled Spec", 35 | "program": "${workspaceFolder}/node_modules/ava/profile.js", 36 | "args": [ 37 | "${file}" 38 | // TODO: VSCode's launch.json variable substitution 39 | // (https://code.visualstudio.com/docs/editor/variables-reference) 40 | // doesn't quite allow us to go from: 41 | // `./src/path/to/file.ts` to `./build/main/path/to/file.js` 42 | // so the user has to navigate to the compiled file manually. (Close:) 43 | // "${workspaceFolder}/build/main/lib/${fileBasenameNoExtension}.js" 44 | ], 45 | "skipFiles": ["/**/*.js"], 46 | // Consider using `npm run watch` or `yarn watch` for faster debugging 47 | // "preLaunchTask": "npm: build", 48 | // "smartStep": true, 49 | "runtimeArgs": ["--nolazy"] 50 | }] 51 | } 52 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | // "typescript.implementationsCodeLens.enabled": true 4 | // "typescript.referencesCodeLens.enabled": true 5 | } 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | # 1.15.0 4 | 5 | - Added component set type [#53](https://github.com/jongold/figma-js/pull/53) by [bruno12mota](https://github.com/bruno12mota) 6 | - Support pluginData and sharedPluginData on files [#54](https://github.com/jongold/figma-js/pull/54) by [jacoblapworth](https://github.com/jacoblapworth) 7 | 8 | # 1.14.0 9 | 10 | - BooleanGroup is changed to BooleanOperation [#42](https://github.com/jongold/figma-js/pull/42) by [ErgoFriend](https://github.com/ErgoFriend) 11 | - Fix params for fileVersions [#44](https://github.com/jongold/figma-js/pull/44) by [Kerumen](https://github.com/Kerumen) 12 | - Add new properties for AutoLayout [#46](https://github.com/jongold/figma-js/pull/46) by [mikkmartin](https://github.com/mikkmartin) 13 | - Add component-sets features (variants) [#48](https://github.com/jongold/figma-js/pull/48) by [gorango](https://github.com/gorango) 14 | - Upgrade axios [#50](https://github.com/jongold/figma-js/pull/50) by [frassinier](https://github.com/frassinier) 15 | - Fix: double cursor property typing [#51](https://github.com/jongold/figma-js/pull/51) by [erictaylor](https://github.com/erictaylor) 16 | 17 | # 1.13.0 18 | 19 | - Fix issue with optional ids param [#41](https://github.com/jongold/figma-js/pull/41) by [dmiller9911](https://github.com/dmiller9911) 20 | 21 | # 1.12.0 22 | 23 | - Adds support for the use_absolute_bounds query param on GET image requests. [#37](https://github.com/jongold/figma-js/pull/37) by [xtiandiaz](https://github.com/xtiandiaz) 24 | 25 | - Change ids params of file method from string to array. [#39](https://github.com/jongold/figma-js/pull/39) by [Kerumen](https://github.com/Kerumen) 26 | 27 | # 1.2.0 28 | 29 | ### Bug Fixes 30 | 31 | - Fix client return types ([f3e4f82](https://github.com/jongold/figma-js/commit/f3e4f82)) 32 | 33 | ### Features 34 | 35 | - Add new authentication type ([9d16842](https://github.com/jongold/figma-js/commit/9d16842)) 36 | 37 | # 1.0.0 38 | 39 | ### Features 40 | 41 | - Create Figma client ([454ca6c](https://github.com/jongold/figma-js/commit/454ca6c)) 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jon Gold 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Figma.js 2 | 3 | A simple wrapper for the Figma API. 4 | 5 | Cool projects using this: 6 | - [figma-graphql](https://github.com/braposo/figma-graphql) 7 | - [figmint](https://github.com/tiltshift/figmint) 8 | 9 | ## Usage 10 | 11 | [Full documentation](https://jemgold.github.io/figma-js) is available on the web and most everything is typed with TypeScript. 12 | 13 | ### Creating a client 14 | 15 | Quickest start is to grab a personal access token from your Figma account settings page 16 | 17 | ```typescript 18 | import * as Figma from 'figma-js'; 19 | 20 | const token = '12345'; 21 | 22 | const client = Figma.Client({ 23 | personalAccessToken: token 24 | }); 25 | ``` 26 | 27 | Or if you're building an app with OAuth authentication, after you get back the OAuth access token… 28 | 29 | ```typescript 30 | import * as Figma from 'figma-js'; 31 | 32 | const token = '12345'; 33 | 34 | const client = Figma.Client({ 35 | accessToken: token 36 | }); 37 | ``` 38 | 39 | ### Doing cool things 40 | 41 | Once you have instantiated a client, have fun! 42 | 43 | ```typescript 44 | client.file('file-id').then(({ data }) => { 45 | console.log(data); 46 | }); 47 | ``` 48 | 49 | ### Just reusing types 50 | 51 | All of the types in the Figma file format / API are exported. 52 | 53 | ```typescript 54 | import * as Figma from 'figma-js'; 55 | 56 | const textNode: Figma.Text = { 57 | // … this should autocomplete if your editor is set up for it! 58 | }; 59 | ``` 60 | 61 | ## Contributing 62 | 63 | We used the [`typescript-starter`](https://github.com/bitjson/typescript-starter) repo for this - refer to its README for more detailed instructions. 64 | 65 | Helpful development commands: 66 | 67 | ```sh 68 | yarn watch 69 | yarn docs 70 | yarn docs:publish 71 | ``` 72 | 73 | ### Contributions welcomed 74 | 75 | * [ ] [generate types automatically](https://github.com/jemgold/figma-js/issues/1) 76 | * [ ] [add tests](https://github.com/jemgold/figma-js/issues/2) 77 | 78 | ### Committing 79 | 80 | ```sh 81 | yarn global add commitizen 82 | 83 | # instead of git commit 84 | 85 | git cz 86 | ``` 87 | 88 | ## Contributors 89 | 90 | * [@jemgold](https://github.com/jemgold/) (Airbnb) 91 | * [@chrisdrackett](https://github.com/chrisdrackett/) 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "figma-js", 3 | "version": "1.16.1-0", 4 | "description": "A simple wrapper for the Figma API", 5 | "main": "build/main/index.js", 6 | "types": "build/main/index.d.ts", 7 | "module": "build/module/index.js", 8 | "repository": "https://github.com/jemgold/figma-js", 9 | "license": "MIT", 10 | "keywords": [], 11 | "scripts": { 12 | "info": "npm-scripts-info", 13 | "build": "run-s clean && run-p build:main build:module", 14 | "build:main": "tsc -p tsconfig.json", 15 | "build:module": "tsc -p tsconfig.module.json", 16 | "fix": "run-s fix:*", 17 | "fix:prettier": "prettier \"src/**/*.ts\" --write", 18 | "fix:tslint": "tslint --fix --project .", 19 | "test": "run-s build test:*", 20 | "test:lint": "tslint --project . && prettier \"src/**/*.ts\" --list-different", 21 | "test:unit": "nyc --silent ava", 22 | "test:nsp": "nsp check", 23 | "watch": "run-s clean build:main && run-p \"build:main -- -w\" \"test:unit -- --watch\"", 24 | "cov": "run-s build test:unit cov:html && opn coverage/index.html", 25 | "cov:html": "nyc report --reporter=html", 26 | "cov:send": "nyc report --reporter=lcov > coverage.lcov && codecov", 27 | "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100", 28 | "doc": "run-s doc:html && opn build/docs/index.html", 29 | "doc:html": "typedoc src/ --target ES6 --mode file --out build/docs", 30 | "doc:json": "typedoc src/ --target ES6 --mode file --json build/docs/typedoc.json", 31 | "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs", 32 | "zzzversion": "standard-version", 33 | "zzzreset": "git clean -dfx && git reset --hard && npm i", 34 | "clean": "trash build test", 35 | "all": "run-s doc:html", 36 | "prepare-release": "yarn build && yarn doc && yarn doc:publish", 37 | "release": "yarn prepare-release && yarn npm publish && git push && git push --tag", 38 | "zzzpreinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('figma-js must be installed with Yarn: https://yarnpkg.com/')\"" 39 | }, 40 | "scripts-info": { 41 | "info": "Display information about the package scripts", 42 | "build": "Clean and rebuild the project", 43 | "fix": "Try to automatically fix any linting problems", 44 | "test": "Lint and unit test the project", 45 | "watch": "Watch and rebuild the project on save, then rerun relevant tests", 46 | "cov": "Rebuild, run tests, then create and open the coverage report", 47 | "doc": "Generate HTML API documentation and open it in a browser", 48 | "doc:json": "Generate API documentation in typedoc JSON format", 49 | "changelog": "Bump package.json version, update CHANGELOG.md, tag release", 50 | "reset": "Delete all untracked files and reset the repo to the last commit", 51 | "prepare-release": "One-step: clean, build, test, publish docs, and prep a release" 52 | }, 53 | "engines": { 54 | "node": ">=8.9" 55 | }, 56 | "dependencies": { 57 | "axios": "^1.6.0" 58 | }, 59 | "devDependencies": { 60 | "ava": "^3.12.1", 61 | "codecov": "^3.7.2", 62 | "cz-conventional-changelog": "^3.3.0", 63 | "gh-pages": "^3.1.0", 64 | "npm-run-all": "^4.1.5", 65 | "npm-scripts-info": "^0.3.9", 66 | "nsp": "^3.2.1", 67 | "nyc": "^11.5.0", 68 | "opn-cli": "^3.1.0", 69 | "prettier": "^2.1.1", 70 | "standard-version": "^9.0.0", 71 | "trash-cli": "^3.1.0", 72 | "tslint": "^6.1.3", 73 | "tslint-config-prettier": "^1.18.0", 74 | "tslint-immutable": "^6.0.1", 75 | "typedoc": "^0.19.1", 76 | "typescript": "^4.3.4" 77 | }, 78 | "ava": { 79 | "failFast": true, 80 | "files": [ 81 | "build/main/**/*.spec.js" 82 | ] 83 | }, 84 | "config": { 85 | "commitizen": { 86 | "path": "cz-conventional-changelog" 87 | } 88 | }, 89 | "greenkeeper": { 90 | "ignore": [ 91 | "@types/node" 92 | ] 93 | }, 94 | "prettier": { 95 | "singleQuote": true 96 | }, 97 | "nyc": { 98 | "exclude": [ 99 | "**/*.spec.js" 100 | ] 101 | }, 102 | "packageManager": "yarn@4.1.1", 103 | "stableVersion": "1.16.0" 104 | } 105 | -------------------------------------------------------------------------------- /src/figmaTypes.ts: -------------------------------------------------------------------------------- 1 | export interface Global { 2 | /** a string uniquely identifying this node within the document */ 3 | readonly id: string; 4 | /** the name given to the node by the user in the tool. */ 5 | readonly name: string; 6 | /** whether or not the node is visible on the canvas */ 7 | readonly visible?: boolean; 8 | /** the type of the node, refer to table below for details */ 9 | readonly type: NodeType; 10 | /** data written by plugins that is visible only to the plugin that wrote it. Requires the `pluginData` to include the ID of the plugin. */ 11 | readonly pluginData?: any; 12 | /** data written by plugins that is visible to all plugins. Requires the `pluginData` parameter to include the string "shared". */ 13 | readonly sharedPluginData?: any; 14 | } 15 | 16 | /** 17 | * Styles can be one of the following types 18 | */ 19 | export type StyleType = 'FILL' | 'TEXT' | 'EFFECT' | 'GRID'; 20 | 21 | /** 22 | * the above styles can be used in the following ways 23 | */ 24 | export type StyleKeyType = 25 | | 'fill' 26 | | 'stroke' 27 | | 'effect' 28 | | 'grid' 29 | | 'text' 30 | | 'background'; 31 | 32 | export type StylesObject = { 33 | [key in StyleKeyType]: Record; 34 | }[StyleKeyType]; 35 | 36 | export type ScaleMode = 'FILL' | 'FIT' | 'TILE' | 'STRETCH'; 37 | 38 | export type PaintTypeSolid = 'SOLID'; 39 | 40 | export type PaintTypeGradient = 41 | | 'GRADIENT_LINEAR' 42 | | 'GRADIENT_RADIAL' 43 | | 'GRADIENT_ANGULAR' 44 | | 'GRADIENT_DIAMOND'; 45 | 46 | export type PaintTypeImage = 'IMAGE' | 'EMOJI'; // I'm guessing that EMOJI is like an image, not sure where it is used 47 | 48 | export type TextType = 'TEXT'; 49 | 50 | export type PaintType = PaintTypeSolid | PaintTypeGradient | PaintTypeImage; 51 | 52 | /** 53 | * how the layer blends with layers below 54 | */ 55 | export type BlendMode = 56 | | 'PASS_THROUGH' /** (Only applicable to objects with children) */ 57 | | 'NORMAL' 58 | 59 | /** Darken: */ 60 | | 'DARKEN' 61 | | 'MULTIPLY' 62 | | 'LINEAR_BURN' 63 | | 'COLOR_BURN' 64 | 65 | /** Lighten: */ 66 | | 'LIGHTEN' 67 | | 'SCREEN' 68 | | 'LINEAR_DODGE' 69 | | 'COLOR_DODGE' 70 | 71 | /** Contrast: */ 72 | | 'OVERLAY' 73 | | 'SOFT_LIGHT' 74 | | 'HARD_LIGHT' 75 | 76 | /** Inversion: */ 77 | | 'DIFFERENCE' 78 | | 'EXCLUSION' 79 | 80 | /** Component: */ 81 | | 'HUE' 82 | | 'SATURATION' 83 | | 'COLOR' 84 | | 'LUMINOSITY'; 85 | 86 | export type EasingType = 87 | | 'EASE_IN' /** Ease in with an animation curve similar to CSS ease-in */ 88 | | 'EASE_OUT' /** Ease out with an animation curve similar to CSS ease-out */ 89 | | 'EASE_IN_AND_OUT'; /** Ease in and then out with an animation curve similar to CSS ease-in-out */ 90 | 91 | export type RoleType = 'viewer' | 'editor' | 'owner'; 92 | 93 | export type NodeType = 94 | | 'DOCUMENT' 95 | | 'CANVAS' 96 | | 'FRAME' 97 | | 'GROUP' 98 | | 'VECTOR' 99 | | 'BOOLEAN_OPERATION' 100 | | 'STAR' 101 | | 'LINE' 102 | | 'ELLIPSE' 103 | | 'REGULAR_POLYGON' 104 | | 'RECTANGLE' 105 | | 'TEXT' 106 | | 'SLICE' 107 | | 'COMPONENT' 108 | | 'COMPONENT_SET' 109 | | 'INSTANCE'; 110 | 111 | export type Node = 112 | | Document 113 | | Canvas 114 | | Frame 115 | | Group 116 | | Vector 117 | | BooleanOperation 118 | | Star 119 | | Line 120 | | Ellipse 121 | | RegularPolygon 122 | | Rectangle 123 | | Text 124 | | Slice 125 | | Component 126 | | ComponentSet 127 | | Instance; 128 | 129 | /** Node Properties */ 130 | 131 | /** The root node */ 132 | export interface Document extends Global { 133 | readonly type: 'DOCUMENT'; 134 | /** An array of canvases attached to the document */ 135 | readonly children: ReadonlyArray; 136 | } 137 | 138 | /** Represents a single page */ 139 | export interface Canvas extends Global { 140 | readonly type: 'CANVAS'; 141 | /** An array of top level layers on the canvas */ 142 | readonly children: ReadonlyArray; 143 | /** Background color of the canvas */ 144 | readonly backgroundColor: Color; 145 | /** Node ID that corresponds to the start frame for prototypes */ 146 | readonly prototypeStartNodeID: string | null; 147 | /** An array of export settings representing images to export from the canvas */ 148 | readonly exportSettings?: ReadonlyArray; 149 | } 150 | 151 | export interface FrameBase extends Global { 152 | /** An array of nodes that are direct children of this node */ 153 | readonly children: ReadonlyArray; 154 | /** Background of the node. This is deprecated, as backgrounds for frames are now in the fills field. */ 155 | readonly background: ReadonlyArray; 156 | /** Background color of the node. This is deprecated, as frames now support more than a solid color as a fills. Please use the fills field instead. */ 157 | readonly backgroundColor: Color; 158 | /** 159 | * An array of fill paints applied to the node 160 | * @default [] 161 | */ 162 | readonly fills: ReadonlyArray; 163 | /** 164 | * An array of stroke paints applied to the node 165 | * @default [] 166 | */ 167 | readonly strokes: ReadonlyArray; 168 | /** The weight of strokes on the node */ 169 | readonly strokeWeight: number; 170 | /** 171 | * Position of stroke relative to vector outline, as a string enum 172 | * "INSIDE": stroke drawn inside the shape boundary 173 | * "OUTSIDE": stroke drawn outside the shape boundary 174 | * "CENTER": stroke drawn centered along the shape boundary 175 | */ 176 | readonly strokeAlign: 'INSIDE' | 'OUTSIDE' | 'CENTER'; 177 | /** 178 | * Radius of each corner of the frame if a single radius is set for all 179 | * corners 180 | */ 181 | readonly cornerRadius?: number; 182 | /** 183 | * Array of length 4 of the radius of each corner of the frame, starting 184 | * in the top left and proceeding clockwise 185 | */ 186 | readonly rectangleCornerRadii?: readonly [number, number, number, number]; 187 | /** 188 | * An array of export settings representing images to export from node 189 | * @default [] 190 | */ 191 | readonly exportSettings?: ReadonlyArray; 192 | /** 193 | * How this node blends with nodes behind it in the scene 194 | * (see blend mode section for more details) 195 | */ 196 | readonly blendMode: BlendMode; 197 | /** 198 | * Keep height and width constrained to same ratio 199 | * @default false 200 | */ 201 | readonly preserveRatio?: boolean; 202 | /** Horizontal and vertical layout constraints for node */ 203 | readonly constraints: LayoutConstraint; 204 | /** 205 | * How the layer is aligned inside an auto-layout frame. This property 206 | * is only provided for direct children of auto-layout frames. 207 | * MIN 208 | * CENTER 209 | * MAX 210 | * STRETCH 211 | * In horizontal auto-layout frames, "MIN" and "MAX" correspond to 212 | * "TOP" and "BOTTOM". * In vertical auto-layout frames, "MIN" and 213 | * "MAX" correspond to "LEFT" and "RIGHT". 214 | */ 215 | readonly layoutAlign?: string; 216 | /** 217 | * Node ID of node to transition to in prototyping 218 | * @default null 219 | */ 220 | readonly transitionNodeID?: string | null; 221 | /** 222 | * The duration of the prototyping transition on this node (in milliseconds) 223 | * @default null 224 | */ 225 | readonly transitionDuration?: number | null; 226 | /** 227 | * The easing curve used in the prototyping transition on this node 228 | * @default null 229 | */ 230 | readonly transitionEasing?: EasingType | null; 231 | /** 232 | * Opacity of the node 233 | * @default 1 234 | */ 235 | readonly opacity?: number; 236 | /** Bounding box of the node in absolute space coordinates */ 237 | readonly absoluteBoundingBox: Rect; 238 | 239 | /** 240 | * Width and height of element. This is different from the width and height 241 | * of the bounding box in that the absolute bounding box represents the 242 | * element after scaling and rotation. Only present if geometry=paths 243 | * is passed 244 | */ 245 | readonly size?: Vector2; 246 | 247 | /** 248 | * The top two rows of a matrix that represents the 2D transform of this 249 | * node relative to its parent. The bottom row of the matrix is implicitly 250 | * always (0, 0, 1). Use to transform coordinates in geometry. 251 | * Only present if geometry=paths is passed 252 | */ 253 | readonly relativeTransform?: Transform; 254 | 255 | /** Does this node clip content outside of its bounds? */ 256 | readonly clipsContent: boolean; 257 | /** 258 | * Whether this layer uses auto-layout to position its children. 259 | * @default NONE 260 | */ 261 | readonly layoutMode?: 'NONE' | 'HORIZONTAL' | 'VERTICAL'; 262 | /** 263 | * Whether the counter axis has a fixed length (determined by the user) 264 | * or an automatic length (determined by the layout engine). 265 | * This property is only applicable for auto-layout frames 266 | * @default AUTO 267 | */ 268 | readonly primaryAxisSizingMode?: 'FIXED' | 'AUTO'; 269 | /** 270 | * When autolayout is enabled 271 | */ 272 | readonly primaryAxisAlignItems?: 'MIN' | 'CENTER' | 'MAX' | 'SPACE_BETWEEN'; 273 | /** 274 | * When autolayout is enabled 275 | */ 276 | readonly counterAxisAlignItems?: 'MIN' | 'CENTER' | 'MAX'; 277 | /** 278 | * When autolayout is enabled 279 | */ 280 | readonly paddingLeft?: number; 281 | /** 282 | * The padding betweeen the left border of the frame and its children. 283 | * This property is only applicable for auto-layout frames. 284 | * @default 0 285 | */ 286 | readonly paddingRight?: number; 287 | /** 288 | * The padding betweeen the right border of the frame and its children. 289 | * This property is only applicable for auto-layout frames. 290 | * @default 0 291 | */ 292 | readonly paddingTop?: number; 293 | /** 294 | * The padding betweeen the top border of the frame and its children. 295 | * This property is only applicable for auto-layout frames. 296 | * @default 0 297 | */ 298 | readonly paddingBottom?: number; 299 | /** 300 | * The padding betweeen the bottom border of the frame and its children. 301 | * This property is only applicable for auto-layout frames. 302 | * @default 0 303 | */ 304 | readonly counterAxisSizingMode?: 'FIXED' | 'AUTO'; 305 | /** 306 | * The horizontal padding between the borders of the frame and its 307 | * children. This property is only applicable for auto-layout frames. 308 | * @default 0 309 | */ 310 | readonly horizontalPadding?: number; 311 | /** 312 | * The vertical padding between the borders of the frame and its 313 | * children. This property is only applicable for auto-layout frames. 314 | * @default 0 315 | */ 316 | readonly verticalPadding?: number; 317 | /** 318 | * The distance between children of the frame. This property is only 319 | * applicable for auto-layout frames. 320 | * @default 0 321 | */ 322 | readonly itemSpacing?: number; 323 | /** 324 | * An array of layout grids attached to this node (see layout grids section 325 | * for more details). GROUP nodes do not have this attribute 326 | * @default [] 327 | */ 328 | readonly layoutGrids?: ReadonlyArray; 329 | /** 330 | * Defines the scrolling behavior of the frame, if there exist contents 331 | * outside of the frame boundaries. The frame can either scroll 332 | * vertically, horizontally, or in both directions to the extents of the 333 | * content contained within it. This behavior can be observed in a 334 | * prototype. 335 | * HORIZONTAL_SCROLLING 336 | * VERTICAL_SCROLLING 337 | * HORIZONTAL_AND_VERTICAL_SCROLLING 338 | * @default NONE 339 | */ 340 | readonly overflowDirection?: string; 341 | /** 342 | * An array of effects attached to this node 343 | * (see effects sectionfor more details) 344 | * @default [] 345 | */ 346 | readonly effects: ReadonlyArray; 347 | /** 348 | * Does this node mask sibling nodes in front of it? 349 | * @default false 350 | */ 351 | readonly isMask?: boolean; 352 | } 353 | 354 | /** A node of fixed size containing other nodes */ 355 | export interface Frame extends FrameBase { 356 | readonly type: 'FRAME'; 357 | } 358 | 359 | /** A logical grouping of nodes */ 360 | export interface Group extends FrameBase { 361 | readonly type: 'GROUP'; 362 | } 363 | 364 | export interface VectorBase extends Global { 365 | /** 366 | * An array of export settings representing images to export from node 367 | * @default [] 368 | */ 369 | readonly exportSettings?: ReadonlyArray; 370 | /** 371 | * How this node blends with nodes behind it in the scene 372 | * (see blend mode section for more details) 373 | */ 374 | readonly blendMode: BlendMode; 375 | /** 376 | * Keep height and width constrained to same ratio 377 | * @default false 378 | */ 379 | readonly preserveRatio?: boolean; 380 | /** 381 | * Horizontal and vertical layout constraints for node 382 | */ 383 | readonly constraints: LayoutConstraint; 384 | /** 385 | * Node ID of node to transition to in prototyping 386 | * @default null 387 | */ 388 | readonly transitionNodeID?: string | null; 389 | /** 390 | * The duration of the prototyping transition on this node (in milliseconds) 391 | * @default null 392 | */ 393 | readonly transitionDuration?: number | null; 394 | /** 395 | * The easing curve used in the prototyping transition on this node 396 | * @default null 397 | */ 398 | readonly transitionEasing?: EasingType | null; 399 | /** 400 | * Opacity of the node 401 | * @default 1 402 | */ 403 | readonly opacity?: number; 404 | /** Bounding box of the node in absolute space coordinates */ 405 | readonly absoluteBoundingBox: Rect; 406 | 407 | /** 408 | * Width and height of element. This is different from the width and height 409 | * of the bounding box in that the absolute bounding box represents the 410 | * element after scaling and rotation. Only present if geometry=paths 411 | * is passed 412 | */ 413 | readonly size?: Vector2; 414 | 415 | /** 416 | * The top two rows of a matrix that represents the 2D transform of this 417 | * node relative to its parent. The bottom row of the matrix is implicitly 418 | * always (0, 0, 1). Use to transform coordinates in geometry. 419 | * Only present if geometry=paths is passed 420 | */ 421 | readonly relativeTransform?: Transform; 422 | 423 | /** 424 | * An array of effects attached to this node 425 | * (see effects sectionfor more details) 426 | * @default [] 427 | */ 428 | readonly effects: ReadonlyArray; 429 | /** 430 | * Does this node mask sibling nodes in front of it? 431 | * @default false 432 | */ 433 | readonly isMask?: boolean; 434 | /** 435 | * An array of fill paints applied to the node 436 | * @default [] 437 | */ 438 | readonly fills: ReadonlyArray; 439 | 440 | /** 441 | * Only specified if parameter geometry=paths is used. An array of paths 442 | * representing the object fill 443 | */ 444 | readonly fillGeometry?: ReadonlyArray; 445 | 446 | /** 447 | * An array of stroke paints applied to the node 448 | * @default [] 449 | */ 450 | readonly strokes: ReadonlyArray; 451 | 452 | /** The weight of strokes on the node */ 453 | readonly strokeWeight: number; 454 | 455 | /** 456 | * Only specified if parameter geometry=paths is used. An array of paths 457 | * representing the object stroke 458 | */ 459 | readonly strokeGeometry?: ReadonlyArray; 460 | 461 | /** 462 | * Where stroke is drawn relative to the vector outline as a string enum 463 | * "INSIDE": draw stroke inside the shape boundary 464 | * "OUTSIDE": draw stroke outside the shape boundary 465 | * "CENTER": draw stroke centered along the shape boundary 466 | */ 467 | readonly strokeAlign: 'INSIDE' | 'OUTSIDE' | 'CENTER'; 468 | 469 | /** 470 | * Styles this node uses from the global `styles` 471 | */ 472 | readonly styles?: StylesObject; 473 | } 474 | 475 | /** A vector network, consisting of vertices and edges */ 476 | export interface Vector extends VectorBase { 477 | readonly type: 'VECTOR'; 478 | } 479 | 480 | /** A group that has a boolean operation applied to it */ 481 | export interface BooleanOperation extends VectorBase { 482 | readonly type: 'BOOLEAN_OPERATION'; 483 | /** 484 | * A string enum with value of "UNION", "INTERSECT", "SUBTRACT", or "EXCLUDE" 485 | * indicating the type of boolean operation applied 486 | */ 487 | readonly booleanOperation: 'UNION' | 'INTERSECT' | 'SUBTRACT' | 'EXCLUDE'; 488 | /** An array of nodes that are being boolean operated on */ 489 | readonly children: ReadonlyArray; 490 | } 491 | 492 | /** A regular star shape */ 493 | export interface Star extends VectorBase { 494 | readonly type: 'STAR'; 495 | } 496 | 497 | /** A straight line */ 498 | export interface Line extends VectorBase { 499 | readonly type: 'LINE'; 500 | } 501 | 502 | /** An ellipse */ 503 | export interface Ellipse extends VectorBase { 504 | readonly type: 'ELLIPSE'; 505 | } 506 | 507 | /** A regular n-sided polygon */ 508 | export interface RegularPolygon extends VectorBase { 509 | readonly type: 'REGULAR_POLYGON'; 510 | } 511 | 512 | /** A rectangle */ 513 | export interface Rectangle extends VectorBase { 514 | readonly type: 'RECTANGLE'; 515 | /** Radius of each corner of the rectangle if a single radius is set for all corners */ 516 | readonly cornerRadius?: number; 517 | /** Array of length 4 of the radius of each corner of the rectangle, starting in the top left and proceeding clockwise */ 518 | readonly rectangleCornerRadii?: readonly [number, number, number, number]; 519 | } 520 | 521 | /** A text box */ 522 | export interface Text extends VectorBase { 523 | readonly type: TextType; 524 | /** Text contained within text box */ 525 | readonly characters: string; 526 | /** 527 | * Style of text including font family and weight (see type style 528 | * section for more information) 529 | */ 530 | readonly style: TypeStyle; 531 | /** 532 | * Array with same number of elements as characeters in text 'box' | * each element is a reference to the styleOverrideTable defined 533 | * below and maps to the corresponding character in the characters 534 | * field. Elements with value 0 have the default type style 535 | */ 536 | readonly characterStyleOverrides: ReadonlyArray; 537 | /** Map from ID to TypeStyle for looking up style overrides */ 538 | readonly styleOverrideTable: { readonly [index: number]: TypeStyle }; 539 | } 540 | 541 | /** A rectangular region of the canvas that can be exported */ 542 | export interface Slice extends Global { 543 | readonly type: 'SLICE'; 544 | /** An array of export settings representing images to export from this node */ 545 | readonly exportSettings: ReadonlyArray; 546 | /** Bounding box of the node in absolute space coordinates */ 547 | readonly absoluteBoundingBox: Rect; 548 | /** 549 | * Width and height of element. This is different from the width and height 550 | * of the bounding box in that the absolute bounding box represents the 551 | * element after scaling and rotation. Only present if geometry=paths 552 | * is passed 553 | */ 554 | readonly size?: Vector2; 555 | 556 | /** 557 | * The top two rows of a matrix that represents the 2D transform of this 558 | * node relative to its parent. The bottom row of the matrix is implicitly 559 | * always (0, 0, 1). Use to transform coordinates in geometry. 560 | * Only present if geometry=paths is passed 561 | */ 562 | readonly relativeTransform?: Transform; 563 | } 564 | 565 | /** A node that can have instances created of it that share the same properties */ 566 | export interface Component extends FrameBase { 567 | readonly type: 'COMPONENT'; 568 | } 569 | 570 | /** A node that can have multiple component variations */ 571 | export interface ComponentSet extends FrameBase { 572 | readonly type: 'COMPONENT_SET'; 573 | } 574 | 575 | /** 576 | * An instance of a component, changes to the component result in the same 577 | * changes applied to the instance 578 | */ 579 | export interface Instance extends FrameBase { 580 | readonly type: 'INSTANCE'; 581 | /** 582 | * ID of component that this instance came from, refers to components 583 | * table (see endpoints section below) 584 | */ 585 | readonly componentId: string; 586 | } 587 | 588 | // Types 589 | 590 | /** An RGBA color */ 591 | export interface Color { 592 | /** Red channel value, between 0 and 1 */ 593 | readonly r: number; 594 | /** Green channel value, between 0 and 1 */ 595 | readonly g: number; 596 | /** Blue channel value, between 0 and 1 */ 597 | readonly b: number; 598 | /** Alpha channel value, between 0 and 1 */ 599 | readonly a: number; 600 | } 601 | 602 | /** Format and size to export an asset at */ 603 | export interface ExportSetting { 604 | /** File suffix to append to all filenames */ 605 | readonly suffix: string; 606 | /** Image type, string enum */ 607 | readonly format: 'JPG' | 'PNG' | 'SVG' | 'PDF'; 608 | /** Constraint that determines sizing of exported asset */ 609 | readonly constraint: Constraint; 610 | } 611 | 612 | /** Sizing constraint for exports */ 613 | export interface Constraint { 614 | /** 615 | * Type of constraint to apply; string enum with potential values below 616 | * "SCALE": Scale by value 617 | * "WIDTH": Scale proportionally and set width to value 618 | * "HEIGHT": Scale proportionally and set height to value 619 | */ 620 | readonly type: 'SCALE' | 'WIDTH' | 'HEIGHT'; 621 | /** See type property for effect of this field */ 622 | readonly value: number; 623 | } 624 | 625 | /** A rectangle that expresses a bounding box in absolute coordinates */ 626 | export interface Rect { 627 | /** X coordinate of top left corner of the rectangle */ 628 | readonly x: number; 629 | /** Y coordinate of top left corner of the rectangle */ 630 | readonly y: number; 631 | /** Width of the rectangle */ 632 | readonly width: number; 633 | /** Height of the rectangle */ 634 | readonly height: number; 635 | } 636 | 637 | /** Layout constraint relative to containing Frame */ 638 | export interface LayoutConstraint { 639 | /** 640 | * Vertical constraint as an enum 641 | * "TOP": Node is laid out relative to top of the containing frame 642 | * "BOTTOM": Node is laid out relative to bottom of the containing frame 643 | * "CENTER": Node is vertically centered relative to containing frame 644 | * "TOP_BOTTOM": Both top and bottom of node are constrained relative to containing frame (node stretches with frame) 645 | * "SCALE": Node scales vertically with containing frame 646 | */ 647 | readonly vertical: 'TOP' | 'BOTTOM' | 'CENTER' | 'TOP_BOTTOM' | 'SCALE'; 648 | /** 649 | * Horizontal constraint as an enum 650 | * "LEFT": Node is laid out relative to left of the containing frame 651 | * "RIGHT": Node is laid out relative to right of the containing frame 652 | * "CENTER": Node is horizontally centered relative to containing frame 653 | * "LEFT_RIGHT": Both left and right of node are constrained relative to containing frame (node stretches with frame) 654 | * "SCALE": Node scales horizontally with containing frame 655 | */ 656 | readonly horizontal: 'LEFT' | 'RIGHT' | 'CENTER' | 'LEFT_RIGHT' | 'SCALE'; 657 | } 658 | 659 | /** Guides to align and place objects within a frame */ 660 | export interface LayoutGrid { 661 | /** 662 | * Orientation of the grid as a string enum 663 | * "COLUMNS": Vertical grid 664 | * "ROWS": Horizontal grid 665 | * "GRID": Square grid 666 | */ 667 | readonly pattern: 'COLUMNS' | 'ROWS' | 'GRID'; 668 | /** Width of column grid or height of row grid or square grid spacing */ 669 | readonly sectionSize: number; 670 | /** Is the grid currently visible? */ 671 | readonly visible: boolean; 672 | /** Color of the grid */ 673 | readonly color: Color; 674 | /** 675 | * Positioning of grid as a string enum 676 | * "MIN": Grid starts at the left or top of the frame 677 | * "MAX": Grid starts at the right or bottom of the frame 678 | * "CENTER": Grid is center aligned 679 | */ 680 | readonly alignment: 'MIN' | 'MAX' | 'CENTER'; 681 | /** Spacing in between columns and rows */ 682 | readonly gutterSize: number; 683 | /** Spacing before the first column or row */ 684 | readonly offset: number; 685 | /** Number of columns or rows */ 686 | readonly count: number; 687 | } 688 | 689 | /** A visual effect such as a shadow or blur */ 690 | export interface Effect { 691 | /** Type of effect as a string enum */ 692 | readonly type: 693 | | 'INNER_SHADOW' 694 | | 'DROP_SHADOW' 695 | | 'LAYER_BLUR' 696 | | 'BACKGROUND_BLUR'; 697 | /** Is the effect active? */ 698 | readonly visible: boolean; 699 | /** Radius of the blur effect (applies to shadows as well) */ 700 | readonly radius: number; 701 | 702 | // The following properties are for shadows only: 703 | readonly color?: Color; 704 | readonly blendMode?: BlendMode; 705 | readonly offset?: Vector2; 706 | } 707 | 708 | /** A solid color, gradient, or image texture that can be applied as fills or strokes */ 709 | export interface Paint { 710 | /** Type of paint as a string enum */ 711 | readonly type: PaintType; 712 | /** 713 | * Is the paint enabled? 714 | * @default true 715 | */ 716 | readonly visible?: boolean; 717 | /** 718 | * Overall opacity of paint (colors within the paint can also have opacity 719 | * values which would blend with this) 720 | * @default 1 721 | */ 722 | readonly opacity?: number; 723 | // for solid paints 724 | /** Solid color of the paint */ 725 | readonly color?: Color; 726 | /** 727 | * How this node blends with nodes behind it in the scene 728 | * (see blend mode section for more details) 729 | */ 730 | readonly blendMode: BlendMode; 731 | // for gradient paints 732 | /** 733 | * This field contains three vectors, each of which are a position in 734 | * normalized object space (normalized object space is if the top left 735 | * corner of the bounding box of the object is (0, 0) and the bottom 736 | * right is (1,1)). The first position corresponds to the start of the 737 | * gradient (value 0 for the purposes of calculating gradient stops), 738 | * the second position is the end of the gradient (value 1), and the 739 | * third handle position determines the width of the gradient (only 740 | * relevant for non-linear gradients). 741 | * 742 | */ 743 | readonly gradientHandlePositions?: ReadonlyArray; 744 | /** 745 | * Positions of key points along the gradient axis with the colors 746 | * anchored there. Colors along the gradient are interpolated smoothly 747 | * between neighboring gradient stops. 748 | */ 749 | readonly gradientStops?: ReadonlyArray; 750 | 751 | // for image paints 752 | 753 | /** Image scaling mode */ 754 | readonly scaleMode?: ScaleMode; 755 | /** 756 | * Affine transform applied to the image, only present if scaleMode is `STRETCH` 757 | */ 758 | readonly imageTransform?: Transform; 759 | /** 760 | * Amount image is scaled by in tiling, only present if scaleMode is `TILE` 761 | */ 762 | readonly scalingFactor?: number; 763 | /** 764 | * A reference to an image embedded in the file. To download the image using this reference, 765 | * use the GET file images endpoint to retrieve the mapping from image references to image URLs 766 | */ 767 | readonly imageRef?: string; 768 | /** 769 | * A reference to the GIF embedded in this node, if the image is a GIF. 770 | * To download the image using this reference, 771 | * use the GET file images endpoint to retrieve the mapping from image references to image URLs 772 | */ 773 | readonly gifRef?: string; 774 | } 775 | 776 | export interface Path { 777 | /** A sequence of path commands in SVG notation */ 778 | readonly path: string; 779 | /** Winding rule for the path */ 780 | readonly windingRule: 'EVENODD' | 'NONZERO'; 781 | } 782 | 783 | export type Transform = ReadonlyArray>; 784 | 785 | /** A 2d vector */ 786 | export interface Vector2 { 787 | /** X coordinate of the vector */ 788 | readonly x: number; 789 | /** Y coordinate of the vector */ 790 | readonly y: number; 791 | } 792 | 793 | /** A position color pair representing a gradient stop */ 794 | export interface ColorStop { 795 | /** Value between 0 and 1 representing position along gradient axis */ 796 | readonly position: number; 797 | /** Color attached to corresponding position */ 798 | readonly color: Color; 799 | } 800 | 801 | /** Metadata for character formatting */ 802 | export interface TypeStyle { 803 | /** Font family of text (standard name) */ 804 | readonly fontFamily: string; 805 | /** PostScript font name */ 806 | readonly fontPostScriptName: string; 807 | /** Space between paragraphs in px, 0 if not present */ 808 | readonly paragraphSpacing?: number; 809 | /** Paragraph indentation in px, 0 if not present */ 810 | readonly paragraphIndent?: number; 811 | /** Is text italicized? */ 812 | readonly italic?: boolean; 813 | /** Numeric font weight */ 814 | readonly fontWeight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900; 815 | /** Font size in px */ 816 | readonly fontSize: number; 817 | /** Horizontal text alignment as string enum */ 818 | readonly textAlignHorizontal: 'LEFT' | 'RIGHT' | 'CENTER' | 'JUSTIFIED'; 819 | /** Vertical text alignment as string enum */ 820 | readonly textAlignVertical: 'TOP' | 'CENTER' | 'BOTTOM'; 821 | /** Space between characters in px */ 822 | readonly letterSpacing: number; 823 | /** Paints applied to characters */ 824 | readonly fills?: ReadonlyArray; 825 | /** Line height in px */ 826 | readonly lineHeightPx: number; 827 | /** Line height as a percentage of normal line height */ 828 | readonly lineHeightPercent: number; 829 | /** The unit of the line height value specified by the user. */ 830 | readonly lineHeightUnit: 'PIXELS' | 'FONT_SIZE_%' | 'INTRINSIC_%'; 831 | /** Text casing applied to the node, default is the original casing */ 832 | readonly textCase?: 'UPPER' | 'LOWER' | 'TITLE'; 833 | /** Text decoration applied to the node, default is none */ 834 | readonly textDecoration?: 'STRIKETHROUGH' | 'UNDERLINE'; 835 | /** Line height as a percentage of the font size. Only returned when lineHeightPercent is not 100. */ 836 | readonly lineHeightPercentFontSize?: number; 837 | } 838 | 839 | /** 840 | * A description of a master component. Helps you identify which component 841 | * instances are attached to 842 | */ 843 | export interface ComponentMetadata { 844 | /** The unique identifier of the element */ 845 | readonly key: string; 846 | /** The name of the element */ 847 | readonly name: string; 848 | /** The description of the element as entered in the editor */ 849 | readonly description: string; 850 | } 851 | 852 | export interface FrameInfo { 853 | /** Id of the frame node within the figma file */ 854 | readonly node_id: string; 855 | /** The name of the frame */ 856 | readonly name: string; 857 | /** Background color of the frame */ 858 | readonly background_color: string; 859 | /** Id of the frame's residing page */ 860 | readonly page_id: string; 861 | /** Name of the frame's residing page */ 862 | readonly page_name: string; 863 | } 864 | 865 | interface SharedElement extends ComponentMetadata { 866 | /** The unique identifier of the figma file which contains the element */ 867 | readonly file_key: string; 868 | /** Id of the component node within the figma file */ 869 | readonly node_id: string; 870 | /** URL link to the element's thumbnail image */ 871 | readonly thumbnail_url: string; 872 | /** The UTC ISO 8601 time at which the element was created */ 873 | readonly created_at: string; 874 | /** The UTC ISO 8601 time at which the element was updated */ 875 | readonly updated_at: string; 876 | /** The user who last updated the element */ 877 | readonly user: User; 878 | } 879 | 880 | /** 881 | * An arrangement of published UI elements that can be instantiated across figma files 882 | */ 883 | export interface FullComponentMetadata extends SharedElement { 884 | /** Data on component's containing frame, if component resides within a frame */ 885 | readonly containing_frame: FrameInfo; 886 | /** Data on component's containing page, if component resides in a multi-page file */ 887 | readonly containing_page: any; // broken link in the doc 888 | } 889 | 890 | export interface FullStyleMetadata extends SharedElement { 891 | /** The type of style */ 892 | readonly style_type: StyleType; 893 | /** A user specified order number by which the style can be sorted */ 894 | readonly sort_position: string; 895 | } 896 | 897 | /** 898 | * A description of styles used in a file. 899 | */ 900 | export interface Style { 901 | /** The name of the stlye */ 902 | readonly name: string; 903 | /** A description of the style */ 904 | readonly description: string; 905 | /** The unique identifier of the style */ 906 | readonly key: string; 907 | /** The type of style */ 908 | readonly styleType: StyleType; 909 | } 910 | 911 | // General API Types 912 | 913 | /** A comment or reply left by a user */ 914 | export interface Comment { 915 | /** Unique identifier for comment */ 916 | readonly id: string; 917 | /** The file in which the comment lives */ 918 | readonly file_key: string; 919 | /** If present, the id of the comment to which this is the reply */ 920 | readonly parent_id: string; 921 | /** The user who left the comment */ 922 | readonly user: User; 923 | /** The time at which the comment was left */ 924 | readonly created_at: Date; 925 | /** If set, when the comment was resolved */ 926 | readonly resolved_at: Date | null; 927 | /** 928 | * (MISSING IN DOCS) 929 | * The content of the comment 930 | */ 931 | readonly message: string; 932 | readonly client_meta: Vector2 | FrameOffset; 933 | /** 934 | * Only set for top level comments. The number displayed with the 935 | * comment in the UI 936 | */ 937 | readonly order_id: number; 938 | } 939 | 940 | /** A description of a user */ 941 | export interface User { 942 | /** Unique stable id of the user */ 943 | readonly id: string; 944 | /** Name of the user */ 945 | readonly handle: string; 946 | /** URL link to the user's profile image */ 947 | readonly img_url: string; 948 | } 949 | 950 | /** A relative offset within a frame */ 951 | export interface FrameOffset { 952 | /** Unique id specifying the frame */ 953 | readonly node_id: string; 954 | /** 2d vector offset within the frame */ 955 | readonly node_offset: Vector2; 956 | } 957 | 958 | export interface ProjectSummary { 959 | readonly id: string; 960 | readonly name: string; 961 | } 962 | 963 | export interface FileResponse { 964 | readonly components: { 965 | readonly [key: string]: ComponentMetadata; 966 | }; 967 | readonly styles: { 968 | readonly [key: string]: Style; 969 | }; 970 | readonly document: Document; 971 | readonly lastModified: string; 972 | readonly name: string; 973 | readonly role: RoleType; 974 | readonly schemaVersion: number; 975 | readonly thumbnailUrl: string; 976 | readonly version: string; 977 | } 978 | 979 | export interface FileNodesResponse { 980 | readonly nodes: { 981 | readonly [key: string]: null | { 982 | readonly document: Node; 983 | readonly components: { 984 | readonly [key: string]: ComponentMetadata; 985 | }; 986 | readonly styles: { 987 | readonly [key: string]: Style; 988 | }; 989 | readonly schemaVersion: number; 990 | }; 991 | }; 992 | readonly lastModified: string; 993 | readonly name: string; 994 | readonly role: RoleType; 995 | readonly thumbnailUrl: string; 996 | readonly version: string; 997 | } 998 | 999 | export interface VersionMetadata { 1000 | /** Unique identifier for version */ 1001 | readonly id: string; 1002 | /** The UTC ISO 8601 time at which the version was created */ 1003 | readonly created_at: string; 1004 | /** The label given to the version in the editor */ 1005 | readonly label: string; 1006 | /** The description of the version as entered in the editor */ 1007 | readonly description: string; 1008 | /** The user that created the version */ 1009 | readonly user: User; 1010 | } 1011 | 1012 | export interface FileVersionsResponse { 1013 | readonly versions: ReadonlyArray; 1014 | } 1015 | 1016 | export interface FileImageResponse { 1017 | readonly err: string | null; 1018 | readonly images: { 1019 | readonly [key: string]: string; 1020 | }; 1021 | } 1022 | 1023 | export interface FileImageFillsResponse { 1024 | readonly error: boolean; 1025 | readonly status: number; 1026 | readonly meta: { 1027 | readonly images: { 1028 | readonly [key: string]: string; 1029 | }; 1030 | }; 1031 | } 1032 | 1033 | export interface CommentsResponse { 1034 | readonly comments: ReadonlyArray; 1035 | } 1036 | 1037 | export interface ComponentResponse { 1038 | readonly error: boolean; 1039 | readonly status: number; 1040 | readonly meta: FullComponentMetadata; 1041 | } 1042 | 1043 | export interface ComponentSetResponse { 1044 | readonly error: boolean; 1045 | readonly status: number; 1046 | readonly meta: FullComponentMetadata; 1047 | } 1048 | 1049 | export interface StyleResponse { 1050 | readonly error: boolean; 1051 | readonly status: number; 1052 | readonly meta: FullStyleMetadata; 1053 | } 1054 | 1055 | export interface FileSummary { 1056 | readonly key: string; 1057 | readonly name: string; 1058 | readonly thumbnail_url: string; 1059 | readonly last_modified: string; 1060 | } 1061 | 1062 | export interface TeamProjectsResponse { 1063 | readonly name: string; 1064 | readonly projects: ReadonlyArray; 1065 | } 1066 | 1067 | export interface ProjectFilesResponse { 1068 | readonly name: string; 1069 | readonly files: ReadonlyArray; 1070 | } 1071 | 1072 | interface PaginationMeta { 1073 | readonly before: number; 1074 | readonly after: number; 1075 | } 1076 | 1077 | export interface TeamComponentsResponse { 1078 | readonly error: boolean; 1079 | readonly status: number; 1080 | readonly meta: { 1081 | readonly components: ReadonlyArray; 1082 | readonly cursor: PaginationMeta; 1083 | }; 1084 | } 1085 | 1086 | export interface FileComponentsResponse { 1087 | readonly error: boolean; 1088 | readonly status: number; 1089 | readonly meta: { 1090 | readonly components: ReadonlyArray; 1091 | }; 1092 | } 1093 | 1094 | export interface TeamComponentSetsResponse { 1095 | readonly error: boolean; 1096 | readonly status: number; 1097 | readonly meta: { 1098 | readonly component_sets: ReadonlyArray; 1099 | readonly cursor: PaginationMeta; 1100 | }; 1101 | } 1102 | 1103 | export interface FileComponentSetsResponse { 1104 | readonly error: boolean; 1105 | readonly status: number; 1106 | readonly meta: { 1107 | readonly component_sets: ReadonlyArray; 1108 | }; 1109 | } 1110 | 1111 | export interface TeamStylesResponse { 1112 | readonly error: boolean; 1113 | readonly status: number; 1114 | readonly meta: { 1115 | readonly styles: ReadonlyArray; 1116 | readonly cursor: PaginationMeta; 1117 | }; 1118 | } 1119 | 1120 | export interface FileStylesResponse { 1121 | readonly error: boolean; 1122 | readonly status: number; 1123 | readonly meta: { 1124 | readonly styles: ReadonlyArray; 1125 | }; 1126 | } 1127 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | // export * from './lib/number'; 2 | import * as Figma from './figmaTypes'; 3 | export * from './figmaTypes'; 4 | import axios, { AxiosInstance, AxiosPromise } from 'axios'; 5 | 6 | export interface FileParams { 7 | /** 8 | * A list of nodes that you care about in the document. 9 | * If specified, only a subset of the document will be returned corresponding to the nodes listed, their children, and everything between the root node and the listed nodes 10 | */ 11 | readonly ids?: ReadonlyArray; 12 | 13 | /** 14 | * Positive integer representing how deep into the document tree to traverse. 15 | * For example, setting this to 1 returns only Pages, setting it to 2 returns Pages and all top level objects on each page. 16 | * Not setting this parameter returns all nodes 17 | */ 18 | readonly depth?: number; 19 | 20 | /** 21 | * A specific version ID to get. Omitting this will get the current version of the file 22 | */ 23 | readonly version?: string; 24 | 25 | /** 26 | * Set to "paths" to export vector data 27 | */ 28 | readonly geometry?: string; 29 | 30 | /** 31 | * A comma separated list of plugin IDs and/or the string "shared". 32 | * Any data present in the document written by those plugins will be included in the result in the `pluginData` and `sharedPluginData` properties. 33 | */ 34 | readonly plugin_data?: string; 35 | } 36 | 37 | export interface FileNodesParams { 38 | /** A list of node IDs to retrieve and convert */ 39 | readonly ids: ReadonlyArray; 40 | 41 | /** 42 | * A specific version ID to get. Omitting this will get the current version of the file 43 | */ 44 | readonly version?: string; 45 | 46 | /** 47 | * Set to "paths" to export vector data 48 | */ 49 | readonly geometry?: string; 50 | 51 | /** 52 | * A comma separated list of plugin IDs and/or the string "shared". 53 | * Any data present in the document written by those plugins will be included in the result in the `pluginData` and `sharedPluginData` properties. 54 | */ 55 | readonly plugin_data?: string; 56 | } 57 | 58 | export type exportFormatOptions = 'jpg' | 'png' | 'svg' | 'pdf'; 59 | 60 | export interface FileImageParams { 61 | /** A list of node IDs to render */ 62 | readonly ids: ReadonlyArray; 63 | /** A number between 0.01 and 4, the image scaling factor */ 64 | readonly scale?: number; 65 | /** A string enum for the image output format, can be "jpg", "png", "svg", or "pdf" */ 66 | readonly format?: exportFormatOptions; 67 | /** 68 | * Whether to include id attributes for all SVG elements. 69 | * @default false 70 | */ 71 | readonly svg_include_id?: boolean; 72 | /** 73 | * Whether to simplify inside/outside strokes and use stroke attribute if 74 | * possible instead of . 75 | * @default true 76 | */ 77 | readonly svg_simplify_stroke?: boolean; 78 | /** 79 | * Use the full dimensions of the node regardless of whether or not it is cropped or the space around it is empty. 80 | * Use this to export text nodes without cropping. 81 | * @default false 82 | */ 83 | readonly use_absolute_bounds?: boolean; 84 | /** A specific version ID to use. Omitting this will use the current version of the file */ 85 | readonly version?: string; 86 | } 87 | 88 | export interface PostCommentParams { 89 | /** The text contents of the comment to post */ 90 | readonly message: string; 91 | /** The absolute canvas position of where to place the comment */ 92 | readonly client_meta?: Figma.Vector2 | Figma.FrameOffset; 93 | /** The comment to reply to, if any. This must be a root comment, that is, you cannot reply to a comment that is a reply itself (a reply has a parent_id). */ 94 | readonly comment_id?: string; 95 | } 96 | 97 | export interface PaginationParams { 98 | /** 99 | * Number of items in a paged list of results. 100 | * @default 30 101 | */ 102 | readonly page_size?: number; 103 | /** 104 | * A map that indicates the starting/ending point from which objects are returned. 105 | * The cursor value is an internally tracked integer that doesn't correspond to any Ids 106 | */ 107 | readonly cursor?: { readonly before?: number; readonly after?: number }; 108 | } 109 | 110 | export interface ClientOptions { 111 | /** access token returned from OAuth authentication */ 112 | readonly accessToken?: string; 113 | /** personal access token obtained from account settings */ 114 | readonly personalAccessToken?: string; 115 | /** custom API root */ 116 | readonly apiRoot?: string; 117 | } 118 | 119 | export interface ClientInterface { 120 | readonly client: AxiosInstance; 121 | /** 122 | * Returns the document refered to by :key as a JSON object. 123 | * The file key can be parsed from any Figma file url: 124 | * https://www.figma.com/file/:key/:title. 125 | * The "document" attribute contains a Node of type DOCUMENT. 126 | * @param {fileId} String File to export JSON from 127 | * @see https://www.figma.com/developers/api#get-files-endpoint 128 | */ 129 | readonly file: ( 130 | fileId: string, 131 | params?: FileParams 132 | ) => AxiosPromise; 133 | 134 | /** 135 | * Returns a list of the versions of a file. 136 | * The file key can be parsed from any Figma node url: 137 | * https://www.figma.com/file/:key/:title. 138 | * @param {fileId} String File to get version history from 139 | * @see https://www.figma.com/developers/api#get-file-versions-endpoint 140 | */ 141 | readonly fileVersions: ( 142 | fileId: string 143 | ) => AxiosPromise; 144 | 145 | /** 146 | * Returns the nodes referenced to by :ids as a JSON object. 147 | * The nodes are retrieved from the Figma file referenced to by :key. 148 | * The node Id and file key can be parsed from any Figma node url: 149 | * https://www.figma.com/file/:key/:title?node-id=:id. 150 | * @param {fileId} String File to export JSON from 151 | * @param {params} FileNodesParams 152 | * @see https://www.figma.com/developers/api#get-file-nodes-endpoint 153 | */ 154 | readonly fileNodes: ( 155 | fileId: string, 156 | params: FileNodesParams 157 | ) => AxiosPromise; 158 | 159 | /** 160 | * If no error occurs, "images" will be populated with a map from 161 | * node IDs to URLs of the rendered images, and "status" will be omitted. 162 | * Important: the image map may contain values that are null. 163 | * This indicates that rendering of that specific node has failed. 164 | * This may be due to the node id not existing, or other reasons such 165 | * has the node having no renderable components. It is guaranteed that 166 | * any node that was requested for rendering will be represented in this 167 | * map whether or not the render succeeded. 168 | * @param {fileId} String File to export images from 169 | * @param {params} FileImageParams 170 | * @see https://www.figma.com/developers/api#get-images-endpoint 171 | */ 172 | readonly fileImages: ( 173 | fileId: string, 174 | params: FileImageParams 175 | ) => AxiosPromise; 176 | 177 | /** 178 | * Returns download links for all images present in image fills in a document. 179 | * Image fills are how Figma represents any user supplied images. 180 | * When you drag an image into Figma, we create a rectangle with a single 181 | * fill that represents the image, and the user is able to transform the 182 | * rectangle (and properties on the fill) as they wish. 183 | * 184 | * This endpoint returns a mapping from image references to the URLs at which 185 | * the images may be download. Image URLs will expire after no more than 14 days. 186 | * Image references are located in the output of the GET files endpoint under the 187 | * imageRef attribute in a Paint. 188 | * @param {fileId} String File to export images from 189 | * @see https://www.figma.com/developers/api#get-image-fills-endpoint 190 | */ 191 | readonly fileImageFills: ( 192 | fileId: string 193 | ) => AxiosPromise; 194 | 195 | /** 196 | * A list of comments left on the file 197 | * @param {fileId} String File to get comments from 198 | * @see https://www.figma.com/developers/api#get-comments-endpoint 199 | */ 200 | readonly comments: (fileId: string) => AxiosPromise; 201 | 202 | /** 203 | * Posts a new comment on the file. 204 | * @param {fileId} String File to post comment to 205 | * @param {params} PostCommentParams 206 | * @see https://www.figma.com/developers/api#post-comments-endpoint 207 | */ 208 | readonly postComment: ( 209 | fileId: string, 210 | params: PostCommentParams 211 | ) => AxiosPromise; 212 | 213 | /** 214 | * Delete a comment from the file 215 | * @param {fileId} String File to delete comment from 216 | * @param {commentId} String id of the comment to be deleted 217 | * @see https://www.figma.com/developers/api#delete-comments-endpoint 218 | */ 219 | readonly deleteComment: ( 220 | fileId: string, 221 | commentId: string 222 | ) => AxiosPromise; 223 | 224 | /** 225 | * Get user information for the authenticated user. 226 | * @see https://www.figma.com/developers/api#get-me-endpoint 227 | */ 228 | readonly me: () => AxiosPromise; 229 | 230 | /** 231 | * Lists the projects for a specified team. Note that this will only 232 | * return projects visible to the authenticated user or owner of the 233 | * developer token. 234 | * @param {teamId} String Id of the team to list projects from 235 | * @see https://www.figma.com/developers/api#get-team-projects-endpoint 236 | */ 237 | readonly teamProjects: ( 238 | teamId: string 239 | ) => AxiosPromise; 240 | 241 | /** 242 | * List the files in a given project. 243 | * @param {projectId} String Id of the project to list files from 244 | * @see https://www.figma.com/developers/api#get-project-files-endpoint 245 | */ 246 | readonly projectFiles: ( 247 | projectId: string 248 | ) => AxiosPromise; 249 | 250 | /** 251 | * Get a paginated list of published components within a team library 252 | * @param {teamId} String Id of the team to list components from 253 | * @see https://www.figma.com/developers/api#get-team-components-endpoint 254 | */ 255 | readonly teamComponents: ( 256 | teamId: string, 257 | params?: PaginationParams 258 | ) => AxiosPromise; 259 | 260 | /** 261 | * Get a list of published components within a file 262 | * @param {fileId} String Id of the file to list components from 263 | * @see https://www.figma.com/developers/api#get-file-components-endpoint 264 | */ 265 | readonly fileComponents: ( 266 | fileId: string 267 | ) => AxiosPromise; 268 | 269 | /** 270 | * Get metadata on a component by key. 271 | * @param {key} The unique identifier of the component. 272 | * @see https://www.figma.com/developers/api#get-component-endpoint 273 | */ 274 | 275 | readonly component: (key: string) => AxiosPromise; 276 | 277 | /** 278 | * Get a paginated list of published component sets within a team library 279 | * @param {teamId} String Id of the team to list components from 280 | * @see https://www.figma.com/developers/api#get-team-component-sets-endpoint 281 | */ 282 | readonly teamComponentSets: ( 283 | teamId: string, 284 | params?: PaginationParams 285 | ) => AxiosPromise; 286 | 287 | /** 288 | * Get a list of published component sets within a file 289 | * @param {fileId} String Id of the file to list components from 290 | * @see https://www.figma.com/developers/api#get-team-component-sets-endpoint 291 | */ 292 | readonly fileComponentSets: ( 293 | fileId: string 294 | ) => AxiosPromise; 295 | 296 | /** 297 | * Get metadata on a component set by key. 298 | * @param {key} The unique identifier of the component. 299 | * @see https://www.figma.com/developers/api#get-component-sets-endpoint 300 | */ 301 | 302 | readonly componentSet: ( 303 | key: string 304 | ) => AxiosPromise; 305 | 306 | /** 307 | * Get a paginated list of published styles within a team library 308 | * @param {teamId} String Id of the team to list styles from 309 | * @see https://www.figma.com/developers/api#get-team-styles-endpoint 310 | */ 311 | readonly teamStyles: ( 312 | teamId: string, 313 | params?: PaginationParams 314 | ) => AxiosPromise; 315 | 316 | /** 317 | * Get a list of published styles within a file 318 | * @param {fileId} String Id of the file to list styles from 319 | * @see https://www.figma.com/developers/api#get-file-styles-endpoint 320 | */ 321 | readonly fileStyles: ( 322 | fileId: string 323 | ) => AxiosPromise; 324 | 325 | /** 326 | * Get metadata on a style by key. 327 | * @param {key} The unique identifier of the style. 328 | * @see https://www.figma.com/developers/api#get-style-endpoint 329 | */ 330 | readonly style: (key: string) => AxiosPromise; 331 | } 332 | 333 | export const Client = (opts: ClientOptions): ClientInterface => { 334 | const headers = opts.accessToken 335 | ? { 336 | Authorization: `Bearer ${opts.accessToken}`, 337 | } 338 | : { 339 | 'X-Figma-Token': opts.personalAccessToken, 340 | }; 341 | 342 | const client = axios.create({ 343 | baseURL: `https://${opts.apiRoot || 'api.figma.com'}/v1/`, 344 | headers, 345 | }); 346 | 347 | return { 348 | client, 349 | 350 | file: (fileId, params = {}) => 351 | client.get(`files/${fileId}`, { 352 | params: { 353 | ...params, 354 | ids: params.ids ? params.ids.join(',') : '', 355 | }, 356 | }), 357 | 358 | fileVersions: (fileId) => client.get(`files/${fileId}/versions`), 359 | 360 | fileNodes: (fileId, params) => 361 | client.get(`files/${fileId}/nodes`, { 362 | params: { 363 | ...params, 364 | ids: params.ids.join(','), 365 | }, 366 | }), 367 | 368 | fileImages: (fileId, params) => 369 | client.get(`images/${fileId}`, { 370 | params: { 371 | ...params, 372 | ids: params.ids.join(','), 373 | }, 374 | }), 375 | 376 | fileImageFills: (fileId) => client.get(`files/${fileId}/images`), 377 | 378 | comments: (fileId) => client.get(`files/${fileId}/comments`), 379 | 380 | postComment: (fileId, params) => 381 | client.post(`files/${fileId}/comments`, params), 382 | 383 | deleteComment: (fileId, commentId) => 384 | client.delete(`files/${fileId}/comments/${commentId}`), 385 | 386 | me: () => client.get(`me`), 387 | 388 | teamProjects: (teamId) => client.get(`teams/${teamId}/projects`), 389 | 390 | projectFiles: (projectId) => client.get(`projects/${projectId}/files`), 391 | 392 | teamComponents: (teamId, params = {}) => 393 | client.get(`teams/${teamId}/components`, { params }), 394 | 395 | fileComponents: (fileId) => client.get(`files/${fileId}/components`), 396 | 397 | component: (key) => client.get(`components/${key}`), 398 | 399 | teamComponentSets: (teamId, params = {}) => 400 | client.get(`teams/${teamId}/component_sets`, { params }), 401 | 402 | fileComponentSets: (fileId) => client.get(`files/${fileId}/component_sets`), 403 | 404 | componentSet: (key) => client.get(`component_set/${key}`), 405 | 406 | teamStyles: (teamId, params = {}) => 407 | client.get(`teams/${teamId}/styles`, { params }), 408 | 409 | fileStyles: (fileId) => client.get(`files/${fileId}/styles`), 410 | 411 | style: (key) => client.get(`styles/${key}`), 412 | }; 413 | }; 414 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "outDir": "build/main", 5 | "rootDir": "src", 6 | "moduleResolution": "node", 7 | "module": "commonjs", 8 | "declaration": true, 9 | "inlineSourceMap": true, 10 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, 11 | 12 | // "strict": true /* Enable all strict type-checking options. */, 13 | 14 | /* Strict Type-Checking Options */ 15 | // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, 16 | "strictNullChecks": true /* Enable strict null checks. */, 17 | // "strictFunctionTypes": true /* Enable strict checking of function types. */, 18 | // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, 19 | // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, 20 | // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, 21 | 22 | /* Additional Checks */ 23 | "noUnusedLocals": true /* Report errors on unused locals. */, 24 | "noUnusedParameters": true /* Report errors on unused parameters. */, 25 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, 26 | "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, 27 | 28 | /* Debugging Options */ 29 | "traceResolution": false /* Report module resolution log messages. */, 30 | "listEmittedFiles": false /* Print names of generated files part of the compilation. */, 31 | "listFiles": false /* Print names of files part of the compilation. */, 32 | "pretty": true /* Stylize errors and messages using color and context. */, 33 | 34 | /* Experimental Options */ 35 | // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, 36 | // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, 37 | 38 | "lib": ["es2017"], 39 | "types": [], 40 | "typeRoots": ["node_modules/@types", "src/types"] 41 | }, 42 | "include": ["src/**/*.ts"], 43 | "exclude": ["node_modules/**"], 44 | "compileOnSave": false 45 | } 46 | -------------------------------------------------------------------------------- /tsconfig.module.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "compilerOptions": { 4 | "target": "es5", 5 | "outDir": "build/module", 6 | "module": "esnext" 7 | }, 8 | "exclude": ["node_modules/**"] 9 | } 10 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint:latest", "tslint-config-prettier", "tslint-immutable"], 3 | "rules": { 4 | "interface-name": [true, "never-prefix"], 5 | // TODO: allow devDependencies only in **/*.spec.ts files: 6 | // waiting on https://github.com/palantir/tslint/pull/3708 7 | "no-implicit-dependencies": [true, "dev"], 8 | 9 | /* tslint-immutable rules */ 10 | // Recommended built-in rules 11 | "no-var-keyword": true, 12 | "no-parameter-reassignment": true, 13 | "typedef": [true, "call-signature"], 14 | 15 | // Immutability rules 16 | "readonly-keyword": true, 17 | "readonly-array": true, 18 | "no-let": true, 19 | "no-object-mutation": true, 20 | "no-delete": true, 21 | "no-method-signature": true, 22 | 23 | // Functional style rules 24 | "no-this": true, 25 | "no-class": true, 26 | "no-mixed-interface": false, 27 | "no-expression-statement": [ 28 | true, 29 | { "ignore-prefix": ["console.", "process.exit"] } 30 | ], 31 | "no-if-statement": true 32 | /* end tslint-immutable rules */ 33 | } 34 | } 35 | --------------------------------------------------------------------------------