@offline-protocol/core
v0.1.4
Published
Core types and funtions used in Offline Protocol apps.
Readme
@offline-protocol/core
A lightweight utility package for handling profile pricing, expiry formatting, and rewards logic within the Offline Protocol ecosystem.
📦 Installation
npm install @offline-protocol/core
# or
yarn add @offline-protocol/core🔧 Utilities & Functions
📅 Profile Dates & Duration
getProfileActiveYears(expiry, createdAt)- Calculates the number of active years between a profile's creation and expiry.
- Returns a number representing how long the profile is active.
getFormatedExpiryDate(date)- Formats a JavaScript
Dateobject into a human-readable string like"16 Jun 2025"(British format).
- Formats a JavaScript
💰 Pricing & Cost Calculation
getBasePrice(username)- Determines the base price of a username based on its length:
getOneYearCost()- Returns the fixed cost of maintaining a profile for one year.
getTotalPrice(username, years)- Computes the total price for a username over a given number of years.
💡 Username Suggestions
generateUsernameSuggestions(baseName)- Generates a list of quirky and creative username variations based on a given string.
- Applies fun transformations like replacing characters, prefixing, etc.
🎯 Reward System
getPointsForBoughtProfile(username, years)- Calculates the reward points earned for purchasing a profile.
- Points depend on the username length and number of years.
getPointsForReferredProfile(username, years)- Calculates the referral points.
🔢 Utilities
getNumberWithSeparators(number)- Adds thousands separators to large numbers for better readability.
- Example:
1000000→"1,000,000"
🛠 Use Case Example
import {
getTotalPrice,
getFormatedExpiryDate,
generateUsernameSuggestions,
getPointsForBoughtProfile,
} from "@offline-protocol/core";
const price = getTotalPrice("adi", 3); // returns 11.5
const expiryDate = getFormatedExpiryDate(new Date()); // returns "16 Jun 2025"
const suggestions = generateUsernameSuggestions("adi"); // returns ["xdi", "adi", "adee", ...]
const points = getPointsForBoughtProfile("adi", 3); // returns 1150📄 License
MIT © Offline Protocol Team
