diff --git a/README.md b/README.md index 3345520..92d4ed2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/proxy-addr/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/proxy-addr/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/proxy-addr.svg?style=flat)](https://www.npmjs.com/package/@fastify/proxy-addr) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) +[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) Determine address of proxied request. diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..89fd678 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = require('neostandard')({ + ignores: require('neostandard').resolveIgnoresFromGitignore(), + ts: true +}) diff --git a/package.json b/package.json index ebfd278..ba4520c 100644 --- a/package.json +++ b/package.json @@ -30,14 +30,14 @@ "beautify-benchmark": "0.2.4", "benchmark": "2.1.4", "c8": "^10.1.2", - "standard": "^17.1.0", + "neostandard": "^0.11.9", "tape": "^5.7.5", "tsd": "^0.31.0" }, "scripts": { "bench": "node benchmark/index.js", - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", "test:unit": "c8 tape test/**/*.js" diff --git a/types/index.d.ts b/types/index.d.ts index e554f50..c3fd134 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,18 +1,18 @@ /// -import { IncomingMessage } from 'http'; +import { IncomingMessage } from 'http' type FastifyProxyAddr = typeof proxyaddr -declare function proxyaddr(req: IncomingMessage, trust: proxyaddr.Address | proxyaddr.Address[] | ((addr: string, i: number) => boolean)): string; +declare function proxyaddr (req: IncomingMessage, trust: proxyaddr.Address | proxyaddr.Address[] | ((addr: string, i: number) => boolean)): string declare namespace proxyaddr { - export function all(req: IncomingMessage, trust?: Address | Address[] | ((addr: string, i: number) => boolean)): string[]; - export function compile(val: Address | Address[]): (addr: string, i: number) => boolean; + export function all (req: IncomingMessage, trust?: Address | Address[] | ((addr: string, i: number) => boolean)): string[] + export function compile (val: Address | Address[]): (addr: string, i: number) => boolean - export type Address = 'loopback' | 'linklocal' | 'uniquelocal' | string; + export type Address = 'loopback' | 'linklocal' | 'uniquelocal' | string export const proxyAddr: FastifyProxyAddr export { proxyAddr as default } } -export = proxyaddr; +export = proxyaddr diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 067e761..ebdce35 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,27 +1,27 @@ -import proxyaddr from '..'; -import { createServer } from 'http'; +import proxyaddr from '..' +import { createServer } from 'http' +import { expectType } from 'tsd' createServer(req => { - // $ExpectType string - proxyaddr(req, addr => addr === '127.0.0.1'); - proxyaddr(req, (addr, i) => i < 1); + expectType(proxyaddr(req, addr => addr === '127.0.0.1')) + expectType(proxyaddr(req, (addr, i) => i < 1)) - proxyaddr(req, '127.0.0.1'); - proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8']); - proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0']); + expectType(proxyaddr(req, '127.0.0.1')) + expectType(proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])) + expectType(proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])) - proxyaddr(req, '::1'); - proxyaddr(req, ['::1/128', 'fe80::/10']); + expectType(proxyaddr(req, '::1')) + expectType(proxyaddr(req, ['::1/128', 'fe80::/10'])) - proxyaddr(req, 'loopback'); - proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64']); + expectType(proxyaddr(req, 'loopback')) + expectType(proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])) - // $ExpectType string[] - proxyaddr.all(req); - proxyaddr.all(req, 'loopback'); + expectType(proxyaddr.all(req)) + expectType(proxyaddr.all(req, 'loopback')) - const trust = proxyaddr.compile('localhost'); - proxyaddr.compile(['localhost']); - trust; // $ExpectType (addr: string, i: number) => boolean - proxyaddr(req, trust); -}); \ No newline at end of file + proxyaddr.compile(['localhost']) + + const trust = proxyaddr.compile('localhost') + expectType<(addr: string, i: number) => boolean>(trust) + proxyaddr(req, trust) +})