Skip to content
Open
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 src/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe('create(filename, options)', function () {
it('should require a valid type', function () {
assert.throws(
create.bind(null, undefined, { type: 'invalid;type' }),
/Invalid type: invalid;type/,
/Invalid type: "invalid;type"/,
);
});

Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ function createParameters(

if (typeof fallback === 'string') {
if (!ASCII_TEXT_REGEXP.test(fallback)) {
throw new TypeError('Fallback must be valid US-ASCII: ' + fallback);
throw new TypeError(
`Fallback must be valid US-ASCII: ${JSON.stringify(fallback)}`,
);
}

if (fallback === filename) return { filename };
Expand Down Expand Up @@ -375,7 +377,7 @@ export function format(
const extended = options?.extended !== false;

if (!type || !TOKEN_REGEXP.test(type)) {
throw new TypeError('Invalid type: ' + type);
throw new TypeError(`Invalid type: ${JSON.stringify(type)}`);
}

let result = type;
Expand All @@ -385,7 +387,7 @@ export function format(
const value = parameters[param];

if (!TOKEN_REGEXP.test(param)) {
throw new TypeError('Invalid parameter name: ' + param);
throw new TypeError(`Invalid parameter name: ${JSON.stringify(param)}`);
}

if (multipart) {
Expand All @@ -404,7 +406,9 @@ export function format(
}

if (!extended) {
throw new TypeError('Invalid parameter value: ' + value);
throw new TypeError(
`Invalid parameter value: ${JSON.stringify(value)}`,
);
}

result += '; ' + param + '*=' + encodeExtended(value);
Expand Down
Loading