Repository: sindresorhus/latest-version
Branch: main
Commit: e550aac4704d
Files: 13
Total size: 6.7 KB
Directory structure:
gitextract_ne8lyc7f/
├── .editorconfig
├── .gitattributes
├── .github/
│ ├── security.md
│ └── workflows/
│ └── main.yml
├── .gitignore
├── .npmrc
├── index.d.ts
├── index.js
├── index.test-d.ts
├── license
├── package.json
├── readme.md
└── test.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
root = 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
================================================
FILE: .gitattributes
================================================
* text=auto eol=lf
================================================
FILE: .github/security.md
================================================
# Security Policy
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
================================================
FILE: .github/workflows/main.yml
================================================
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 21
- 20
- 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
================================================
FILE: .gitignore
================================================
node_modules
yarn.lock
================================================
FILE: .npmrc
================================================
package-lock=false
================================================
FILE: index.d.ts
================================================
import type {Options as PackageJsonOptions} from 'package-json';
export {PackageNotFoundError, VersionNotFoundError} from 'package-json';
export type Options = Pick<PackageJsonOptions, 'version' | 'registryUrl' | 'omitDeprecated'>;
/**
Get the latest version of an npm package.
@example
```
import latestVersion from 'latest-version';
console.log(await latestVersion('ava'));
//=> '6.1.1'
console.log(await latestVersion('@sindresorhus/df'));
//=> '4.0.0'
// Also works with semver ranges and dist-tags
console.log(await latestVersion('npm', {version: 'latest-5'}));
//=> '5.10.0'
```
*/
export default function latestVersion(packageName: string, options?: Options): Promise<string>;
================================================
FILE: index.js
================================================
import packageJson from 'package-json';
export {PackageNotFoundError, VersionNotFoundError} from 'package-json';
export default async function latestVersion(packageName, options) {
const {version} = await packageJson(packageName.toLowerCase(), options);
return version;
}
================================================
FILE: index.test-d.ts
================================================
import {expectType} from 'tsd';
import latestVersion from './index.js';
expectType<Promise<string>>(latestVersion('ava'));
expectType<Promise<string>>(latestVersion('npm', {version: 'latest-5'}));
expectType<Promise<string>>(latestVersion('npm', {registryUrl: 'https://registry.yarnpkg.com'}));
expectType<Promise<string>>(latestVersion('npm', {omitDeprecated: false}));
================================================
FILE: license
================================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
================================================
FILE: package.json
================================================
{
"name": "latest-version",
"version": "9.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": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"latest",
"version",
"npm",
"pkg",
"package",
"package.json",
"current",
"module"
],
"dependencies": {
"package-json": "^10.0.0"
},
"devDependencies": {
"ava": "^6.1.1",
"semver": "^7.6.0",
"semver-regex": "^4.0.5",
"tsd": "^0.30.7",
"xo": "^0.57.0"
}
}
================================================
FILE: readme.md
================================================
# 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'));
//=> '6.1.1'
console.log(await latestVersion('@sindresorhus/df'));
//=> '4.0.0'
// Also works with semver ranges and dist-tags
console.log(await latestVersion('npm', {version: 'latest-5'}));
//=> '5.10.0'
```
This package exposes the [`version`](https://github.com/sindresorhus/package-json#version), [`registryUrl`](https://github.com/sindresorhus/package-json#registryurl), and [`omitDeprecated`](https://github.com/sindresorhus/package-json#omitdeprecated) options from [`package-json`](https://github.com/sindresorhus/package-json#options), as well as the [`PackageNotFoundError`](https://github.com/sindresorhus/package-json#packagenotfounderror) and [`VersionNotFoundError`](https://github.com/sindresorhus/package-json#versionnotfounderror) errors.
## 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
================================================
FILE: test.js
================================================
import test from 'ava';
import semver from 'semver';
import semverRegex from 'semver-regex';
import latestVersion, {PackageNotFoundError, VersionNotFoundError} 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());
});
test('registry url', async t => {
t.regex(await latestVersion('npm', {registryUrl: 'https://registry.yarnpkg.com/'}), semverRegex());
});
test('include deprecated', async t => {
t.regex(await latestVersion('querystring', {version: '0.2', omitDeprecated: false}), semverRegex());
});
test('throws if not found', async t => {
await t.throwsAsync(latestVersion('nnnope'), {instanceOf: PackageNotFoundError});
await t.throwsAsync(latestVersion('npm', {version: '0.0.0'}), {instanceOf: VersionNotFoundError});
});
gitextract_ne8lyc7f/ ├── .editorconfig ├── .gitattributes ├── .github/ │ ├── security.md │ └── workflows/ │ └── main.yml ├── .gitignore ├── .npmrc ├── index.d.ts ├── index.js ├── index.test-d.ts ├── license ├── package.json ├── readme.md └── test.js
SYMBOL INDEX (2 symbols across 2 files)
FILE: index.d.ts
type Options (line 5) | type Options = Pick<PackageJsonOptions, 'version' | 'registryUrl' | 'omi...
FILE: index.js
function latestVersion (line 5) | async function latestVersion(packageName, options) {
Condensed preview — 13 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (8K chars).
[
{
"path": ".editorconfig",
"chars": 175,
"preview": "root = true\n\n[*]\nindent_style = tab\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newlin"
},
{
"path": ".gitattributes",
"chars": 19,
"preview": "* text=auto eol=lf\n"
},
{
"path": ".github/security.md",
"chars": 179,
"preview": "# Security Policy\n\nTo report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/s"
},
{
"path": ".github/workflows/main.yml",
"chars": 436,
"preview": "name: CI\non:\n - push\n - pull_request\njobs:\n test:\n name: Node.js ${{ matrix.node-version }}\n runs-on: ubuntu-la"
},
{
"path": ".gitignore",
"chars": 23,
"preview": "node_modules\nyarn.lock\n"
},
{
"path": ".npmrc",
"chars": 19,
"preview": "package-lock=false\n"
},
{
"path": "index.d.ts",
"chars": 691,
"preview": "import type {Options as PackageJsonOptions} from 'package-json';\n\nexport {PackageNotFoundError, VersionNotFoundError} fr"
},
{
"path": "index.js",
"chars": 276,
"preview": "import packageJson from 'package-json';\n\nexport {PackageNotFoundError, VersionNotFoundError} from 'package-json';\n\nexpor"
},
{
"path": "index.test-d.ts",
"chars": 372,
"preview": "import {expectType} from 'tsd';\nimport latestVersion from './index.js';\n\nexpectType<Promise<string>>(latestVersion('ava'"
},
{
"path": "license",
"chars": 1117,
"preview": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby grant"
},
{
"path": "package.json",
"chars": 890,
"preview": "{\n\t\"name\": \"latest-version\",\n\t\"version\": \"9.0.0\",\n\t\"description\": \"Get the latest version of an npm package\",\n\t\"license\""
},
{
"path": "readme.md",
"chars": 1469,
"preview": "# latest-version\n\n> Get the latest version of an npm package\n\nFetches the version directly from the registry instead of "
},
{
"path": "test.js",
"chars": 1184,
"preview": "import test from 'ava';\nimport semver from 'semver';\nimport semverRegex from 'semver-regex';\nimport latestVersion, {Pack"
}
]
About this extraction
This page contains the full source code of the sindresorhus/latest-version GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 13 files (6.7 KB), approximately 2.1k tokens, and a symbol index with 2 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.