MCPcopy Create free account
hub / github.com/nodejs/node / set

Method set

deps/undici/src/lib/web/fetch/formdata.js:121–161  ·  view source on GitHub ↗
(name, value, filename = undefined)

Source from the content-addressed store, hash-verified

119 }
120
121 set (name, value, filename = undefined) {
122 webidl.brandCheck(this, FormData)
123
124 const prefix = 'FormData.set'
125 webidl.argumentLengthCheck(arguments, 2, prefix)
126
127 name = webidl.converters.USVString(name)
128
129 if (arguments.length === 3 || webidl.is.Blob(value)) {
130 value = webidl.converters.Blob(value, prefix, 'value')
131
132 if (filename !== undefined) {
133 filename = webidl.converters.USVString(filename)
134 }
135 } else {
136 value = webidl.converters.USVString(value)
137 }
138
139 // The set(name, value) and set(name, blobValue, filename) method steps
140 // are:
141
142 // 1. Let value be value if given; otherwise blobValue.
143
144 // 2. Let entry be the result of creating an entry with name, value, and
145 // filename if given.
146 const entry = makeEntry(name, value, filename)
147
148 // 3. If there are entries in this’s entry list whose name is name, then
149 // replace the first such entry with entry and remove the others.
150 const idx = this.#state.findIndex((entry) => entry.name === name)
151 if (idx !== -1) {
152 this.#state = [
153 ...this.#state.slice(0, idx),
154 entry,
155 ...this.#state.slice(idx + 1).filter((entry) => entry.name !== name)
156 ]
157 } else {
158 // 4. Otherwise, append entry to this’s entry list.
159 this.#state.push(entry)
160 }
161 }
162
163 [nodeUtil.inspect.custom] (depth, options) {
164 const state = this.#state.reduce((a, b) => {

Callers

nothing calls this directly

Calls 7

brandCheckMethod · 0.80
argumentLengthCheckMethod · 0.80
USVStringMethod · 0.80
makeEntryFunction · 0.70
sliceMethod · 0.65
filterMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected