|
| 1 | +# TypeScript definitions for njs |
| 2 | + |
| 3 | +This package contains type definitions for [njs](https://github.com/nginx/njs) – NGINX JavaScript. |
| 4 | + |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +Install **njs-types** from the [npm registry](https://www.npmjs.com/) into your project: |
| 9 | + |
| 10 | +```sh |
| 11 | +# using npm: |
| 12 | +npm install --save-dev njs-types |
| 13 | +# or using yarn: |
| 14 | +yarn add --dev njs-types |
| 15 | +``` |
| 16 | + |
| 17 | +njs-types provides three entry points with global declarations for each of njs environments: |
| 18 | + |
| 19 | +* `njs_shell.d.ts` – njs shell |
| 20 | +* `ngx_http_js_module.d.ts` – NGINX JS HTTP Module |
| 21 | +* `ngx_stream_js_module.d.ts` – NGINX JS Stream Module |
| 22 | + |
| 23 | +You can either reference them using [triple-slash directive](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) at top of your `.ts` files (adjust `path` to point into your project’s node_modules): |
| 24 | + |
| 25 | +```ts |
| 26 | +/// <reference path="./node_modules/njs-types/ngx_http_js_module.d.ts" /> |
| 27 | +``` |
| 28 | + |
| 29 | +or include them using the [files](https://www.typescriptlang.org/tsconfig#files) flag in your `tsconfig.json`, for example: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "compilerOptions": { |
| 34 | + "target": "ES5", |
| 35 | + "module": "es2015", |
| 36 | + "lib": [ |
| 37 | + "ES2015", |
| 38 | + ], |
| 39 | + "outDir": "./lib", |
| 40 | + "downlevelIteration": true, |
| 41 | + |
| 42 | + "strict": true, |
| 43 | + "noImplicitAny": true, |
| 44 | + "strictNullChecks": true, |
| 45 | + "strictFunctionTypes": true, |
| 46 | + "strictBindCallApply": true, |
| 47 | + "strictPropertyInitialization": true, |
| 48 | + "noImplicitThis": true, |
| 49 | + "alwaysStrict": true, |
| 50 | + |
| 51 | + "moduleResolution": "node", |
| 52 | + |
| 53 | + "skipLibCheck": true, |
| 54 | + "forceConsistentCasingInFileNames": true, |
| 55 | + }, |
| 56 | + "include": [ |
| 57 | + "./src", |
| 58 | + ], |
| 59 | + "files": [ |
| 60 | + "./node_modules/njs-types/ngx_http_js_module.d.ts", |
| 61 | + ], |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | +## Versions |
| 67 | + |
| 68 | +njs-types is typically being released together with njs. |
| 69 | +Their major and minor release numbers (the first two numbers) are always aligned, but the patch version (the third number) may differ. |
| 70 | +That's because njs-types may be updated between njs releases and in such case the patch version is incremented. |
| 71 | + |
| 72 | +It's the same strategy as used in [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library). |
| 73 | +The reason is that npmjs enforces [SemVer](https://semver.org/) which doesn't allow four-part version number nor provide post-release suffixes. |
| 74 | + |
| 75 | +You can find from which commit the package was built in file `COMMITHASH` inside the published package. |
| 76 | +It contains global revision id in the upstream repository https://hg.nginx.org/njs/ (Mercurial). |
0 commit comments