forked from capricorn86/happy-dom
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
capricorn86#308@trivial: Improves interface for NamedNodeMap and adds…
… some more unit tests.
- Loading branch information
Showing
6 changed files
with
220 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,70 @@ | ||
import IAttr from '../nodes/attr/IAttr'; | ||
|
||
export type INamedNodeMapProps = { | ||
/** | ||
* NamedNodeMap. | ||
* | ||
* Reference: | ||
* https://developer.mozilla.org/en-US/docs/Web/API/NamedNodeMap. | ||
*/ | ||
export default interface INamedNodeMap extends Iterable<IAttr> { | ||
[index: number]: IAttr; | ||
[Symbol.toStringTag]: string; | ||
readonly length: number; | ||
|
||
/** | ||
* Returns attribute by index. | ||
* | ||
* @param index Index. | ||
*/ | ||
item: (index: number) => IAttr; | ||
|
||
/** | ||
* Returns attribute by name. | ||
* | ||
* @param qualifiedName Name. | ||
* @returns Attribute. | ||
*/ | ||
getNamedItem: (qualifiedName: string) => IAttr; | ||
|
||
/** | ||
* Returns attribute by name and namespace. | ||
* | ||
* @param namespace Namespace. | ||
* @param localName Local name of the attribute. | ||
* @returns Attribute. | ||
*/ | ||
getNamedItemNS: (namespace: string, localName: string) => IAttr; | ||
|
||
/** | ||
* Adds a new attribute node. | ||
* | ||
* @param attr Attribute. | ||
* @returns Replaced attribute. | ||
*/ | ||
setNamedItem: (attr: IAttr) => IAttr; | ||
|
||
/** | ||
* Adds a new namespaced attribute node. | ||
* | ||
* @param attr Attribute. | ||
* @returns Replaced attribute. | ||
*/ | ||
setNamedItemNS: (attr: IAttr) => IAttr; | ||
removeNamedItem: (qualifiedName: string) => IAttr; | ||
removeNamedItemNS: (namespace: string, localName: string) => IAttr; | ||
[Symbol.toStringTag]: string; | ||
} & Iterable<IAttr>; | ||
type INamedNodeMapProperties = keyof INamedNodeMapProps; | ||
|
||
type INamedNodeMap = INamedNodeMapProps & { | ||
[k in Exclude<string | number, INamedNodeMapProperties>]: IAttr; | ||
}; | ||
/** | ||
* Removes an attribute. | ||
* | ||
* @param qualifiedName Name of the attribute. | ||
* @returns Removed attribute. | ||
*/ | ||
removeNamedItem: (qualifiedName: string) => IAttr; | ||
|
||
/** | ||
* NamedNodeMap interface. | ||
*/ | ||
export default INamedNodeMap; | ||
/** | ||
* Removes a namespaced attribute. | ||
* | ||
* @param namespace Namespace. | ||
* @param localName Local name of the attribute. | ||
* @returns Removed attribute. | ||
*/ | ||
removeNamedItemNS: (namespace: string, localName: string) => IAttr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.