arnaucube
arnaucube/raspberryGPIOhtmlserverPublic Self-hosted repository
raspberryGPIOhtmlserver/node_modules/connect/node_modules/send/lib/utils.js
node_modules/connect/node_modules/send/lib/utils.jsRaw
 1
 2/**
 3 * Return an ETag in the form of `"<size>-<mtime>"`
 4 * from the given `stat`.
 5 *
 6 * @param {Object} stat
 7 * @return {String}
 8 * @api private
 9 */
10
11exports.etag = function(stat) {
12  return '"' + stat.size + '-' + Number(stat.mtime) + '"';
13};
14
15/**
16 * decodeURIComponent.
17 *
18 * Allows V8 to only deoptimize this fn instead of all
19 * of send().
20 *
21 * @param {String} path
22 * @api private
23 */
24
25exports.decode = function(path){
26  try {
27    return decodeURIComponent(path);
28  } catch (err) {
29    return -1;
30  }
31};
32
33/**
34 * Escape the given string of `html`.
35 *
36 * @param {String} html
37 * @return {String}
38 * @api private
39 */
40
41exports.escape = function(html){
42  return String(html)
43    .replace(/&(?!\w+;)/g, '&amp;')
44    .replace(/</g, '&lt;')
45    .replace(/>/g, '&gt;')
46    .replace(/"/g, '&quot;');
47};