mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 19:12:20 +08:00
Merge pull request #25929 from AmirTugi/master
Add declaration file for express-paginate
This commit is contained in:
26
types/express-paginate/express-paginate-tests.ts
Normal file
26
types/express-paginate/express-paginate-tests.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import express from 'express';
|
||||
import * as paginate from 'express-paginate';
|
||||
|
||||
declare function findAndCountAll(params: object): Promise<{count: number, rows: object[]}>;
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(paginate.middleware(10, 50));
|
||||
|
||||
app.get('/users', async (req, res, next) => {
|
||||
// req.skip should be available
|
||||
return findAndCountAll({limit: req.query.limit, offset: req.skip})
|
||||
.then(results => {
|
||||
const itemCount = results.count;
|
||||
const pageCount = Math.ceil(results.count / req.query.limit);
|
||||
res.render('users/all_users', {
|
||||
users: results.rows,
|
||||
pageCount,
|
||||
itemCount,
|
||||
currentPageHref: paginate.href(req)(false, req.params),
|
||||
// Instead of exposing this to the html template, we'll test this here and pass a static number
|
||||
hasNextPages: paginate.hasNextPages(req)(pageCount),
|
||||
pages: paginate.getArrayPages(req)(3, pageCount, req.query.page)
|
||||
});
|
||||
}).catch(next);
|
||||
});
|
||||
26
types/express-paginate/index.d.ts
vendored
Normal file
26
types/express-paginate/index.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for express-paginate 1.0
|
||||
// Project: https://github.com/niftylettuce/express-paginate
|
||||
// Definitions by: Amir Tugendhaft <https://github.com/AmirTugi>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.7
|
||||
|
||||
import express = require("express");
|
||||
|
||||
declare global {
|
||||
namespace Express {
|
||||
interface Request {
|
||||
skip?: number;
|
||||
offset?: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface PageElement {
|
||||
number: number;
|
||||
url: typeof href;
|
||||
}
|
||||
|
||||
export function middleware(limit?: number, maxLimit?: number): (req: express.Request, res: express.Response, next: express.NextFunction) => void;
|
||||
export function hasNextPages(req: express.Request): (pageCount: number) => boolean;
|
||||
export function href(req: express.Request): (prev: object | boolean, params: object) => string;
|
||||
export function getArrayPages(req: express.Request): (limit: number, pageCount: number, currentPage: number) => PageElement[];
|
||||
24
types/express-paginate/tsconfig.json
Normal file
24
types/express-paginate/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"express-paginate-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/express-paginate/tslint.json
Normal file
1
types/express-paginate/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user