mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 19:43:20 +08:00
committed by
Sheetal Nandi
parent
e9622c76ea
commit
8c6804beec
22
decay/decay-tests.ts
Normal file
22
decay/decay-tests.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {redditHot, hackerHot, wilsonScore} from 'decay';
|
||||
|
||||
const upvotes = 42;
|
||||
const downvotes = 12;
|
||||
const posted = new Date(2017, 1, 1);
|
||||
|
||||
let score: number;
|
||||
|
||||
let redditCalculator = redditHot();
|
||||
score = redditCalculator(upvotes, downvotes, posted);
|
||||
redditCalculator = redditHot(10000);
|
||||
score = redditCalculator(upvotes, downvotes, posted);
|
||||
|
||||
let hackerCalculator = hackerHot();
|
||||
score = hackerCalculator(upvotes, posted);
|
||||
hackerCalculator = hackerHot(1.6);
|
||||
score = hackerCalculator(upvotes, posted);
|
||||
|
||||
let wilsonCalculator = wilsonScore();
|
||||
score = wilsonCalculator(upvotes, downvotes);
|
||||
wilsonCalculator = wilsonScore(1.0);
|
||||
score = wilsonCalculator(upvotes, downvotes);
|
||||
52
decay/index.d.ts
vendored
Normal file
52
decay/index.d.ts
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Type definitions for decay 1.0
|
||||
// Project: https://github.com/clux/decay
|
||||
// Definitions by: Eric Naeseth <https://github.com/enaeseth>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Creates a function to rank posts using Reddit's "hot" algorithm.
|
||||
* @param decay controls how quickly rankings drop with time
|
||||
* @return calculator function
|
||||
*/
|
||||
export function redditHot(decay?: number): RedditHotFunction;
|
||||
|
||||
/**
|
||||
* Creates a function to rank posts using the Hacker News "hot" algorithm.
|
||||
* @param gravity controls how quickly rankings drop with time
|
||||
* @return calculator function
|
||||
*/
|
||||
export function hackerHot(gravity?: number): HackerNewsHotFunction;
|
||||
|
||||
/**
|
||||
* Creates a function to rank posts using the Wilson score interval sort (Reddit's "best"
|
||||
* algorithm).
|
||||
* @param confidence statistical confidence
|
||||
* @return calculator function
|
||||
* @see {@link https://redditblog.com/2009/10/15/reddits-new-comment-sorting-system/ Reddit's writeup}
|
||||
*/
|
||||
export function wilsonScore(confidence?: number): WilsonScoreFunction;
|
||||
|
||||
/**
|
||||
* Computes a ranking using Reddit's "hot" algorithm.
|
||||
* @param upvotes number of upvotes the post has received
|
||||
* @param downvotes number of upvotes the post has received
|
||||
* @param date when the post was posted
|
||||
* @return ranking
|
||||
*/
|
||||
export type RedditHotFunction = (upvotes: number, downvotes: number, date: Date) => number;
|
||||
|
||||
/**
|
||||
* Computes a ranking using the Hacker News "hot" algorithm.
|
||||
* @param votes number of upvotes the post has received
|
||||
* @param date when the post was posted
|
||||
* @return ranking
|
||||
*/
|
||||
export type HackerNewsHotFunction = (votes: number, date: Date) => number;
|
||||
|
||||
/**
|
||||
* Computes a ranking using the Wilson score (Reddit's "best" algorithm).
|
||||
* @param upvotes number of upvotes the post has received
|
||||
* @param downvotes number of upvotes the post has received
|
||||
* @return ranking
|
||||
*/
|
||||
export type WilsonScoreFunction = (upvotes: number, downvotes: number) => number;
|
||||
20
decay/tsconfig.json
Normal file
20
decay/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"decay-tests.ts"
|
||||
]
|
||||
}
|
||||
1
decay/tslint.json
Normal file
1
decay/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user