parse-prefer-header: More specific typings (#42642)

* parse-prefer-header: Allow null or undefined input

* parse-prefer-header: More explicit return value typing

* parse-prefer-header: amend contributor list

* parse-prefer-header: Support ReadonlyArray argument

* parse-prefer-header: Add separate tests for Array and ReadonlyArray
This commit is contained in:
Marcell Toth
2020-02-26 20:33:49 +01:00
committed by GitHub
parent 92a3a4061b
commit cd414cbf2f
2 changed files with 10 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
// Type definitions for parse-prefer-header 1.0
// Project: https://github.com/ppaskaris/node-parse-prefer-header
// Definitions by: Vincenzo Chianese <https://github.com/XVincentX>
// Definitions by: Vincenzo Chianese <https://github.com/XVincentX>, Marcell Toth <https://github.com/marcelltoth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function parsePreferHeader(preferHeader: string | string[]): { [key: string]: string | boolean };
declare function parsePreferHeader(preferHeader: string | ReadonlyArray<string> | null | undefined): { [key: string]: string | true };
export = parsePreferHeader;

View File

@@ -1,4 +1,11 @@
import parsePreferHeader = require('parse-prefer-header');
parsePreferHeader(['respond-async, wait=100', 'handling=lenient']);
const testArray = ['respond-async, wait=100', 'handling=lenient'];
const readonlyTestArray: ReadonlyArray<string> = testArray;
parsePreferHeader(testArray);
parsePreferHeader(readonlyTestArray);
parsePreferHeader('');
parsePreferHeader(null);
parsePreferHeader(undefined);