├── .gitignore ├── c ├── math.h ├── stb_image.c ├── string.h └── stdlib.h ├── img ├── tsodinPog-112.png └── tsodinThink-113.png ├── wasm └── stb_image.wasm ├── package.json ├── index.html ├── ts ├── demo.ts └── stb_image.ts ├── js ├── demo.js.map ├── demo.js ├── stb_image.js.map └── stb_image.js ├── LICENSE ├── README.md └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /c/math.h: -------------------------------------------------------------------------------- 1 | #ifndef MATH_H_ 2 | #define MATH_H_ 3 | 4 | #endif // MATH_H_ 5 | -------------------------------------------------------------------------------- /img/tsodinPog-112.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsoding/stb_image_js/HEAD/img/tsodinPog-112.png -------------------------------------------------------------------------------- /wasm/stb_image.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsoding/stb_image_js/HEAD/wasm/stb_image.wasm -------------------------------------------------------------------------------- /img/tsodinThink-113.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsoding/stb_image_js/HEAD/img/tsodinThink-113.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stb_image_js", 3 | "version": "1.0.0", 4 | "description": "stb_image.h wrapper for a Web Browser", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Alexey Kutepov ", 10 | "license": "MIT", 11 | "devDependencies": { 12 | "typescript": "^5.0.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /c/stb_image.c: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | 3 | #define STBI_NO_STDIO 4 | #define STBI_ASSERT(...) 5 | // TODO: add support for HDR 6 | // HDR requires support for strcmp, strncmp and strtol and I'm just too lazy rn to implement them 7 | #define STBI_NO_HDR 8 | #define STBI_NO_LINEAR 9 | 10 | #define STBI_MALLOC malloc 11 | #define STBI_FREE(...) 12 | #define STBI_REALLOC_SIZED realloc_sized 13 | 14 | #include "stb_image.h" 15 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | stb_image.js 4 | 5 | 6 |

stb_image_js Demo

7 |

See https://github.com/tsoding/stb_image_js for more info.

