]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/iot-gateway/node_modules/escape-html/index.js
Updated to use the latest TI 15.4-Stack v2.1.0 from the SimpleLink CC13x0 SDK v1.30.
[apps/tidep0084.git] / example / iot-gateway / node_modules / escape-html / index.js
1 /*!
2  * escape-html
3  * Copyright(c) 2012-2013 TJ Holowaychuk
4  * Copyright(c) 2015 Andreas Lubbe
5  * Copyright(c) 2015 Tiancheng "Timothy" Gu
6  * MIT Licensed
7  */
9 'use strict';
11 /**
12  * Module variables.
13  * @private
14  */
16 var matchHtmlRegExp = /["'&<>]/;
18 /**
19  * Module exports.
20  * @public
21  */
23 module.exports = escapeHtml;
25 /**
26  * Escape special characters in the given string of html.
27  *
28  * @param  {string} string The string to escape for inserting into HTML
29  * @return {string}
30  * @public
31  */
33 function escapeHtml(string) {
34   var str = '' + string;
35   var match = matchHtmlRegExp.exec(str);
37   if (!match) {
38     return str;
39   }
41   var escape;
42   var html = '';
43   var index = 0;
44   var lastIndex = 0;
46   for (index = match.index; index < str.length; index++) {
47     switch (str.charCodeAt(index)) {
48       case 34: // "
49         escape = '&quot;';
50         break;
51       case 38: // &
52         escape = '&amp;';
53         break;
54       case 39: // '
55         escape = '&#39;';
56         break;
57       case 60: // <
58         escape = '&lt;';
59         break;
60       case 62: // >
61         escape = '&gt;';
62         break;
63       default:
64         continue;
65     }
67     if (lastIndex !== index) {
68       html += str.substring(lastIndex, index);
69     }
71     lastIndex = index + 1;
72     html += escape;
73   }
75   return lastIndex !== index
76     ? html + str.substring(lastIndex, index)
77     : html;
78 }