1.0.1 • Published 4 years ago

ranked-profile v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Overview

This project acts as a way to integrate a personalized experience for your users who support you through web monetization by tying an experience/levelling mechanic around payment dispatches. Experience is determined by the payment amount (controlled with a multiplier), with callbacks on experience update and level up functions to integrate into your own application.

Requirements

Check out the official Web Monetization Quick Start Guide to learn how to set up a wallet for receiving payments. This library assumes you have a meta tag with both the name="moneization" and content={your payment pointer} properties. Example:

<meta
  name="monetization"
  content="$wallet.example.com/alice"
>

Installation

npm install ranked-profile --save

Example

const rp = new RankedProfile()

rp.init({
    level: 1,
    xp: 0,
    levelThresholds: [10, 20, 50],
    multiplier: 1000,
    onXPUpdate: (xp) => console.log(xp),
    onLevelUp: (level) => console.log(level),
});

Options

NameTypeRequiredDescription
xpnumberyesThe current experience for a user.
levelnumberyesThe current level for a user.
levelThresholdsarrayyesThe experience thresholds needed for each level.
multipliernumbernoThe multiplier for controlling the payment/experience ratio.
onXPUpdatefunctionnoThe callback function when experience is updated.
onLevelUpfunctionnoThe callback function when level is updated.

API

NameReturnsDescription
initvoidInitialize a new RankedProfile instance.
getCurrentXPnumberReturns the user's current experience.
getExperienceToNextLevelnumberReturns the amount of experience needed to reach the next level (returns 0 at max level).
getPercentageTowardsLevelnumberReturns the current percentage towards the next level (returns 100 at max level).
getCurrentLevelnumberReturns the user's current level.
startMonetizationvoidStarts the monetization event (called automatically with init).
stopMonetizationvoidStops the monetization event (called automatically with cleanup).
isActivebooleanReturns whether a RankedProfile instance has been initialized.
cleanupvoidCleanup function to remove event listeners and clean up callbacks.

Contributing

If you've noticed a bug or have a feature you'd like to suggest, please open a GitHub Issue. If you would like to contribute to the project, feel free to fork this repo, create a new branch & open a pull request.

Licence

MIT © brewsterbhg

1.0.1

4 years ago

1.0.0

4 years ago