npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sleeper-wrapper

v1.0.2

Published

Sleeper API Client

Downloads

1

Readme

Sleeper Wrapper

Sleeper Wrapper is an NPM package that offers a seamless integration with the Sleeper Fantasy Football API. This package encompasses all available endpoints related to drafts, players, transactions, user information, NFL states, and more. Whether you're building a fantasy football dashboard, a statistical analysis tool, or a custom league management system, Sleeper Wrapper simplifies your interaction with the Sleeper platform and helps you turn ideas into reality with ease.

Table of Contents

Installation

npm install sleeper-wrapper

Usage

User Information

| Function | Description | Example Usage | |-------------------------------|----------------------------------------------------------|----------------------------------------------------| | fetchUser | Retrieves user information. | const user = await fetchUser('usernameOrId'); | | fetchAvatarFullSizeUrl | Gets the full-size avatar. | const url = fetchAvatarFullSizeUrl('avatarId'); | | fetchAvatarThumbnailUrl | Gets the thumbnail of the avatar. | const url = fetchAvatarThumbnailUrl('avatarId'); | | getLeaguesForUser | Retrieves all leagues for a user. | const leagues = await getLeaguesForUser('userId', 'sport', 'season'); | | getSpecificLeague | Retrieves specific league information. | const league = await getSpecificLeague('leagueId'); | | getRostersInLeague | Retrieves all rosters in a league. | const rosters = await getRostersInLeague('leagueId'); | | getUsersInLeague | Retrieves all users in a league. | const users = await getUsersInLeague('leagueId'); | | getMatchupsInLeague | Retrieves all matchups in a league for a given week. | const matchups = await getMatchupsInLeague('leagueId', 'week'); | | getPlayoffBracketWinners | Retrieves the winners' playoff bracket. | const winners = await getPlayoffBracketWinners('leagueId'); | | getPlayoffBracketLosers | Retrieves the losers' playoff bracket. | const losers = await getPlayoffBracketLosers('leagueId'); |

Drafts

| Function | Description | Example Usage | |-------------------------------|----------------------------------------------------------|--------------------------------------------------------| | getAllDraftsForUser | Retrieves all drafts by a user. | const drafts = await getAllDraftsForUser('userId'); | | getAllDraftsForLeague | Retrieves all drafts for a league. | const drafts = await getAllDraftsForLeague('leagueId'); | | getSpecificDraft | Retrieves a specific draft. | const draft = await getSpecificDraft('draftId'); | | getAllPicksInDraft | Retrieves all picks in a draft. | const picks = await getAllPicksInDraft('draftId'); | | getTradedPicksInDraft | Retrieves all traded picks in a draft. | const tradedPicks = await getTradedPicksInDraft('draftId'); |

Players

| Function | Description | Example Usage | |-------------------------------|----------------------------------------------------------|----------------------------------------------------| | fetchAllPlayers | Fetches all players (intended to be used once per day). | const players = await fetchAllPlayers(); | | getTrendingPlayers | Gets a list of trending players based on add/drop activity.| const trendingPlayers = await getTrendingPlayers('sport', 'type'); |

Transactions

| Function | Description | Example Usage | |-------------------------------|----------------------------------------------------------|--------------------------------------------------------| | getTransactions | Retrieves all free agent transactions, waivers, and trades. | const transactions = await getTransactions('leagueId', 'round'); | | getTradedPicks | Retrieves all traded picks in a league, including future picks. | const tradedPicks = await getTradedPicks('leagueId'); |

NFL State

| Function | Description | Example Usage | |-------------------------------|----------------------------------------------------------|-------------------------------------| | getNFLState | Returns information about the current state for any sport. | const state = await getNFLState(); |

Example

import { useState, useEffect } from 'react';
import { fetchUser, fetchAvatarFullSizeUrl, fetchAvatarThumbnailUrl, getLeaguesForUser } from 'sleeper-wrapper';
import { UserResponse } from 'sleeper-wrapper/dist/endpoints/user/fetchUser';

interface UserData {
  username: string;
  user_id: string;
  displayName: string;
  avatar: string;
}

interface LeagueData {
  league_id: string;
  name: string;
}

const UserProfile = () => {
  const [user, setUser] = useState<UserData | null>(null);
  const [leagues, setLeagues] = useState<LeagueData[]>([]);
  const username = 'INPUT_YOUR_USERNAME_HERE';

  useEffect(() => {
    const fetchUserData = async () => {
      try {
        const userData: UserResponse = await fetchUser(username);
        setUser(userData);
      } catch (error) {
        console.error('Error fetching user:', error);
      }
    };

    fetchUserData();
  }, [username]);

  useEffect(() => {
    const fetchUserLeagues = async () => {
      try {
        if (user) {
          const fetchedLeagues = await getLeaguesForUser(user.user_id, 'nfl', '2023');
          setLeagues(fetchedLeagues);
        }
      } catch (error) {
        console.error('Error fetching leagues:', error);
      }
    };

    if (user) {
      fetchUserLeagues();
    }
  }, [user]);

  return (
    <div>
      {user ? (
        <div>
          <p>Display Name: {user.displayName}</p>
          <p>Username: {user.username}</p>
          <p>User ID: {user.user_id}</p>
          <img src={fetchAvatarFullSizeUrl(user.avatar)} alt="Avatar" />
          <img src={fetchAvatarThumbnailUrl(user.avatar)} alt="Avatar" />
          <p>Leagues:</p>
          {leagues.map((league) => (
            <p key={league.league_id}>{league.name}</p>
          ))}
        </div>
      ) : (
        <p>Loading...</p>
      )}
    </div>
  );
};

export default UserProfile;

File Directory

├── package-lock.json
├── package.json
├── README.md
├── src
│   ├── endpoints
│   │   ├── drafts
│   │   ├── nflState
│   │   ├── players
│   │   ├── transactions
│   │   └── user
│   ├── errors
│   │   └── ApiErrors.ts
│   └── index.ts
└── tsconfig.json

Errors

  • 400: Bad Request
  • 404: Not Found
  • 429: Too Many Requests
  • 500: Internal Server Error
  • 503: Service Unavailable

Contributing

Feel free to fork the repository, make changes, and submit pull requests. If you find any bugs or have suggestions, please open an issue.

License

This project is licensed under the MIT License.