Skip to content

Commit 212e7be

Browse files
committed
Use named exports for consistency across the project.
1 parent 139a6cc commit 212e7be

14 files changed

+36
-47
lines changed

src/FormDataEncoder.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import createBoundary from "./util/createBoundary.js"
2-
import isPlainObject from "./util/isPlainObject.js"
3-
import normalize from "./util/normalizeValue.js"
4-
import escape from "./util/escapeName.js"
5-
6-
import {isFile} from "./util/isFile.js"
7-
import {isFormData} from "./util/isFormData.js"
8-
import {proxyHeaders} from "./util/proxyHeaders.js"
91
import type {LowercaseObjectKeys} from "./util/LowercaseObjectKeys.js"
10-
import {FormDataLike} from "./FormDataLike.js"
11-
import {FileLike} from "./FileLike.js"
2+
import {createBoundary} from "./util/createBoundary.js"
3+
import {normalizeValue} from "./util/normalizeValue.js"
4+
import {isPlainObject} from "./util/isPlainObject.js"
5+
import {proxyHeaders} from "./util/proxyHeaders.js"
6+
import type {FormDataLike} from "./FormDataLike.js"
7+
import {isFormData} from "./util/isFormData.js"
8+
import {escapeName} from "./util/escapeName.js"
9+
import type {FileLike} from "./FileLike.js"
10+
import {isFile} from "./util/isFile.js"
1211

1312
type FormDataEntryValue = string | FileLike
1413

@@ -195,10 +194,10 @@ export class FormDataEncoder {
195194
let header = ""
196195

197196
header += `${this.#DASHES}${this.boundary}${this.#CRLF}`
198-
header += `Content-Disposition: form-data; name="${escape(name)}"`
197+
header += `Content-Disposition: form-data; name="${escapeName(name)}"`
199198

200199
if (isFile(value)) {
201-
header += `; filename="${escape(value.name)}"${this.#CRLF}`
200+
header += `; filename="${escapeName(value.name)}"${this.#CRLF}`
202201
header += `Content-Type: ${value.type || "application/octet-stream"}`
203202
}
204203

@@ -218,7 +217,9 @@ export class FormDataEncoder {
218217
let length = 0
219218

220219
for (const [name, raw] of this.#form) {
221-
const value = isFile(raw) ? raw : this.#encoder.encode(normalize(raw))
220+
const value = isFile(raw) ? raw : this.#encoder.encode(
221+
normalizeValue(raw)
222+
)
222223

223224
length += this.#getFieldHeader(name, value).byteLength
224225

@@ -277,7 +278,9 @@ export class FormDataEncoder {
277278
*/
278279
* values(): Generator<Uint8Array | FileLike, void, undefined> {
279280
for (const [name, raw] of this.#form) {
280-
const value = isFile(raw) ? raw : this.#encoder.encode(normalize(raw))
281+
const value = isFile(raw) ? raw : this.#encoder.encode(
282+
normalizeValue(raw)
283+
)
281284

282285
yield this.#getFieldHeader(name, value)
283286

src/util/createBoundary.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from "ava"
22

3-
import createBoundary from "./createBoundary.js"
3+
import {createBoundary} from "./createBoundary.js"
44

55
test("Returns a string", t => {
66
const actual = createBoundary()

src/util/createBoundary.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
1515
* createBoundary() // -> n2vw38xdagaq6lrv
1616
* ```
1717
*/
18-
function createBoundary(): string {
18+
export function createBoundary(): string {
1919
let size = 16
2020
let res = ""
2121

@@ -32,5 +32,3 @@ function createBoundary(): string {
3232

3333
return res
3434
}
35-
36-
export default createBoundary

src/util/escapeName.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from "ava"
22

3-
import escapeName from "./escapeName.js"
3+
import {escapeName} from "./escapeName.js"
44

55
const CR = "%0D"
66
const LF = "%0A"

src/util/escapeName.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
*
88
* @api private
99
*/
10-
const escapeName = (name: unknown) => String(name)
10+
export const escapeName = (name: unknown) => String(name)
1111
.replace(/\r/g, "%0D") // CR
1212
.replace(/\n/g, "%0A") // LF
1313
.replace(/"/g, "%22")
14-
15-
export default escapeName

src/util/isFile.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import test from "ava"
22

33
import {File, Blob} from "formdata-node"
44

5-
import {FileLike} from "../FileLike.js"
6-
5+
import type {FileLike} from "../FileLike.js"
76
import {isFile} from "./isFile.js"
87

98
test("Returns true for a File", t => {

src/util/isFile.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import isFunction from "./isFunction.js"
2-
3-
import {FileLike} from "../FileLike.js"
1+
import type {FileLike} from "../FileLike.js"
2+
import {isFunction} from "./isFunction.js"
43

54
/**
65
* Check if given object is `File`.

src/util/isFormData.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import test from "ava"
33
import {FormData} from "formdata-node"
44

55
import {isFormData} from "./isFormData.js"
6-
7-
import {FormDataLike, FormDataEntryValue} from "../FormDataLike.js"
6+
import type {FormDataLike, FormDataEntryValue} from "../FormDataLike.js"
87

98
test("Returns true for spec-compatible FormData instance", t => {
109
t.true(isFormData(new FormData()))

src/util/isFormData.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import isFunction from "./isFunction.js"
2-
3-
import {FormDataLike} from "../FormDataLike.js"
1+
import type {FormDataLike} from "../FormDataLike.js"
2+
import {isFunction} from "./isFunction.js"
43

54
/**
65
* Check if given object is FormData

src/util/isFunction.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*
44
* @api private
55
*/
6-
const isFunction = (value: unknown): value is Function => (
6+
export const isFunction = (value: unknown): value is Function => (
77
typeof value === "function"
88
)
9-
10-
export default isFunction

0 commit comments

Comments
 (0)