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

duolingo

v1.2.4

Published

A tiny package that makes using (unofficial) Duolingo API easier.

Downloads

30

Readme

Duolingo API

1. Description

This npm package is quite simple and rather not perfect. My main goal in creating this package was to learn how to create my own npm packages and how to add them to the official npm repository. Anyway, I believe that it might be useful for someone. 🙃

2. Installation.

You can add this package to your project by running the command below:

npm install duolingo

3. Usage example.

You can use getField method to get the value of the specific field from the response. Below you can find the available fields (as of 10.02.2023):

const mainFields = [
    'joinedClassroomIds',
    'streak',
    'motivation',
    'acquisitionSurveyReason',
    'shouldForceConnectPhoneNumber',
    'picture',
    'learningLanguage',
    'hasFacebookId',
    'shakeToReportEnabled',
    'liveOpsFeatures',
    'canUseModerationTools',
    'id',
    'betaStatus',
    'hasGoogleId',
    'privacySettings',
    'fromLanguage',
    'hasRecentActivity15',
    '_achievements',
    'observedClassroomIds',
    'username',
    'bio',
    'profileCountry',
    'globalAmbassadorStatus',
    'currentCourseId',
    'hasPhoneNumber',
    'creationDate',
    'achievements',
    'hasPlus',
    'name',
    'roles',
    'classroomLeaderboardsEnabled',
    'emailVerified',
    'courses',
    'totalXp'
];

You can use getCourseField method to get the value of the specific field for a specific course. Below you can find the available fields (as of 12.02.2023):

const coursesFields = [
    'preload',
    'placementTestAvailable',
    'authorId',
    'title',
    'learningLanguage',
    'xp',
    'healthEnabled',
    'fromLanguage',
    'crowns',
    'id'
]

You can use getLanguageDetail method to get some details related to the language that you are currently learning. For example if your learning language is english, method getField('learningLanguage') will return en value. Then you can pass this value to getLanguageDetail method and get the full name of the language or its Emoji flag.

Below you can find some usage examples.

const Duolingo = require('duolingo');

(async() => {
    // You have to pass your Duolingo user name to the constructor and use async method init() to prepare the data.
    const duo = new Duolingo('adrian_kurek');
    await duo.init();

    const streak = duo.getField('streak');
    console.log(streak); // Output: 272

    const totalXp = duo.getField('totalXp');
    console.log(totalXp); // Output: 114189

    const learningLanguage = duo.getField('learningLanguage');
    console.log(learningLanguage); // Output: de

    const learningLanguageFullName = duo.getLanguageDetail(learningLanguage, 'fullName');
    console.log(learningLanguageFullName); // Output: German

    const learningLanguageEmojiFlag = duo.getLanguageDetail(learningLanguage, 'emojiFlag');
    console.log(learningLanguageEmojiFlag); // Output: 🇩🇪

    // Get total crowns from all of the courses.
    const totalCrowns = duo.getTotalCrowns();
    console.log(totalCrowns); // Output: 696

    const learningLanguageXp = duo.getCourseField(learningLanguage, 'xp');
    console.log(learningLanguageXp); // Output: 55185

    const learningLanguageCrowns = duo.getCourseField(learningLanguage, 'crowns');
    console.log(learningLanguageCrowns); // Output: 180

    const spanishLanguageXp = duo.getCourseField('es', 'xp');
    console.log(spanishLanguageXp); // Output: 8344
})();

4. Contribution.

At the moment getLanguageDetail method supports only 8 languages.

New languages can be simply added to the languages constant array in ./src/constants.js file.

const languages = {
    'pl': {
        fullName: 'Polish',
        emojiFlag: '🇵🇱'
    },
    'en': {
        fullName: 'English',
        emojiFlag: '🇬🇧'
    },
    'de': {
        fullName: 'German',
        emojiFlag: '🇩🇪'
    },
    'es': {
        fullName: 'Spanish',
        emojiFlag: '🇪🇸'
    },
    'fr': {
        fullName: 'French',
        emojiFlag: '🇫🇷'
    },
    'it': {
        fullName: 'Italian',
        emojiFlag: '🇮🇹'
    },
    'fi': {
        fullName: 'Finnish',
        emojiFlag: '🇫🇮'
    },
    'sv': {
        fullName: 'Swedish',
        emojiFlag: '🇸🇪'
    }
};

5. Duolingo Statistics Card

I used this npm package to create Duolingo Statistics Card that displays some statistics for a specific user. The data is always "fresh" as the package is using the API to retrieve it, but to be honest I do not know how many times a single IP address can hit this API, because it is not really "official". Therefore I cannot guarantee that the application which allows to render those cards will be working without any problems.

Anyway, the cards can be displayed on a webpage, in the GitHub special repository or any other markdown file (e.g. README.md). The example below is showing how the URL should look like:

https://artysta-cloud.vercel.app/api/duolingo/statistics?user=your_user_name&renderTitle=true&fields=field_1,field_2,field_3,field_4,field_5,field_6

The user query parameter is required. The fields parameter is also required. You have to provide at least 1 field in the query. At the moment only 6 fields are supported: streak, totalXp, totalCrowns, learningLanguage, username, totalCourses. Fields in the URL query should be separated by comma. The renderTitle parameter is optional (but its default value is true). If the renderTitle is set to false, the card title will not be displayed. You can also use the optional lightTheme parameter to define, if the card should be displayed in light or dark mode - the default value of this parameter is false.

For example, below you can find a valid URL for my Duolingo user:

https://artysta-cloud.vercel.app/api/duolingo/statistics?user=adrian_kurek&fields=streak,totalXp,totalCrowns,learningLanguage

If it comes to a GitHub special repository or any other markdown file you can just use the markdown example below:

[![artysta's GitHub Statistics](https://artysta-cloud.vercel.app/api/duolingo/statistics?user=your_user_name&fields=field_1,field_2,field_3,field_4,field_5,field_6)](https://github.com/artysta/artysta-cloud)

Here are some examples how the cards can look like (I have also included non valid URLs, so some of the cards are displaying error messages):

All available fields (dark theme):

artysta's GitHub Statistics

All available fields (light theme):

artysta's GitHub Statistics

All available fields (but different fields order - the order in which the fields are displayed depends on the order in which they are given in the query):

artysta's GitHub Statistics

4 fields + disabled card title:

artysta's GitHub Statistics

Only 1 field:

artysta's GitHub Statistics

The user parameter missing:

artysta's GitHub Statistics

The fields parameter missing:

artysta's GitHub Statistics

Not supported field (or just a typo in its name):

artysta's GitHub Statistics