| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var GetIntrinsic = require('get-intrinsic'); |
| 4 | |
| 5 | var $TypeError = GetIntrinsic('%TypeError%'); |
| 6 | |
| 7 | var callBound = require('call-bind/callBound'); |
| 8 | |
| 9 | var $replace = callBound('String.prototype.replace'); |
| 10 | |
| 11 | var RequireObjectCoercible = require('./RequireObjectCoercible'); |
| 12 | var ToString = require('./ToString'); |
| 13 | var Type = require('./Type'); |
| 14 | |
| 15 | // https://ecma-international.org/ecma-262/6.0/#sec-createhtml |
| 16 | |
| 17 | module.exports = function CreateHTML(string, tag, attribute, value) { |
| 18 | if (Type(tag) !== 'String' || Type(attribute) !== 'String') { |
| 19 | throw new $TypeError('Assertion failed: `tag` and `attribute` must be strings'); |
| 20 | } |
| 21 | var str = RequireObjectCoercible(string); |
| 22 | var S = ToString(str); |
| 23 | var p1 = '<' + tag; |
| 24 | if (attribute !== '') { |
| 25 | var V = ToString(value); |
| 26 | var escapedV = $replace(V, /\x22/g, '"'); |
| 27 | p1 += '\x20' + attribute + '\x3D\x22' + escapedV + '\x22'; |
| 28 | } |
| 29 | return p1 + '>' + S + '</' + tag + '>'; |
| 30 | }; |