pax_global_header00006660000000000000000000000064142550612010014506gustar00rootroot0000000000000052 comment=b79a0ceb9997f8ceb5078626a64001b7b88799fa latest-version-7.0.0/000077500000000000000000000000001425506120100144715ustar00rootroot00000000000000latest-version-7.0.0/.editorconfig000066400000000000000000000002571425506120100171520ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 latest-version-7.0.0/.gitattributes000066400000000000000000000000231425506120100173570ustar00rootroot00000000000000* text=auto eol=lf latest-version-7.0.0/.github/000077500000000000000000000000001425506120100160315ustar00rootroot00000000000000latest-version-7.0.0/.github/funding.yml000066400000000000000000000001701425506120100202040ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus custom: https://sindresorhus.com/donate tidelift: npm/latest-version latest-version-7.0.0/.github/security.md000066400000000000000000000002631425506120100202230ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. latest-version-7.0.0/.github/workflows/000077500000000000000000000000001425506120100200665ustar00rootroot00000000000000latest-version-7.0.0/.github/workflows/main.yml000066400000000000000000000006641425506120100215430ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 18 - 16 - 14 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test latest-version-7.0.0/.gitignore000066400000000000000000000000271425506120100164600ustar00rootroot00000000000000node_modules yarn.lock latest-version-7.0.0/.npmrc000066400000000000000000000000231425506120100156040ustar00rootroot00000000000000package-lock=false latest-version-7.0.0/index.d.ts000066400000000000000000000011171425506120100163720ustar00rootroot00000000000000export interface Options { /** A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag). */ readonly version?: string; } /** Get the latest version of an npm package. @example ``` import latestVersion from 'latest-version'; console.log(await latestVersion('ava')); //=> '0.18.0' console.log(await latestVersion('@sindresorhus/df')); //=> '1.0.1' // Also works with semver ranges and dist-tags console.log(await latestVersion('npm', {version: 'latest-5'})); //=> '5.5.1' ``` */ export default function latestVersion(packageName: string, options?: Options): Promise; latest-version-7.0.0/index.js000066400000000000000000000003121425506120100161320ustar00rootroot00000000000000import packageJson from 'package-json'; export default async function latestVersion(packageName, options) { const {version} = await packageJson(packageName.toLowerCase(), options); return version; } latest-version-7.0.0/index.test-d.ts000066400000000000000000000003061425506120100173460ustar00rootroot00000000000000import {expectType} from 'tsd'; import latestVersion from './index.js'; expectType>(latestVersion('ava')); expectType>(latestVersion('npm', {version: 'latest-5'})); latest-version-7.0.0/license000066400000000000000000000021351425506120100160370ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. latest-version-7.0.0/package.json000066400000000000000000000015221425506120100167570ustar00rootroot00000000000000{ "name": "latest-version", "version": "7.0.0", "description": "Get the latest version of an npm package", "license": "MIT", "repository": "sindresorhus/latest-version", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": ">=14.16" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "latest", "version", "npm", "pkg", "package", "package.json", "current", "module" ], "dependencies": { "package-json": "^8.1.0" }, "devDependencies": { "ava": "^4.3.0", "semver": "^7.3.7", "semver-regex": "^4.0.5", "tsd": "^0.21.0", "typescript": "^4.7.4", "xo": "^0.50.0" } } latest-version-7.0.0/readme.md000066400000000000000000000025271425506120100162560ustar00rootroot00000000000000# latest-version > Get the latest version of an npm package Fetches the version directly from the registry instead of depending on the massive [npm](https://github.com/npm/npm/blob/8b5e7b6ae5b4cd2d7d62eaf93b1428638b387072/package.json#L37-L85) module like the [latest](https://github.com/bahamas10/node-latest) module does. ## Install ```sh npm install latest-version ``` ## Usage ```js import latestVersion from 'latest-version'; console.log(await latestVersion('ava')); //=> '0.18.0' console.log(await latestVersion('@sindresorhus/df')); //=> '1.0.1' // Also works with semver ranges and dist-tags console.log(await latestVersion('npm', {version: 'latest-5'})); //=> '5.5.1' ``` ## Related - [latest-version-cli](https://github.com/sindresorhus/latest-version-cli) - CLI for this module - [package-json](https://github.com/sindresorhus/package-json) - Get the package.json of a package from the npm registry ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
latest-version-7.0.0/test.js000066400000000000000000000011561425506120100160110ustar00rootroot00000000000000import test from 'ava'; import semver from 'semver'; import semverRegex from 'semver-regex'; import latestVersion from './index.js'; test('latest version', async t => { t.regex(await latestVersion('ava'), semverRegex()); }); test('latest version with version', async t => { t.true(semver.satisfies(await latestVersion('package-json', {version: '0'}), '0.x')); }); test('latest version with dist-tag', async t => { t.true(semver.satisfies(await latestVersion('npm', {version: 'latest-5'}), '5.x')); }); test('latest version scoped', async t => { t.regex(await latestVersion('@sindresorhus/df'), semverRegex()); });