MCPcopy Index your code
hub / github.com/deployd/deployd / decode

Function decode

test-app/public/mocha.js:11852–11922  ·  view source on GitHub ↗
(html, options)

Source from the content-addressed store, hash-verified

11850 };
11851
11852 var decode = function(html, options) {
11853 options = merge(options, decode.options);
11854 var strict = options.strict;
11855 if (strict && regexInvalidEntity.test(html)) {
11856 parseError('malformed character reference');
11857 }
11858 return html.replace(regexDecode, function($0, $1, $2, $3, $4, $5, $6, $7) {
11859 var codePoint;
11860 var semicolon;
11861 var decDigits;
11862 var hexDigits;
11863 var reference;
11864 var next;
11865 if ($1) {
11866 // Decode decimal escapes, e.g. `𝌆`.
11867 decDigits = $1;
11868 semicolon = $2;
11869 if (strict && !semicolon) {
11870 parseError('character reference was not terminated by a semicolon');
11871 }
11872 codePoint = parseInt(decDigits, 10);
11873 return codePointToSymbol(codePoint, strict);
11874 }
11875 if ($3) {
11876 // Decode hexadecimal escapes, e.g. `𝌆`.
11877 hexDigits = $3;
11878 semicolon = $4;
11879 if (strict && !semicolon) {
11880 parseError('character reference was not terminated by a semicolon');
11881 }
11882 codePoint = parseInt(hexDigits, 16);
11883 return codePointToSymbol(codePoint, strict);
11884 }
11885 if ($5) {
11886 // Decode named character references with trailing `;`, e.g. `©`.
11887 reference = $5;
11888 if (has(decodeMap, reference)) {
11889 return decodeMap[reference];
11890 } else {
11891 // Ambiguous ampersand. https://mths.be/notes/ambiguous-ampersands
11892 if (strict) {
11893 parseError(
11894 'named character reference was not terminated by a semicolon'
11895 );
11896 }
11897 return $0;
11898 }
11899 }
11900 // If we’re still here, it’s a legacy reference for sure. No need for an
11901 // extra `if` check.
11902 // Decode named character references without trailing `;`, e.g. `&amp`
11903 // This is only a parse error if it gets converted to `&`, or if it is
11904 // followed by `=` in an attribute context.
11905 reference = $6;
11906 next = $7;
11907 if (next && options.isAttributeValue) {
11908 if (strict && next == '=') {
11909 parseError('`&` did not start a character reference');

Callers

nothing calls this directly

Calls 5

parseErrorFunction · 0.85
parseIntFunction · 0.85
codePointToSymbolFunction · 0.85
mergeFunction · 0.70
hasFunction · 0.70

Tested by

no test coverage detected