@tryghost/string 0.1.25 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * escapeHTML
3
+ *
4
+ * Escape a string to be used as text or an attribute in HTML
5
+ *
6
+ * @param {string} string - the string we want to escape
7
+ * @returns {string} The escaped string
8
+ */
9
+ module.exports = function (string) {
10
+ const htmlChars = {
11
+ '&': '&',
12
+ '"': '"',
13
+ '\'': ''',
14
+ '<': '&lt;',
15
+ '>': '&gt;'
16
+ };
17
+ return string.replace(/[&"'<>]/g, c => htmlChars[c]);
18
+ };
package/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  module.exports.stripInvisibleChars = require('./stripInvisibleChars');
2
2
  module.exports.slugify = require('./slugify');
3
+ module.exports.escapeHtml = require('./escapeHtml');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/string",
3
- "version": "0.1.25",
3
+ "version": "0.2.0",
4
4
  "repository": "https://github.com/TryGhost/SDK/tree/master/packages/string",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -19,7 +19,8 @@
19
19
  "access": "public"
20
20
  },
21
21
  "devDependencies": {
22
- "c8": "7.11.2",
22
+ "c8": "7.12.0",
23
+ "jsdom": "^20.0.0",
23
24
  "mocha": "10.0.0",
24
25
  "should": "13.2.3",
25
26
  "sinon": "14.0.0"
@@ -27,5 +28,5 @@
27
28
  "dependencies": {
28
29
  "unidecode": "^0.1.8"
29
30
  },
30
- "gitHead": "2f7fb1fef3f2464f000974c8e0e13e25eabd6f6d"
31
+ "gitHead": "3547712bea5948482aabe9cbe484561501885de9"
31
32
  }