# neaterboard

> a neater leaderboard

Latest version **1.0.1** (published 2017-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install neaterboard
pnpm add neaterboard
yarn add neaterboard
bun add neaterboard
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-05-10 |
| First published | 2017-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | thanh-nm |
| Maintainers | thanh-nm |
| Keywords | leaderboard, scoreboard, redis |

## Links

- npm: https://www.npmjs.com/package/neaterboard
- Repository: https://github.com/thanh-nm/neaterboardjs
- Homepage: https://github.com/thanh-nm/neaterboardjs#readme
- Issues: https://github.com/thanh-nm/neaterboardjs/issues
- npm.io page: https://npm.io/package/neaterboard

## Dependencies (4)

- [async](https://npm.io/package/async.md) ^2.4.0
- [redis](https://npm.io/package/redis.md) ^2.7.1
- [log4js](https://npm.io/package/log4js.md) ^1.1.1
- [node-cron](https://npm.io/package/node-cron.md) ^1.1.3

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-05-10

## README

# neaderboardjs

A NodeJS leaderboard module that besides the all-time leaderboard supports also periodic leaderboards: daily, weekly, monthly options backed by [Redis](http://redis.io).

## Installation

`npm install neaderboard`
Make sure your redis server is running! Redis configuration is outside the scope of this README, but
check out the [Redis quickstart](https://redis.io/topics/quickstart).

## Setup
```javascript
var neaterboardjs = require('neaterboard');
var Neaterboard = neaterboardjs.Neaterboard;
```

### Creating a leaderboard

Create a new leaderboard. This will create an all-time leaderboard.

```javascript
var neaterboard = new Neaterboard();
```

If you have redis-server running on the same machine as node, then the default Neaterboard constructure will create a default RedisClient with default port and host. If you want to supply configuration for your RedisClient, look into [node_redis#rediscreateclient] (https://github.com/NodeRedis/node_redis#rediscreateclient)

### Adding and removing periodic leaderboards
`addLeaderboards([options])`

```javascript
neaterboard.addLeaderboards({daily: true, weekly:true, monthly:true});
```
`removeLeaderboards([options])`
```javascript
neaterboard.removeLeaderboards({daily: true, weekly:true, monthly:true});
```
### Insert
`insertScore(userId, rawScore, callback[, options])`

without options:
```javascript
neaterboard.insertScore('fred', 100, (err, res) => {
  console.log(res);
});
```

with options:
* featureId: a game feature
* date: default is set to the inserted date
* scoreData: any additional score data in JSON string or a simple string

```javascript
neaterboard.insertScore('fred', 100, (err, res) => {
  console.log(res);
}, {featureId: 'quiz 1', scoreData: {timeTaken:'1000'}});
```

### Getting the leaderboard
`getLeaderboard(callback[, options])`

options:
* leaderboard: daily | weekly | monthly. Default is set to all-time
* featureId: a game feature or none
* fromRank: zero-based start index of the leaderboard to return
* toRank: zero-based end index of the leaderboard to return. If fromRank and toRank is not given, the function returns the entire leaderboard

```javascript
neaterboard.getLeaderboard((err, userIds) => {
  console.log('userIds='+userIds);
});
```

```javascript
neaterboard.getLeaderboard((err, userIds) => {
  console.log('userIds='+userIds);
}, {leaderboard:'daily', featureId:'quiz 1', fromRank:5, toRank:10});
```

`getAroundMeLeaderboard(userId, callback, options)`
Returns the leaderboard within a given range around the rank of the given user.

options:
* leaderboard: daily | weekly | monthly. Default is set to all-time
* featureId: a game feature or none
* range: a positive number. If no range is specified, the returned leanderboard contains all ranks +/- 10 around the given user


### Getting the rank of a user on a leaderboard
`getRank(userId, callback[, options])`
Returns the zero-based rank of the user.

options:
* leaderboard: daily | weekly | monthly. Default is set to all-time
* featureId: a game feature or none

```javascript
neaterboard.getRank('fred', (err, rank) => {
  console.log('rank=' + rank);
});
```

```javascript
neaterboard.getRank('fred', (err, rank) => {
  console.log('rank=' + rank);
}, {leaderboard: 'weekly', featureId: 'quiz 1'});
```

#### Retrieving user's best score
`getUserBestScore(userId, callback [, getOptions] [, returnOptions]) `

getOptions:
* leaderboard: daily | weekly | monthly. Default is set to all-time
* featureId: a game feature or none

returnOptions:
If no returnOptions are passed, only the rawScore is returned, otherwise the function returns a json object contains the data specified in returnOptions.
* rawScore: the inserted rawScore
* scoreData: any additional score data in JSON string or a simple string
* date: default is set to the inserted date

```javascript
neaterboard.getUserBestScore('fred', (err, score) => {
  console.log('score=' + score);
});
```

```javascript
neaterboard.getUserBestScore('fred', (err, score) => {
  console.log('rank=' + score);
},{leaderboard:'daily', featureId:'quiz 1'}, {date:true, scoreData:true});
```
## Copyright
Copyright (c) 2017 Thanh Nm. See LICENSE.txt for further details.

---
_Source: https://npm.io/package/neaterboard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
