Giter Club home page Giter Club logo

node-leaderboard's Introduction

Leaderboard

Leaderboards backed by Redis in Node.js. Initially written for the Minefield HTML5 game. Inspired by Agoragames' Leaderboard.

Build Status

Installation

$ npm install leaderboard

API

#Constructor

new Leaderboard('name', [options], [redisOptions|redisClient])

Creates a new leaderboard or attaches to an existing leaderboard.

###Options

  • pageSize - default: 0

    Page size to be used when paging through the leaderboard.

  • reverse - default: false

    If true various methods will return results in lowest-to-highest order.

##Methods

  • add(member, score, [λ])

    Ranks a member in the leaderboard.

    board.add('borbit', 42, function(err) {
      // no arguments except err
    });
    
  • incr(member, score, [λ])

    Increments the score of a member by provided value and ranks it in the leaderboard. Decrements if negative.

    board.incr('borbit', 42, function(err) {
      // no arguments except err
    });
    
  • rank(member, λ)

    Retrieves the rank for a member in the leaderboard.

    board.rank('borbit', function(err, rank) {
      // rank - current position, -1 if a member doesn't
      // fall within the leaderboard
    });
    
  • score(member, λ)

    Retrieves the score for a member in the leaderboard.

    board.score('borbit', function(err, score) {
      // score - current score, -1 if a member doesn't
      // fall within the leaderboard
    });
    
  • list([page], λ)

    Retrieves a page of leaders from the leaderboard.

    board.list(function(err, list) {
      // list - list of leaders are ordered from
      // the highest to the lowest score
      // [
      //   {member: 'member1', score: 30},
      //   {member: 'member2', score: 20},
      //   {member: 'member3', score: 10}
      // ]
    });
    
  • at(rank, λ)

    Retrieves a member on the specified rank.

    board.at(42, function(err, member) {
      // member - member at the specified rank,
      // null if a member is not found
      // {
      //   member: 'member1',
      //   score: 30
      // }
    });
    
  • rm(member, [λ])

    Removes a member from the leaderboard.

    board.rm('kot', function(err, removed) {
      // removed - false in case the removing member
      // doesn't exist in the leaderboard.
      // true - successful remove
    });
    
  • total([λ])

    Retrieves the total number of members in the leaderboard.

    board.total(function(err, number) {
      // captain obvious
    });
    

##Tests

Leaderboard is covered by Mocha. To run tests:

$ npm test

License

MIT. Copyright (c) 2012 Serge Borbit <[email protected]>

node-leaderboard's People

Contributors

borbit avatar cvan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.