NPM Author Download Badge - Svelte Shields

Props #

- interval = 'dw'
- author
- style = 'flat'
- logo
- logoColor
- logoSize
- label
- labelColor
- color
- cacheSeconds
- link
- class: classname
- ...attributes

Types #

import type { HTMLImgAttributes } from 'svelte/elements';

export type LinkType = string[] | [string, string];
export interface BaseBadgePropsType {
  style?: 'flat' | 'flat-square' | 'for-the-badge' | 'plastic' | 'social';
  logo?: string | undefined | null;
  logoColor?: string | undefined | null;
  logoSize?: string | undefined | null;
  label?: string | undefined | null;
  labelColor?: string | undefined | null;
  color?: string | undefined | null;
  cacheSeconds?: string | undefined | null;
  link?: LinkType;
  class?: string | undefined | null;
}
interface ExtendedStyle extends BaseBadgePropsType, HTMLImgAttributes {
  style?: 'flat' | 'flat-square' | 'for-the-badge' | 'plastic' | 'social';
}
export interface NpmAuthorDownloadPropsType extends ExtendedStyle {
  interval?: 'dw' | 'dm' | 'dy' | 'd18m';
  author: string;
}

Examples #

Basic usage #

packageName may be the name of an unscoped package like package-name or a scoped package like @author/package-name.

tag can be next, v1, v2, beta, etc.

NPM dw Downloads - shinichiokada NPM dm Downloads - shinichiokada
<script lang="ts">
  import { NpmAuthorDownload, type NpmAuthorDownloadPropsType } from 'svelte-shields';

  const basic: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada'
  };

  const basic2: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    interval: 'dm'
  };
</script>

<div class="grid gap-4">
  <NpmAuthorDownload {...basic} />
  <NpmAuthorDownload {...basic2} />
</div>

Style #

Possible values: flat, flat-square, plastic, for-the-badge, social. If not specified, the default style for this badge is "flat".

NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada
<script lang="ts">
  import { NpmAuthorDownload, type NpmAuthorDownloadPropsType } from 'svelte-shields';

  const style1: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    style: 'flat'
  };
  const style2: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    style: 'flat-square'
  };
  const style3: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    style: 'for-the-badge'
  };
  const style4: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    style: 'plastic'
  };
  const style5: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    style: 'social'
  };
</script>

<div class="grid gap-4">
  <NpmAuthorDownload {...style1} />
  <NpmAuthorDownload {...style2} />
  <NpmAuthorDownload {...style3} />
  <NpmAuthorDownload {...style4} />
  <NpmAuthorDownload {...style5} />
</div>

Color #

Background color of the right part (hex, rgb, rgba, hsl, hsla and css named colors supported).

NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada NPM dw Downloads - shinichiokada
<script lang="ts">
  import { NpmAuthorDownload, type NpmAuthorDownloadPropsType } from 'svelte-shields';

  const color1: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    color: 'indigo'
  };
  const color2: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    color: '4B0082'
  };
  const color3: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    color: 'rgb(75, 0, 130)'
  };
  const color4: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    color: 'rgba(75, 0, 130, 1)'
  };

  const color5: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    color: 'hsl(275, 100%, 25%)'
  };

  const color6: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    color: 'hsla(275, 100%, 25%, 1)'
  };
</script>

<div class="grid gap-4">
  <NpmAuthorDownload {...color1} />
  <NpmAuthorDownload {...color2} />
  <NpmAuthorDownload {...color3} />
  <NpmAuthorDownload {...color4} />
  <NpmAuthorDownload {...color5} />
  <NpmAuthorDownload {...color6} />
</div>

Logo & Label #

NPM dw Downloads - shinichiokada
<script lang="ts">
  import { NpmAuthorDownload, type NpmAuthorDownloadPropsType } from 'svelte-shields';

  const logo_label: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    logo: 'svelte',
    label: 'Shinichi Okada'
  };
</script>

<NpmAuthorDownload {...logo_label} />

Link #

Specify what clicking on the left/right of a badge should do.

<script lang="ts">
  import { NpmAuthorDownload, type NpmAuthorDownloadPropsType } from 'svelte-shields';

  const link: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    logo: 'svelte',
    link: ['https://github.com/shinokada', 'https://codewithshin.com']
  };
</script>

<NpmAuthorDownload {...link} />

Other #

cacheSeconds is HTTP cache lifetime (rules are applied to infer a default value on a per-badge basis, any values specified below the default will be ignored).

NPM dw Downloads - shinichiokada
<script lang="ts">
  import { NpmAuthorDownload, type NpmAuthorDownloadPropsType } from 'svelte-shields';

  const other: NpmAuthorDownloadPropsType = {
    author: 'shinichiokada',
    logo: 'svelte',
    cacheSeconds: '86400'
  };
</script>

<NpmAuthorDownload {...other} />