diff --git a/README.md b/README.md index aa326be..8193c92 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/point-of-view/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/point-of-view/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/view.svg?style=flat)](https://www.npmjs.com/package/@fastify/view) -[![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) Templates rendering plugin support for Fastify. diff --git a/package.json b/package.json index 50c27bc..cbe2034 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "example": "node examples/example.js", "example-with-options": "node examples/example-ejs-with-some-options.js", "example-typescript": "npx ts-node types/index.test-d.ts", - "lint": "standard", + "lint": "eslint", + "lint:fix": "eslint --fix", "test-with-snapshot": "cross-env TAP_SNAPSHOT=1 tap test/snap/*", "test": "npm run test:unit && npm run test-with-snapshot && npm run test:typescript", "test:unit": "tap", @@ -58,12 +59,12 @@ "html-minifier-terser": "^7.2.0", "liquidjs": "^10.11.0", "mustache": "^4.2.0", + "neostandard": "^0.11.9", "nunjucks": "^3.2.4", "pino": "^9.0.0", "pug": "^3.0.2", "simple-get": "^4.0.1", "split2": "^4.2.0", - "standard": "^17.1.0", "tap": "^21.0.0", "tsd": "^0.31.0", "twig": "^1.17.1" diff --git a/types/index-global-layout.test-d.ts b/types/index-global-layout.test-d.ts index 9c33b26..d5b5fbd 100644 --- a/types/index-global-layout.test-d.ts +++ b/types/index-global-layout.test-d.ts @@ -1,62 +1,62 @@ -import fastify from "fastify"; -import fastifyView, { FastifyViewOptions } from ".."; -import { expectAssignable } from "tsd"; -import * as path from "path"; +import fastify from 'fastify' +import fastifyView, { FastifyViewOptions } from '..' +import { expectAssignable } from 'tsd' +import * as path from 'path' interface Locals { appVersion: string, } -declare module "fastify" { +declare module 'fastify' { interface FastifyReply { locals: Partial | undefined } } -const app = fastify(); +const app = fastify() app.register(fastifyView, { engine: { - ejs: require("ejs"), + ejs: require('ejs'), }, - templates: "templates", + templates: 'templates', includeViewExtension: true, defaultContext: { dev: true, }, options: {}, - charset: "utf-8", - layout: "layout-ts", + charset: 'utf-8', + layout: 'layout-ts', maxCache: 100, production: false, - root: path.resolve(__dirname, "../templates"), - viewExt: "ejs", -}); + root: path.resolve(__dirname, '../templates'), + viewExt: 'ejs', +}) -app.get("/", (request, reply) => { - reply.view("/layout-ts-content-no-data"); -}); +app.get('/', (request, reply) => { + reply.view('/layout-ts-content-no-data') +}) -app.get("/data", (request, reply) => { +app.get('/data', (request, reply) => { if (!reply.locals) { reply.locals = {} } // reply.locals.appVersion = 1 // not a valid type reply.locals.appVersion = '4.14.0' - reply.view("/layout-ts-content-with-data", { text: "Sample data" }); -}); + reply.view('/layout-ts-content-with-data', { text: 'Sample data' }) +}) -app.get("/dataTyped", (request, reply) => { +app.get('/dataTyped', (request, reply) => { if (!reply.locals) { reply.locals = {} } // reply.locals.appVersion = 1 // not a valid type reply.locals.appVersion = '4.14.0' - reply.view<{ text: string; }>("/layout-ts-content-with-data", { text: "Sample data" }); -}); + reply.view<{ text: string; }>('/layout-ts-content-with-data', { text: 'Sample data' }) +}) -app.listen({port: 3000}, (err, address) => { +app.listen({ port: 3000 }, (err, address) => { if (err) throw err console.log(`server listening on ${address} ...`) }) diff --git a/types/index.d.ts b/types/index.d.ts index 12a6bb1..0fa1bf8 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,6 +1,6 @@ -import { FastifyPluginAsync } from 'fastify'; +import { FastifyPluginAsync } from 'fastify' -declare module "fastify" { +declare module 'fastify' { interface RouteSpecificOptions { layout?: string; @@ -59,5 +59,5 @@ declare namespace fastifyView { export const fastifyViewCache: Symbol } -declare function fastifyView(...params: Parameters): ReturnType +declare function fastifyView (...params: Parameters): ReturnType export = fastifyView diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 8a79986..36c4579 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,41 +1,41 @@ -import fastify from "fastify"; -import fastifyView, { PointOfViewOptions, FastifyViewOptions } from ".."; -import { expectAssignable, expectNotAssignable, expectDeprecated, expectType } from "tsd"; -import * as path from "path"; +import fastify from 'fastify' +import fastifyView, { PointOfViewOptions, FastifyViewOptions } from '..' +import { expectAssignable, expectNotAssignable, expectDeprecated, expectType } from 'tsd' +import * as path from 'path' interface Locals { appVersion: string, } -declare module "fastify" { +declare module 'fastify' { interface FastifyReply { locals: Partial | undefined } } -const app = fastify(); +const app = fastify() app.register(fastifyView, { engine: { - ejs: require("ejs"), + ejs: require('ejs'), }, - templates: "templates", + templates: 'templates', includeViewExtension: true, defaultContext: { dev: true, }, options: {}, - charset: "utf-8", + charset: 'utf-8', maxCache: 100, production: false, - root: path.resolve(__dirname, "../templates"), - viewExt: "ejs", -}); + root: path.resolve(__dirname, '../templates'), + viewExt: 'ejs', +}) -app.get("/", (request, reply) => { - reply.view("/index-with-no-data"); -}); +app.get('/', (request, reply) => { + reply.view('/index-with-no-data') +}) -app.get("/data", (request, reply) => { +app.get('/data', (request, reply) => { if (!reply.locals) { reply.locals = {} } @@ -44,10 +44,10 @@ app.get("/data", (request, reply) => { expectNotAssignable['appVersion']>(1) reply.locals.appVersion = '4.14.0' - reply.view("/index", { text: "Sample data" }); -}); + reply.view('/index', { text: 'Sample data' }) +}) -app.get("/dataTyped", (request, reply) => { +app.get('/dataTyped', (request, reply) => { if (!reply.locals) { reply.locals = {} } @@ -56,42 +56,42 @@ app.get("/dataTyped", (request, reply) => { expectNotAssignable['appVersion']>(1) reply.locals.appVersion = '4.14.0' - reply.view<{ text: string; }>("/index", { text: "Sample data" }); -}); + reply.view<{ text: string; }>('/index', { text: 'Sample data' }) +}) -app.get("/use-layout", (request, reply) => { - reply.view("/layout-ts-content-with-data", {text: "Using a layout"}, {layout: "/layout-ts"}) -}); +app.get('/use-layout', (request, reply) => { + reply.view('/layout-ts-content-with-data', { text: 'Using a layout' }, { layout: '/layout-ts' }) +}) -app.get("/view-async", async (request, reply) => { +app.get('/view-async', async (request, reply) => { expectAssignable['appVersion']>('4.14.0') expectNotAssignable['appVersion']>(1) type ViewAsyncDataParamType = Parameters[1] - expectAssignable({ text: "Sample data" }) - expectAssignable({ notText: "Sample data "}) + expectAssignable({ text: 'Sample data' }) + expectAssignable({ notText: 'Sample data ' }) - const html = await reply.viewAsync("/index", { text: "Sample data" }); + const html = await reply.viewAsync('/index', { text: 'Sample data' }) expectType(html) return html -}); +}) -app.get("/view-async-generic-provided", async (request, reply) => { +app.get('/view-async-generic-provided', async (request, reply) => { type ViewAsyncDataParamType = Parameters>[1] - expectAssignable({ text: "Sample data" }) - expectNotAssignable({ notText: "Sample data "}) + expectAssignable({ text: 'Sample data' }) + expectNotAssignable({ notText: 'Sample data ' }) - const html = reply.viewAsync<{ text: string; }>("/index", { text: "Sample data" }); + const html = reply.viewAsync<{ text: string; }>('/index', { text: 'Sample data' }) expectType>(html) return html -}); +}) -app.listen({port: 3000}, (err, address) => { +app.listen({ port: 3000 }, (err, address) => { if (err) throw err console.log(`server listening on ${address} ...`) }) -expectType>(app.view("/index", {}, { layout: "/layout-ts"})) +expectType>(app.view('/index', {}, { layout: '/layout-ts' })) expectAssignable({ engine: { twig: require('twig') }, propertyName: 'mobile' }) @@ -117,4 +117,4 @@ expectType>(nunjucksApp.view('/', { text: 'Hello world' })) expectAssignable({ engine: { nunjucks: require('nunjucks') }, templates: 'templates' }) -expectAssignable({ engine: { nunjucks: require('nunjucks') }, templates: ['templates/nunjucks-layout', 'templates/nunjucks-template']}) +expectAssignable({ engine: { nunjucks: require('nunjucks') }, templates: ['templates/nunjucks-layout', 'templates/nunjucks-template'] })