Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

build(deps-dev): replace standard with neostandard #176

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-accepts/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@fastify/accepts.svg?style=flat)](https://www.npmjs.com/package/@fastify/accepts)
[![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)

Add an accepts parser to Fastify.

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 @@ -9,9 +9,8 @@
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"fastify": "^5.0.0",
"neostandard": "^0.11.9",
"request": "^2.88.0",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"tap": "^20.0.1",
"tsd": "^0.31.1"
},
Expand All @@ -20,7 +19,8 @@
"fastify-plugin": "^5.0.0"
},
"scripts": {
"lint": "standard | snazzy",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap"
Expand Down
22 changes: 11 additions & 11 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyPluginCallback } from "fastify"
import { FastifyPluginCallback } from 'fastify'

declare module "fastify" {
declare module 'fastify' {
// Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/accepts/index.d.ts
// Definitions by: Stefan Reichel <https://github.com/bomret>
// Brice BERNARD <https://github.com/brikou>
Expand Down Expand Up @@ -95,14 +95,14 @@ declare module "fastify" {

interface FastifyReply {
requestAccepts(): Accepts
requestCharset: Accepts["charset"]
requestCharsets: Accepts["charsets"]
requestEncoding: Accepts["encoding"]
requestEncodings: Accepts["charsets"]
requestLanguage: Accepts["language"]
requestLanguages: Accepts["languages"]
requestType: Accepts["type"]
requestTypes: Accepts["types"]
requestCharset: Accepts['charset']
requestCharsets: Accepts['charsets']
requestEncoding: Accepts['encoding']
requestEncodings: Accepts['charsets']
requestLanguage: Accepts['language']
requestLanguages: Accepts['languages']
requestType: Accepts['type']
requestTypes: Accepts['types']
}
}
type FastifyAccepts = FastifyPluginCallback<fastifyAccepts.FastifyAcceptsOptions>
Expand All @@ -116,5 +116,5 @@ declare namespace fastifyAccepts {
export { fastifyAccepts as default }
}

declare function fastifyAccepts(...params: Parameters<FastifyAccepts>): ReturnType<FastifyAccepts>
declare function fastifyAccepts (...params: Parameters<FastifyAccepts>): ReturnType<FastifyAccepts>
export = fastifyAccepts
125 changes: 64 additions & 61 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import fastify from "fastify"
import accepts from ".."
import fastify from 'fastify'
import accepts from '..'

const app = fastify()

app.register(accepts)

app.get("/", (request, reply) => {
const accept = request.accepts();

const charsets = accept.charsets();
const charsetFromEmpty = accept.charset();
const charsetFromParams = accept.charset("json", "text");
const charsetFromArray = accept.charset(["json", "text"]);

const encodings = accept.encodings();
const encodingFromEmpty = accept.encoding();
const encodingFromParams = accept.encoding("json", "text");
const encodingFromArray = accept.encoding(["json", "text"]);

const languages = accept.languages();
const languageFromEmpty = accept.language();
const languageFromParams = accept.language("json", "text");
const languageFromArray = accept.language(["json", "text"]);

const types = accept.types();
const typeFromEmpty = accept.type();
const typeFromParams = accept.type("json", "text");
const typeFromArray = accept.type(["json", "text"]);
app.get('/', (request, reply) => {
const accept = request.accepts()

// Charsets
accept.charsets()
accept.charset()
accept.charset('json', 'text')
accept.charset(['json', 'text'])

// Encoding
accept.encodings()
accept.encoding()
accept.encoding('json', 'text')
accept.encoding(['json', 'text'])

// Languages
accept.languages()
accept.language()
accept.language('json', 'text')
accept.language(['json', 'text'])

// Types
accept.types()
accept.type()
accept.type('json', 'text')
accept.type(['json', 'text'])

request.charset()
request.charsets()
Expand All @@ -37,23 +41,23 @@ app.get("/", (request, reply) => {
request.type()
request.types()

request.charset(["aa", "aa"])
request.charsets(["aa", "aa"])
request.encoding(["aa", "aa"])
request.encodings(["aa", "aa"])
request.language(["aa", "aa"])
request.languages(["aa", "aa"])
request.type(["aa", "aa"])
request.types(["aa", "aa"])

request.charset("aa", "aa")
request.charsets("aa", "aa")
request.encoding("aa", "aa")
request.encodings("aa", "aa")
request.language("aa", "aa")
request.languages("aa", "aa")
request.type("aa", "aa")
request.types("aa", "aa")
request.charset(['aa', 'aa'])
request.charsets(['aa', 'aa'])
request.encoding(['aa', 'aa'])
request.encodings(['aa', 'aa'])
request.language(['aa', 'aa'])
request.languages(['aa', 'aa'])
request.type(['aa', 'aa'])
request.types(['aa', 'aa'])

request.charset('aa', 'aa')
request.charsets('aa', 'aa')
request.encoding('aa', 'aa')
request.encodings('aa', 'aa')
request.language('aa', 'aa')
request.languages('aa', 'aa')
request.type('aa', 'aa')
request.types('aa', 'aa')

reply.requestAccepts()

Expand All @@ -66,24 +70,23 @@ app.get("/", (request, reply) => {
reply.requestType()
reply.requestTypes()

reply.requestCharset(["aa", "aa"])
reply.requestCharsets(["aa", "aa"])
reply.requestEncoding(["aa", "aa"])
reply.requestEncodings(["aa", "aa"])
reply.requestLanguage(["aa", "aa"])
reply.requestLanguages(["aa", "aa"])
reply.requestType(["aa", "aa"])
reply.requestTypes(["aa", "aa"])

reply.requestCharset("aa", "aa")
reply.requestCharsets("aa", "aa")
reply.requestEncoding("aa", "aa")
reply.requestEncodings("aa", "aa")
reply.requestLanguage("aa", "aa")
reply.requestLanguages("aa", "aa")
reply.requestType("aa", "aa")
reply.requestTypes("aa", "aa")

reply.send({ hello: "world" })
reply.requestCharset(['aa', 'aa'])
reply.requestCharsets(['aa', 'aa'])
reply.requestEncoding(['aa', 'aa'])
reply.requestEncodings(['aa', 'aa'])
reply.requestLanguage(['aa', 'aa'])
reply.requestLanguages(['aa', 'aa'])
reply.requestType(['aa', 'aa'])
reply.requestTypes(['aa', 'aa'])

reply.requestCharset('aa', 'aa')
reply.requestCharsets('aa', 'aa')
reply.requestEncoding('aa', 'aa')
reply.requestEncodings('aa', 'aa')
reply.requestLanguage('aa', 'aa')
reply.requestLanguages('aa', 'aa')
reply.requestType('aa', 'aa')
reply.requestTypes('aa', 'aa')

reply.send({ hello: 'world' })
})

Loading