Skip to content

Commit

Permalink
feat: add nodenext compatiblity
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Feb 15, 2023
1 parent bd8f65d commit b897446
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# Removing the `files` key and replacing it with this `.npmignore` saves some bytes, which
# should improve installation performance slightly
*
!src/index.js
!src/index.js
!types/index.d.ts
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"xml"
],
"main": "src/index.js",
"types": "types/index.d.ts",
"repository": "git+https://github.com/Fdawgs/fastify-json-to-xml.git",
"homepage": "https://github.com/Fdawgs/fastify-json-to-xml",
"bugs": {
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const secJSON = require("secure-json-parse");
* replacement character, U+FFFD. Will throw error if invalid characters found when enabled.
* Disabled by default.
*/
async function plugin(server, options) {
async function fastifyJsonToXml(server, options) {
server.addHook("onSend", async (req, res, payload) => {
if (
res.getHeader("content-type")?.includes("application/json") &&
Expand All @@ -40,7 +40,9 @@ async function plugin(server, options) {
});
}

module.exports = fp(plugin, {
module.exports = fp(fastifyJsonToXml, {
fastify: "4.x",
name: "fastify-json-to-xml",
});
module.exports.default = fastifyJsonToXml;
module.exports.fastifyJsonToXml = fastifyJsonToXml;
18 changes: 18 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { FastifyPluginAsync } from "fastify";

type FastifyJsonToXml =
FastifyPluginAsync<fastifyJsonToXml.FastifyJsonToXmlOptions>;

declare namespace fastifyJsonToXml {
export interface FastifyJsonToXmlOptions {
replaceInvalidChars?: boolean;
}

export const fastifyJsonToXml: FastifyPluginAsync;
export { fastifyJsonToXml as default };
}

declare function fastifyJsonToXml(
...params: Parameters<FastifyJsonToXml>
): ReturnType<FastifyJsonToXml>;
export = fastifyJsonToXml;

0 comments on commit b897446

Please sign in to comment.