Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | 1x 1x 1x 110x 27x 83x 1x 110x 110x 110x 110x 110x 198x 9x 189x 4x 185x 185x 185x 185x 6x 6x 6x 47x 6x 6x 41x 13x 47x 40x 10x 30x 15x 40x 25x 25x 15x 13x 2x 11x 11x 11x 11x 42x 42x 42x 21x 21x 17x 4x 11x 3x 11x 147x 20x 127x 110x 48x 9x 3x 110x 104x 104x 63x 63x 41x 41x 3x 2x 3x 38x 104x 63x 63x 63x 63x 63x 61x 63x 105x 63x 229x 63x 63x 166x 166x 166x 35x 35x 34x 1x 1x 35x 131x 61x 70x 70x 70x 63x 63x 7x 7x 131x 49x 46x 46x 46x 49x 1x | // get successful control from form and assemble into object // http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2 // types which indicate a submit action and are not successful controls // these will be ignored const k_r_submitter = /^(?:submit|button|image|reset|file)$/i; // node names which could be successful controls const k_r_success_contrls = /^(?:input|select|textarea|keygen)/i; // Matches bracket notation. const brackets = /(\[[^\[\]]*\])/g; // serializes form fields // @param form MUST be an HTMLForm element // @param options is an optional argument to configure the serialization. Default output // with no options specified is a url encoded string // - hash: [true | false] Configure the output type. If true, the output will // be a js object. // - serializer: [function] Optional serializer function to override the default one. // The function takes 3 arguments (result, key, value) and should return new result // hash and url encoded str serializers are provided with this module // - disabled: [true | false]. If true serialize disabled fields. // - empty: [true | false]. If true serialize empty fields function serialize(form, options) { if (typeof options != 'object') { options = { hash: !!options }; } else if (options.hash === undefined) { options.hash = true; } let result = (options.hash) ? {} : ''; const serializer = options.serializer || ((options.hash) ? hash_serializer : str_serialize); const elements = form && form.elements ? form.elements : []; //Object store each radio and set if it's empty or not const radio_store = Object.create(null); for (let element of elements) { // ingore disabled fields if ((!options.disabled && element.disabled) || !element.name) { continue; } // ignore anyhting that is not considered a success field if (!k_r_success_contrls.test(element.nodeName) || k_r_submitter.test(element.type)) { continue; } const key = element.name; const type = element.type; let val = element.value; switch (type) { case 'number': Eif (val != undefined) val = Number(val); break; case 'checkbox': if (options.booleans) { Iif (element.indeterminate) val=undefined; else val = element.checked; } else { if (!element.checked) { val = ''; } } break; case 'radio': { if (!radio_store[key] && !element.checked) { radio_store[key] = false; } else if (element.checked) { radio_store[key] = true; } if (!element.checked) { val = undefined; continue; } break; } case 'select-multiple': { if (!(options.empty || options.booleans) && !val) { continue; } val = []; const selectOptions = element.options; let isSelectedOptions = false; for (let option of selectOptions) { const allowedEmpty = (options.empty || options.booleans) && !option.value; const hasValue = (option.value || allowedEmpty); if (option.selected && hasValue) { isSelectedOptions = true; // If using a hash serializer be sure to add the // correct notation for an array in the multi-select // context. Here the name attribute on the select element // might be missing the trailing bracket pair. Both names // "foo" and "foo[]" should be arrays. if (options.hash && key.slice(key.length - 2) !== '[]') { result = serializer(result, key + '[]', option.value); } else { result = serializer(result, key, option.value); } } } // Serialize if no selected options and options.empty is true if (!isSelectedOptions && (options.empty || options.booleans)) { result = serializer(result, key, ''); } continue; } } if (!(options.empty || options.booleans) && !val) { continue; } result = serializer(result, key, val); } // Check for all empty radio buttons and serialize them with key="" if (options.empty || options.booleans) { for (let key in radio_store) { if (!radio_store[key]) { result = serializer(result, key, ''); } } } return result; // Object/hash encoding serializer. function hash_serializer(result, key, value) { const matches = key.match(brackets); // Has brackets? Use the recursive assignment function to walk the keys, // construct any missing objects in the result tree and make the assignment // at the end of the chain. if (matches) { const keys = parse_keys(key); hash_assign(result, keys, value); } else { // Non bracket notation can make assignments directly. const existing = result[key]; // If the value has been assigned already (for instance when a radio and // a checkbox have the same name attribute) convert the previous value // into an array before pushing into it. // // NOTE: If this requirement were removed all hash creation and // assignment could go through `hash_assign`. if (existing) { if (!Array.isArray(existing)) { result[key] = [existing]; } result[key].push(value); } else { result[key] = value; } } return result; function parse_keys(string) { const keys = []; const prefix = /^([^\[\]]*)/; const children = new RegExp(brackets); let match = prefix.exec(string); if (match[1]) { keys.push(match[1]); } while ((match = children.exec(string)) !== null) { keys.push(match[1]); } return keys; } function hash_assign(result, keys, value) { if (keys.length === 0) { result = value; return result; } const key = keys.shift(); const between = key.match(/^\[(.+?)\]$/); if (key === '[]') { result = result || []; if (Array.isArray(result)) { result.push(hash_assign(null, keys, value)); } else { // This might be the result of bad name attributes like "[][foo]", // in this case the original `result` object will already be // assigned to an object literal. Rather than coerce the object to // an array, or cause an exception the attribute "_values" is // assigned as an array. result._values = result._values || []; result._values.push(hash_assign(null, keys, value)); } return result; } // Key is an attribute name and can be assigned directly. if (!between) { result[key] = hash_assign(result[key], keys, value); } else { const string = between[1]; // +var converts the variable into a number // better than parseInt because it doesn't truncate away trailing // letters and actually fails if whole thing is not a number const index = +string; // If the characters between the brackets is not a number it is an // attribute name and can be assigned directly. if (isNaN(index)) { result = result || {}; result[string] = hash_assign(result[string], keys, value); } else { result = result || []; result[index] = hash_assign(result[index], keys, value); } } return result; } } // urlform encoding serializer function str_serialize(result, key, value) { if (typeof value === 'string') { value = value.replace(/(\r)?\n/g, '\r\n'); value = encodeURIComponent(value); // spaces should be '+' rather than '%20'. value = value.replace(/%20/g, '+'); } return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + value; } } module.exports = serialize; |