diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 3f4dfb1..dc49dd4 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -45,6 +45,9 @@ jobs: - name: Check format run: npm run format-check + - name: Check types + run: npm run types-check + - name: Coveralls uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..cdd8db8 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,8 @@ +/** + * Takes a node version string and returns an object with the `major`/`minor`/`patch` and `pre`/`build` keys. If the version doesn't contain any pre-release or build information, the properties will be returned as empty string. + * + * @param {string} version node version string. + * @returns {object |string} object or empty string otherwise. + */ +export default function parseNodeVersion(version: string): object | string; +//# sourceMappingURL=index.d.ts.map diff --git a/index.d.ts.map b/index.d.ts.map new file mode 100644 index 0000000..1b3afc4 --- /dev/null +++ b/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,kDAHW,MAAM,GACJ,MAAM,GAAE,MAAM,CAiB1B"} \ No newline at end of file diff --git a/index.js b/index.js index f91cfb1..c0dd723 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,9 @@ +/** + * Takes a node version string and returns an object with the `major`/`minor`/`patch` and `pre`/`build` keys. If the version doesn't contain any pre-release or build information, the properties will be returned as empty string. + * + * @param {string} version node version string. + * @returns {object | string} node version object or empty string otherwise. + */ export default function parseNodeVersion(version) { const match = version.match( /^v(\d{1,2})\.(\d{1,2})\.(\d{1,2})(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$/, diff --git a/package-lock.json b/package-lock.json index 09f79b6..43bf71b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,8 @@ "devDependencies": { "eslint": "10.11.0", "eslint-config-gulp": "7.0.0", - "prettier": "3.9.6" + "prettier": "3.9.6", + "typescript": "6.0.3" }, "engines": { "node": ">= 22.15.0" @@ -994,6 +995,20 @@ "node": ">= 0.8.0" } }, + "node_modules/typescript": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index c7ec1a2..0d4b49c 100644 --- a/package.json +++ b/package.json @@ -17,21 +17,27 @@ }, "type": "module", "main": "./index.js", + "types": "./index.d.ts", "exports": "./index.js", "files": [ "LICENSE", + "index.d.ts", + "index.d.ts.map", "index.js" ], "scripts": { "format-check": "prettier . --check", "format-write": "prettier . --write", "lint": "eslint .", - "test": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=test/lcov.info \"test/*.js\"" + "test": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=test/lcov.info \"test/*.js\"", + "types-check": "tsc index.js --checkJs --noEmit", + "types-write": "tsc index.js --checkJs --declaration --declarationMap --emitDeclarationOnly" }, "devDependencies": { "eslint": "10.11.0", "eslint-config-gulp": "7.0.0", - "prettier": "3.9.6" + "prettier": "3.9.6", + "typescript": "6.0.3" }, "keywords": [ "process.version",