(name?: string | Record<string, string | null | undefined>, value?: string | null)
| 177 | public attr(name: Record<string, string | null | undefined> | undefined): AstNode | undefined; |
| 178 | public attr(name: string): string | undefined; |
| 179 | public attr(name?: string | Record<string, string | null | undefined>, value?: string | null): string | AstNode | undefined { |
| 180 | const self = this; |
| 181 | |
| 182 | if (!Type.isString(name)) { |
| 183 | if (Type.isNonNullable(name)) { |
| 184 | Obj.each(name, (value, key) => { |
| 185 | self.attr(key, value); |
| 186 | }); |
| 187 | } |
| 188 | |
| 189 | return self; |
| 190 | } |
| 191 | |
| 192 | const attrs = self.attributes; |
| 193 | if (attrs) { |
| 194 | if (value !== undefined) { |
| 195 | // Remove attribute |
| 196 | if (value === null) { |
| 197 | if (name in attrs.map) { |
| 198 | delete attrs.map[name]; |
| 199 | |
| 200 | let i = attrs.length; |
| 201 | while (i--) { |
| 202 | if (attrs[i].name === name) { |
| 203 | attrs.splice(i, 1); |
| 204 | return self; |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return self; |
| 210 | } |
| 211 | |
| 212 | // Set attribute |
| 213 | if (name in attrs.map) { |
| 214 | // Set attribute |
| 215 | let i = attrs.length; |
| 216 | while (i--) { |
| 217 | if (attrs[i].name === name) { |
| 218 | attrs[i].value = value; |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | } else { |
| 223 | attrs.push({ name, value }); |
| 224 | } |
| 225 | |
| 226 | attrs.map[name] = value; |
| 227 | |
| 228 | return self; |
| 229 | } |
| 230 | |
| 231 | return attrs.map[name]; |
| 232 | } |
| 233 | |
| 234 | return undefined; |
| 235 | } |
| 236 |
no test coverage detected