Npm Badge
About 678 wordsAbout 2 min
2025-10-08
Overview
The Npm Badge component is used to display npm package information and provide relevant links.
The badges are powered by https://shields.io.
Usage
The component does not need to be registered; the theme will automatically import the NpmBadge and NpmBadgeGroup components on demand.
Use them directly in markdown files:
<!-- use them in markdown -->
<NpmBadge name="vuepress-theme-plume" type="dm" />
<!-- Display multiple npm badges side by side -->
<NpmBadgeGroup name="vuepress-theme-plume" items="version,dm" /><NpmBadge />
Single npm badge
Props
Name:nameOptionalType:string
npm package name. If empty, it will be obtained from repo
Name:repoOptionalType:string
Package GitHub repository address in owner/repo format. Required when name is empty
Name:typeType:NpmBadgeType
Badge type
Name:themeOptionalType:NpmBadgeTheme
Default Value: 'flat'
Badge theme
Name:labelOptionalType:string
Badge label
Name:colorOptionalType:string
Default Value: '#32A9C3'
Badge color
Name:labelColorOptionalType:string
Default Value: '#1B3C4A'
Badge label color
Name:branchOptionalType:string
Default Value: 'main'
Repository branch
Name:dirOptionalType:string
Package directory in repository. Suitable for monorepo projects
Types
type NpmBadgeType
// github
= | 'source' // github source
| 'stars' // github stars
| 'forks' // github forks
| 'license' // github license
// npm
| 'version' // npm version
| 'dt' // alias d18m
| 'd18m' // npm downloads last 18 months
| 'dw' // npm downloads weekly
| 'dm' // npm downloads monthly
| 'dy' // npm downloads yearly
type NpmBadgeTheme = 'flat' | 'flat-square' | 'plastic' | 'for-the-badge' | 'social'Examples
<NpmBadge repo="pengzhanbo/vuepress-theme-plume" type="source" />-<NpmBadge repo="pengzhanbo/vuepress-theme-plume" type="stars" />-<NpmBadge repo="pengzhanbo/vuepress-theme-plume" type="forks" />-<NpmBadge repo="pengzhanbo/vuepress-theme-plume" type="license" />-<NpmBadge name="vuepress-theme-plume" type="version" />-<NpmBadge name="vuepress-theme-plume" type="dt" />-<NpmBadge name="vuepress-theme-plume" type="d18m" />-<NpmBadge name="vuepress-theme-plume" type="dy" />-<NpmBadge name="vuepress-theme-plume" type="dm" />-<NpmBadge name="vuepress-theme-plume" type="dw" />-
<NpmBadgeGroup />
Combines multiple npm badges
Props
Name:nameOptionalType:string
npm package name. If empty, it will be obtained from repo
Name:repoOptionalType:string
Package GitHub repository address in owner/repo format. Required when name is empty
Name:itemsOptionalType:string | NpmBadgeType[]
Default Value: []
List of badge types. When passing a string, separate with ',' and it will be automatically converted to NpmBadgeType[]
Name:themeOptionalType:NpmBadgeTheme
Badge theme
Name:colorOptionalType:string
Badge color
Name:labelColorOptionalType:string
Badge label color
Name:branchOptionalType:string
Repository branch
Name:dirOptionalType:string
Package directory in repository. Suitable for monorepo projects
Slots
<NpmBadgeGroup /> supports passing multiple <NpmBadge /> components.
The Props declared in <NpmBadgeGroup /> will be injected into the <NpmBadge /> components. This approach is used to implement and simplify badge combinations.
Examples
Input:
<NpmBadgeGroup
repo="pengzhanbo/vuepress-theme-plume"
items="stars,version,dm,source"
/>Output:
Use <slot /> to flexibly define badge combinations:
Input:
<NpmBadgeGroup repo="pengzhanbo/vuepress-theme-plume">
<NpmBadge type="stars" />
<NpmBadge type="version" label="npm" />
<NpmBadge type="dm" />
<NpmBadge type="source" />
</NpmBadgeGroup>Output:
Contributors
Changelog
1d04d-feat: add builtin auto-import-components (#932)on16c2d-docs: update field containeron38505-docs: update en docs (#708)on4d236-feat(theme)!: add collections support (#704)on4f60b-style: lint fixond1496-docs: update docson0fd6c-refactor(theme): improve types and flat config (#524)one3b1c-docs: improve docsonac898-docs: update docson
