* Creates a node of a specific type. * * @static * @method create * @param {String} name Name of the node type to create for example "b" or "#text". * @param {Object} attrs Name/value collection of attributes that will be applied to elements.
(name: string, attrs?: Record<string, string>)
| 97 | * @param {Object} attrs Name/value collection of attributes that will be applied to elements. |
| 98 | */ |
| 99 | public static create(name: string, attrs?: Record<string, string>): AstNode { |
| 100 | // Create node |
| 101 | const node = new AstNode(name, typeLookup[name] || 1); |
| 102 | |
| 103 | // Add attributes if needed |
| 104 | if (attrs) { |
| 105 | Obj.each(attrs, (value, attrName) => { |
| 106 | node.attr(attrName, value); |
| 107 | }); |
| 108 | } |
| 109 | |
| 110 | return node; |
| 111 | } |
| 112 | |
| 113 | public name: string; |
| 114 | public type: number; |