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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@chain1/referral-system

v1.0.2

Published

Referral system with tree structure and ReferralSystem class

Downloads

205

Readme

@chain1/referral-system

Referral system with tree structure and level management for React Native applications.

Installation

npm install @chain1/referral-system

Features

  • ReferralSystem Class - Main class for referral operations
  • Level Management - Calculate levels based on member count (0-10)
  • Tree Structure - Manage hierarchical referral trees
  • Utility Functions - Helper functions for level colors, names, and calculations
  • TypeScript Support - Full TypeScript definitions included

Usage

ReferralSystem Class

The ReferralSystem class provides a static interface for referral operations:

import { ReferralSystem } from '@chain1/referral-system';

// Get referral data (placeholder - implement in your app)
const data = await ReferralSystem.getReferralData(userId);

// Calculate level from member count
const level = ReferralSystem.calculateLevel(150); // Returns 3 (Platinum)

// Get level color
const color = ReferralSystem.getLevelColor(3); // Returns '#FFB74D'

// Get level name
const name = ReferralSystem.getLevelName(3); // Returns 'Platinum'

Utility Functions

import {
  calculateLevel,
  getLevelColor,
  getLevelName,
  getMemberCountRequirement,
  calculateProgress,
  flattenTree,
  searchMembers,
  formatNumber,
  LEVEL_CONFIGS
} from '@chain1/referral-system';

// Calculate level from member count
const level = calculateLevel(150); // 3

// Get level requirements
const minMembers = getMemberCountRequirement(3); // 100

// Calculate progress to next level
const progress = calculateProgress(150, 3); // 25%

// Format numbers
const formatted = formatNumber(1234567); // "1,234,567"

// Flatten tree structure for rendering
const flatData = flattenTree(members, 0, expandedIds);

// Search members
const results = searchMembers(members, 'john');

Level Configuration

The system supports 11 levels (0-10):

| Level | Name | Min Members | Color | |-------|------|-------------|-------| | 0 | Bronze | 0 | #9E9E9E | | 1 | Silver | 10 | #8D6E63 | | 2 | Gold | 30 | #90A4AE | | 3 | Platinum | 100 | #FFB74D | | 4 | Diamond I | 300 | #FF8A65 | | 5 | Diamond II | 1,000 | #E57373 | | 6 | Diamond III | 3,000 | #F06292 | | 7 | Master I | 5,000 | #BA68C8 | | 8 | Master II | 10,000 | #9575CD | | 9 | Grand Master | 50,000 | #7986CB | | 10 | Legend | 100,000 | #64B5F6 |

TypeScript

Full TypeScript support with exported types:

import { ReferralMember, ReferralStats, LevelConfig } from '@chain1/referral-system';

const member: ReferralMember = {
  mb_id: 'user123',
  mb_name: 'John Doe',
  level: 3,
  totalMemberCount: 150,
  directMemberCount: 20,
  children: []
};

Important Note

⚠️ ReferralSystem.getReferralData() is a placeholder method. You should implement the actual data fetching logic in your application using your preferred backend service (e.g., ReferralService, Supabase, etc.).

Example implementation:

// In your application
import { ReferralSystem } from '@chain1/referral-system';
import ReferralService from './utils/ReferralService';

// Override or use your own service
const referralService = new ReferralService();

// In your component
const data = await referralService.getReferralData(userId);
// OR
const data = await ReferralSystem.getReferralData(userId); // Will show a warning

License

MIT

Author

Stochain

Repository

https://github.com/stochain/packages