Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard (#74)
Browse files Browse the repository at this point in the history
* build(deps-dev): replace standard with neostandard

* chore: add eslint.config.js

* fix linting

---------

Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com>
  • Loading branch information
Fdawgs and Uzlopak authored Dec 8, 2024
1 parent 785503d commit 6168cf0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/// <reference types="node" />

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
40 changes: 20 additions & 20 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<string>(proxyaddr(req, addr => addr === '127.0.0.1'))
expectType<string>(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<string>(proxyaddr(req, '127.0.0.1'))
expectType<string>(proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8']))
expectType<string>(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<string>(proxyaddr(req, '::1'))
expectType<string>(proxyaddr(req, ['::1/128', 'fe80::/10']))

proxyaddr(req, 'loopback');
proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64']);
expectType<string>(proxyaddr(req, 'loopback'))
expectType<string>(proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64']))

// $ExpectType string[]
proxyaddr.all(req);
proxyaddr.all(req, 'loopback');
expectType<string[]>(proxyaddr.all(req))
expectType<string[]>(proxyaddr.all(req, 'loopback'))

const trust = proxyaddr.compile('localhost');
proxyaddr.compile(['localhost']);
trust; // $ExpectType (addr: string, i: number) => boolean
proxyaddr(req, trust);
});
proxyaddr.compile(['localhost'])

const trust = proxyaddr.compile('localhost')
expectType<(addr: string, i: number) => boolean>(trust)
proxyaddr(req, trust)
})

0 comments on commit 6168cf0

Please sign in to comment.