Socket
Socket
Sign inDemoInstall

@fastify/static

Package Overview
Dependencies
Maintainers
18
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/static - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

15

index.d.ts

@@ -46,9 +46,16 @@ // Definitions by: Jannik <https://github.com/jannikkeye>

interface ListOptions {
format: 'json' | 'html';
names: string[];
render: ListRender;
names?: string[];
extendedFolderInfo?: boolean;
}
interface ListOptionsJsonFormat extends ListOptions {
format: 'json';
jsonFormat?: 'names' | 'extended';
}
interface ListOptionsHtmlFormat extends ListOptions {
format: 'html';
render: ListRender;
}
// Passed on to `send`

@@ -77,3 +84,3 @@ interface SendOptions {

wildcard?: boolean;
list?: boolean | ListOptions;
list?: boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat;
allowedPath?: (pathName: string, root?: string) => boolean;

@@ -80,0 +87,0 @@ /**

@@ -11,3 +11,3 @@ 'use strict'

* @param {string} dir full path fs dir
* @param {ListOptions} options
* @param {(boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat)} options
* @param {string} dotfiles

@@ -103,3 +103,3 @@ * note: can't use glob because don't get error on non existing dir

* @param {string} dir full path fs dir
* @param {ListOptions} options
* @param {(boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat)} options
* @param {string} route request route

@@ -156,3 +156,3 @@ * @param {string} dotfiles

* @param {string} route request route
* @param {ListOptions} options
* @param {(boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat)} options
* @return {boolean}

@@ -200,5 +200,11 @@ */

}
if (options.list.jsonFormat != null && options.list.jsonFormat !== 'names' && options.list.jsonFormat !== 'extended') {
return new TypeError('The `list.jsonFormat` option must be name or extended')
}
if (options.list.format === 'html' && typeof options.list.render !== 'function') {
return new TypeError('The `list.render` option must be a function and is required with html format')
}
if (options.list.format === 'html' && options.list.jsonFormat != null) {
return new TypeError('The `list.jsonFormat` option must be with json format')
}
}

@@ -205,0 +211,0 @@

{
"name": "@fastify/static",
"version": "6.2.0",
"version": "6.3.0",
"description": "Plugin for serving static files as fast as possible.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -43,3 +43,3 @@ 'use strict'

t.test('throws when `list.format option` is invalid', t => {
t.test('throws when `list.format` option is invalid', t => {
t.plan(2)

@@ -60,2 +60,10 @@

t.test('throws when `list.jsonFormat` option is invalid', t => {
t.plan(2)
const err = dirList.validateOptions({ list: { jsonFormat: 'hello' } })
t.type(err, TypeError)
t.equal(err.message, 'The `list.jsonFormat` option must be name or extended')
})
t.test('throws when `list.format` is html and `list render` is not a function', t => {

@@ -69,2 +77,10 @@ t.plan(2)

t.test('throws when `list.format` is html and `list.jsonFormat` is given', t => {
t.plan(2)
const err = dirList.validateOptions({ list: { format: 'html', render: () => '', jsonFormat: 'extended' } })
t.type(err, TypeError)
t.equal(err.message, 'The `list.jsonFormat` option must be with json format')
})
t.test('dir list wrong options', t => {

@@ -71,0 +87,0 @@ t.plan(3)

import fastify from 'fastify'
import { expectError } from 'tsd'
import { expectAssignable, expectError } from 'tsd'
import fastifyStatic, { FastifyStaticOptions } from '../..'

@@ -35,2 +35,32 @@

expectAssignable<FastifyStaticOptions>({
root: '',
list: {
format: 'json',
}
})
expectError<FastifyStaticOptions>({
root: '',
list: {
format: 'json',
render: () => ''
}
})
expectAssignable<FastifyStaticOptions>({
root: '',
list: {
format: 'html',
render: () => ''
}
})
expectError<FastifyStaticOptions>({
root: '',
list: {
format: 'html',
}
})
appWithImplicitHttp

@@ -37,0 +67,0 @@ .register(fastifyStatic, options)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc