(element, trim)
| 127 | * value(s), or null if it had none. |
| 128 | */ |
| 129 | export function getValue(element, trim) { |
| 130 | let value = null |
| 131 | let {type} = element |
| 132 | |
| 133 | if (type === 'select-one') { |
| 134 | if (element.options.length) { |
| 135 | value = element.options[element.selectedIndex].value |
| 136 | } |
| 137 | return value |
| 138 | } |
| 139 | |
| 140 | if (type === 'select-multiple') { |
| 141 | value = [] |
| 142 | for (let i = 0, l = element.options.length; i < l; i++) { |
| 143 | if (element.options[i].selected) { |
| 144 | value.push(element.options[i].value) |
| 145 | } |
| 146 | } |
| 147 | if (value.length === 0) { |
| 148 | value = null |
| 149 | } |
| 150 | return value |
| 151 | } |
| 152 | |
| 153 | // If a file input doesn't have a files attribute, fall through to using its |
| 154 | // value attribute. |
| 155 | if (type === 'file' && 'files' in element) { |
| 156 | if (element.multiple) { |
| 157 | value = slice.call(element.files) |
| 158 | if (value.length === 0) { |
| 159 | value = null |
| 160 | } |
| 161 | } else { |
| 162 | // Should be null if not present, according to the spec |
| 163 | value = element.files[0] |
| 164 | } |
| 165 | return value |
| 166 | } |
| 167 | |
| 168 | if (!CHECKED_INPUT_TYPES[type]) { |
| 169 | value = (trim ? element.value.replace(TRIM_RE, '') : element.value) |
| 170 | } else if (element.checked) { |
| 171 | value = element.value |
| 172 | } |
| 173 | |
| 174 | return value |
| 175 | } |
no outgoing calls
no test coverage detected