8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /c/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H_ 2 | #define STRING_H_ 3 | 4 | typedef unsigned long size_t; 5 | 6 | void *memset(void *s, int c, size_t n) 7 | { 8 | char *sc = s; 9 | for (size_t i = 0; i < n; ++i) *sc++ = c; 10 | return s; 11 | } 12 | 13 | void *memcpy(void *dest, const void *src, size_t n) 14 | { 15 | char *cdest = dest; 16 | const char *csrc = src; 17 | for (size_t i = 0; i < n; ++i) *cdest++ = *csrc++; 18 | return dest; 19 | } 20 | 21 | #endif // STRING_H_ 22 | -------------------------------------------------------------------------------- /ts/demo.ts: -------------------------------------------------------------------------------- 1 | async function start() { 2 | const tsodinPog = await stbi_load_from_url("img/tsodinPog-112.png"); 3 | const tsodinThink = await stbi_load_from_url("img/tsodinThink-113.png"); 4 | 5 | const appId = "app"; 6 | const app = document.getElementById(appId) as HTMLCanvasElement; 7 | if (app === null) { 8 | throw new Error(`Could not find canvas with id ${appId}`); 9 | } 10 | app.width = tsodinPog.width + tsodinThink.width; 11 | app.height = Math.max(tsodinPog.height, tsodinThink.height); 12 | const ctx = app.getContext("2d"); 13 | if (ctx === null) { 14 | throw new Error("Could not create 2d context"); 15 | } 16 | ctx.putImageData(tsodinPog, 0, 0); 17 | ctx.putImageData(tsodinThink, tsodinPog.width, 0); 18 | } 19 | start(); 20 | 21 | -------------------------------------------------------------------------------- /js/demo.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"demo.js","sourceRoot":"","sources":["../ts/demo.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,SAAe,KAAK;;QAChB,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;QACpE,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;QAExE,MAAM,KAAK,GAAG,KAAK,CAAC;QACpB,MAAM,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAsB,CAAC;QAChE,IAAI,GAAG,KAAK,IAAI,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;SAC7D;QACD,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;QAChD,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,GAAG,KAAK,IAAI,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAClD;QACD,GAAG,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;CAAA;AACD,KAAK,EAAE,CAAC"} -------------------------------------------------------------------------------- /c/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef STDLIB_H_ 2 | #define STDLIB_H_ 3 | 4 | #include 5 | 6 | extern char __heap_base; 7 | static char *bump = &__heap_base; 8 | 9 | void heap_reset(void) 10 | { 11 | bump = &__heap_base; 12 | } 13 | 14 | void *malloc(size_t s) 15 | { 16 | // |****|****|** 17 | // |****|****|****|** +3 18 | // |****|****|****| /4*4 19 | /////////////////////////// 20 | // |****|****| 21 | // |****|****|*** +3 22 | // |****|****| /4*4 23 | s = (s + 3)/4*4; 24 | void *result = bump; 25 | bump += s; 26 | return result; 27 | } 28 | 29 | void *realloc_sized(void *oldptr, size_t oldsz, size_t newsz) 30 | { 31 | if (oldsz >= newsz) return oldptr; 32 | void *newptr = malloc(newsz); 33 | memcpy(newptr, oldptr, oldsz); 34 | return newptr; 35 | } 36 | 37 | int abs(int j) 38 | { 39 | if (j < 0) j = -j; 40 | return j; 41 | } 42 | 43 | #endif // STDLIB_H_ 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2023 Alexey Kutepov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /js/demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | function start() { 12 | return __awaiter(this, void 0, void 0, function* () { 13 | const tsodinPog = yield stbi_load_from_url("img/tsodinPog-112.png"); 14 | const tsodinThink = yield stbi_load_from_url("img/tsodinThink-113.png"); 15 | const appId = "app"; 16 | const app = document.getElementById(appId); 17 | if (app === null) { 18 | throw new Error(`Could not find canvas with id ${appId}`); 19 | } 20 | app.width = tsodinPog.width + tsodinThink.width; 21 | app.height = Math.max(tsodinPog.height, tsodinThink.height); 22 | const ctx = app.getContext("2d"); 23 | if (ctx === null) { 24 | throw new Error("Could not create 2d context"); 25 | } 26 | ctx.putImageData(tsodinPog, 0, 0); 27 | ctx.putImageData(tsodinThink, tsodinPog.width, 0); 28 | }); 29 | } 30 | start(); 31 | //# sourceMappingURL=demo.js.map -------------------------------------------------------------------------------- /js/stb_image.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"stb_image.js","sourceRoot":"","sources":["../ts/stb_image.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAelD,MAAM,aAAa,GAA2B,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE;IACvG,GAAG,EAAE,EAAE;CACV,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;IACV,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAA4B,CAAC;IAC/D,gDAAgD;IAChD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO;QACH,QAAQ,EAAE,MAAM;QAChB,uBAAuB,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,qBAAmD;QAC/F,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAqB;QAClD,YAAY,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,UAA6B;KACjE,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,SAAe,0BAA0B,CAAC,WAA+C;;QACrF,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,WAAW,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC;QACtC,+GAA+G;QAC/G,SAAS,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;QAC1B,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,IAAI,iBAAiB,CAAC,CAAC,GAAC,CAAC,GAAC,CAAC,CAAC,CAAC;QAC/C,4FAA4F;QAC5F,SAAS,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC;QAC7E,OAAO,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;CAAA;AAED,SAAe,kBAAkB,CAAC,GAAgB;;QAC9C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,0BAA0B,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9D,CAAC;CAAA"} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stb\_image\_js 2 | 3 | [stb_image.h](https://github.com/nothings/stb) wrapper for a Web Browser. Or any JavaScript environment that supports [WebAssembly](https://webassembly.org/) and [fetch()](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) 4 | 5 | What we did is basically compiled [stb_image.h](https://github.com/nothings/stb) to a self-contained WASM module and wrote a simple js wrapper that takes the bytes of image files, feeds them into the WASM module, receives the parsed pixels and constructs [ImageData](https://developer.mozilla.org/en-US/docs/Web/API/ImageData) out of them. So you can download an image and get its ImageData in one go if you ever wanted to do it this way. 6 | 7 | ## Quick Start 8 | 9 | 1. Copy [js/stb_image.js](./js/stb_image.js) and [wasm/stb_image.wasm](./wasm/stb_image.wasm) file to your website to `js` and `wasm` folder correpondingly. 10 | 1. Modify `STB_IMAGE_WASM_PATH` in [js/stb_image.js](./js/stb_image.js) if you want a different path to [wasm/stb_image.wasm](./wasm/stb_image.wasm). 11 | 1. `` 12 | 1. 13 | 14 | ```javascript 15 | const canvas = document.getElementById("canvas-id"); 16 | const ctx = canvas.getContext("2d"); 17 | stbi_load_from_url("image.png").then((image) => ctx.putImageData(image, 0, 0)); 18 | ``` 19 | 20 | *I'll eventually turn this into a proper npm package. Just copy the files for now. It's simple and straightforward. You have everything you need in here. See Demo for more info. The whole codebase is dead simple. You can learn it in less than an hour. I believe in you.* 21 | 22 | ## Demo 23 | 24 | The demo consists of two files: [index.html](./index.html) and [js/demo.js](./js/demo.js) compiled from [ts/demo.ts](./ts/demo.ts) (that's probably the one you wanna read). It loads up images from [./img/](./img/) folder using [js/stb_image.js](./js/stb_image.js) and puts them into the canvas. 25 | 26 | If you want to run it locally just run something like 27 | 28 | ```console 29 | $ python3 -m http.server 6969 # or any other lightweight HTTP server of your choice 30 | $ browser http://localhost:6969/ 31 | ``` 32 | 33 | You can also find it deployed at https://tsoding.github.io/stb_image_js/ 34 | 35 | ## Rebuilding `stb_image.wasm` 36 | 37 | You will need clang 13.0.0+: 38 | 39 | ```console 40 | $ node build-wasm.js 41 | ``` 42 | 43 | ## Rebuilding the JS files 44 | 45 | ```console 46 | $ npm install 47 | $ ./node_modules/.bin/tsc 48 | ``` 49 | -------------------------------------------------------------------------------- /ts/stb_image.ts: -------------------------------------------------------------------------------- 1 | const STB_IMAGE_WASM_PATH = "wasm/stb_image.wasm"; 2 | 3 | type pointer = number; 4 | 5 | type stbi_load_from_memory_type = (buf: pointer, len: number, x: number, y: number, channels_in_file: pointer, desired_channels: number) => pointer; 6 | type malloc_type = (s: number) => pointer; 7 | type heap_reset_type = () => void; 8 | 9 | interface Stb_Image_Raw { 10 | stbi_load_from_memory: stbi_load_from_memory_type; 11 | malloc: malloc_type; 12 | heap_reset: heap_reset_type; 13 | memory: WebAssembly.Memory; 14 | } 15 | 16 | const stb_image_raw: Promise = WebAssembly.instantiateStreaming(fetch(STB_IMAGE_WASM_PATH), { 17 | env: {}, 18 | }).then((w) => { 19 | const memory = w.instance.exports.memory as WebAssembly.Memory; 20 | // TODO: grow the memory automatically as needed 21 | memory.grow(10); 22 | return { 23 | "memory": memory, 24 | "stbi_load_from_memory": w.instance.exports.stbi_load_from_memory as stbi_load_from_memory_type, 25 | "malloc": w.instance.exports.malloc as malloc_type, 26 | "heap_reset": w.instance.exports.heap_reset as heap_reset_type, 27 | }; 28 | }); 29 | 30 | async function stbi_load_from_arraybuffer(arrayBuffer: ArrayBuffer | Promise): Promise { 31 | const buffer = new Uint8Array(await arrayBuffer); 32 | const stb_image = await stb_image_raw; 33 | // TODO: maybe we should expose all of this memory management to the user so we don't have to do the copy below 34 | stb_image.heap_reset(); 35 | const len = buffer.length; 36 | const buf = stb_image.malloc(len); 37 | new Uint8Array(stb_image.memory.buffer, buf, len).set(buffer); 38 | const x = stb_image.malloc(4); 39 | const y = stb_image.malloc(4); 40 | const pixels = stb_image.stbi_load_from_memory(buf, len, x, y, 0, 4); 41 | const w = new Uint32Array(stb_image.memory.buffer, x, 1)[0]; 42 | const h = new Uint32Array(stb_image.memory.buffer, y, 1)[0]; 43 | const imageData = new Uint8ClampedArray(w*h*4); 44 | // Copying the image data cause the next call to stb_image.heap_reset() above will erase it. 45 | imageData.set(new Uint8ClampedArray(stb_image.memory.buffer, pixels, w*h*4)); 46 | return new ImageData(imageData, w); 47 | } 48 | 49 | async function stbi_load_from_url(url: RequestInfo): Promise { 50 | const response = await fetch(url); 51 | return stbi_load_from_arraybuffer(response.arrayBuffer()); 52 | } 53 | -------------------------------------------------------------------------------- /js/stb_image.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | const STB_IMAGE_WASM_PATH = "wasm/stb_image.wasm"; 12 | const stb_image_raw = WebAssembly.instantiateStreaming(fetch(STB_IMAGE_WASM_PATH), { 13 | env: {}, 14 | }).then((w) => { 15 | const memory = w.instance.exports.memory; 16 | // TODO: grow the memory automatically as needed 17 | memory.grow(10); 18 | return { 19 | "memory": memory, 20 | "stbi_load_from_memory": w.instance.exports.stbi_load_from_memory, 21 | "malloc": w.instance.exports.malloc, 22 | "heap_reset": w.instance.exports.heap_reset, 23 | }; 24 | }); 25 | function stbi_load_from_arraybuffer(arrayBuffer) { 26 | return __awaiter(this, void 0, void 0, function* () { 27 | const buffer = new Uint8Array(yield arrayBuffer); 28 | const stb_image = yield stb_image_raw; 29 | // TODO: maybe we should expose all of this memory management to the user so we don't have to do the copy below 30 | stb_image.heap_reset(); 31 | const len = buffer.length; 32 | const buf = stb_image.malloc(len); 33 | new Uint8Array(stb_image.memory.buffer, buf, len).set(buffer); 34 | const x = stb_image.malloc(4); 35 | const y = stb_image.malloc(4); 36 | const pixels = stb_image.stbi_load_from_memory(buf, len, x, y, 0, 4); 37 | const w = new Uint32Array(stb_image.memory.buffer, x, 1)[0]; 38 | const h = new Uint32Array(stb_image.memory.buffer, y, 1)[0]; 39 | const imageData = new Uint8ClampedArray(w * h * 4); 40 | // Copying the image data cause the next call to stb_image.heap_reset() above will erase it. 41 | imageData.set(new Uint8ClampedArray(stb_image.memory.buffer, pixels, w * h * 4)); 42 | return new ImageData(imageData, w); 43 | }); 44 | } 45 | function stbi_load_from_url(url) { 46 | return __awaiter(this, void 0, void 0, function* () { 47 | const response = yield fetch(url); 48 | return stbi_load_from_arraybuffer(response.arrayBuffer()); 49 | }); 50 | } 51 | //# sourceMappingURL=stb_image.js.map -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | "outDir": "./js/", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | --------------------------------------------------------------------------------