blob: ccded1e65d2f10c35d615bd7410c0990215ea8ef [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = GetIntrinsic('%TypeError%');
6
7var callBound = require('call-bind/callBound');
8
9var $replace = callBound('String.prototype.replace');
10
11var RequireObjectCoercible = require('./RequireObjectCoercible');
12var ToString = require('./ToString');
13var Type = require('./Type');
14
15// https://ecma-international.org/ecma-262/6.0/#sec-createhtml
16
17module.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, '&quot;');
27 p1 += '\x20' + attribute + '\x3D\x22' + escapedV + '\x22';
28 }
29 return p1 + '>' + S + '</' + tag + '>';
30};