Skip to content

Commit

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

* docs(readme): update badge
  • Loading branch information
Fdawgs authored Nov 28, 2024
1 parent 8e46386 commit 7c0065a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 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/fastify-cors/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@fastify/cors.svg?style=flat)](https://www.npmjs.com/package/@fastify/cors)
[![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)


`@fastify/cors` enables the use of [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) in a Fastify application.
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
})
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"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 --100 node --test"
Expand All @@ -32,12 +32,10 @@
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"c8": "^10.1.2",
"cors": "^2.8.5",
"fastify": "^5.0.0",
"standard": "^17.1.0",
"neostandard": "^0.11.9",
"tsd": "^0.31.1",
"typescript": "~5.7.2"
},
Expand Down
26 changes: 13 additions & 13 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// <reference types="node" />

import { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify';
import { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify'

type OriginCallback = (err: Error | null, origin: ValueOrArray<OriginType>) => void;
type OriginType = string | boolean | RegExp;
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;
type OriginCallback = (err: Error | null, origin: ValueOrArray<OriginType>) => void
type OriginType = string | boolean | RegExp
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>

interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {
}

type FastifyCorsPlugin = FastifyPluginCallback<
NonNullable<fastifyCors.FastifyCorsOptions> | fastifyCors.FastifyCorsOptionsDelegate
>;
>

type FastifyCorsHook =
| 'onRequest'
Expand All @@ -22,8 +22,8 @@ type FastifyCorsHook =
| 'onSend'

declare namespace fastifyCors {
export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void;
export type AsyncOriginFunction = (origin: string | undefined) => Promise<ValueOrArray<OriginType>>;
export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void
export type AsyncOriginFunction = (origin: string | undefined) => Promise<ValueOrArray<OriginType>>

export interface FastifyCorsOptions {
/**
Expand Down Expand Up @@ -102,16 +102,16 @@ declare namespace fastifyCors {
}

export interface FastifyCorsOptionsDelegateCallback { (req: FastifyRequest, cb: (error: Error | null, corsOptions?: FastifyCorsOptions) => void): void }
export interface FastifyCorsOptionsDelegatePromise { (req: FastifyRequest): Promise<FastifyCorsOptions> }
export interface FastifyCorsOptionsDelegatePromise { (req: FastifyRequest): Promise<FastifyCorsOptions> }
export type FastifyCorsOptionsDelegate = FastifyCorsOptionsDelegateCallback | FastifyCorsOptionsDelegatePromise
export type FastifyPluginOptionsDelegate<T = FastifyCorsOptionsDelegate> = (instance: FastifyInstance) => T;
export type FastifyPluginOptionsDelegate<T = FastifyCorsOptionsDelegate> = (instance: FastifyInstance) => T

export const fastifyCors: FastifyCorsPlugin
export { fastifyCors as default };
export { fastifyCors as default }
}

declare function fastifyCors(
declare function fastifyCors (
...params: Parameters<FastifyCorsPlugin>
): ReturnType<FastifyCorsPlugin>;
): ReturnType<FastifyCorsPlugin>

export = fastifyCors;
export = fastifyCors
14 changes: 7 additions & 7 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ app.register(fastifyCors, {

const asyncCorsDelegate: OriginFunction = async (origin) => {
if (origin === undefined || /localhost/.test(origin)) {
return true;
return true
}
return false;
return false
}

app.register(fastifyCors, {
Expand Down Expand Up @@ -371,15 +371,15 @@ appHttp2.register(fastifyCors, delegate)
appHttp2.register(fastifyCors, {
hook: 'preParsing',
origin: function (origin, cb) {
expectType<string|undefined>(origin)
expectType<string | undefined>(origin)
cb(null, false)
},
})

const asyncOriginFn: AsyncOriginFunction = async function (origin): Promise<boolean> {
expectType<string|undefined>(origin)
return false;
};
const asyncOriginFn: AsyncOriginFunction = async function (origin): Promise<boolean> {
expectType<string | undefined>(origin)
return false
}

appHttp2.register(fastifyCors, {
hook: 'preParsing',
Expand Down

0 comments on commit 7c0065a

Please sign in to comment.