web-manager 3.1.10 → 3.1.12

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -212,6 +212,8 @@ The Web Manager .utilities() API wraps some useful functions such as getting and
212
212
  ```html
213
213
  <script type="text/javascript">
214
214
  console.log('--- Exploring the .utilities() API ---');
215
+
216
+ // .get() and .set()
215
217
  Manager.ready(function() {
216
218
  var object = {
217
219
  key1: 'val1',
@@ -234,6 +236,12 @@ The Web Manager .utilities() API wraps some useful functions such as getting and
234
236
  console.log('Root object (final)', Manager.utilities().get(object)); // Get whole object a final time
235
237
 
236
238
  });
239
+
240
+ // .clipboardCopy()
241
+ Manager.utilities().clipboardCopy('I am copied to the clipboard!')
242
+
243
+ // .escapeHTML()
244
+ Manager.utilities().escapeHTML('<strong>This will will NOT render as bold!</strong>')
237
245
  </script>
238
246
  ```
239
247
 
package/lib/utilities.js CHANGED
@@ -1,12 +1,23 @@
1
1
  /*
2
2
  */
3
3
 
4
+ var htmlEscapeMap = {
5
+ '&': '&amp;',
6
+ '<': '&lt;',
7
+ '>': '&gt;',
8
+ '"': '&quot;',
9
+ "'": '&#39;',
10
+ '/': '&#x2F;',
11
+ '`': '&#x60;',
12
+ '=': '&#x3D;'
13
+ };
14
+
4
15
  function Utilities(utilObj) {
5
16
  this.utilities = utilObj;
6
17
  }
7
18
 
8
19
  /* https://gist.github.com/jeneg/9767afdcca45601ea44930ea03e0febf */
9
- Utilities.get = function(obj, path, def) {
20
+ Utilities.get = function (obj, path, def) {
10
21
  var fullPath = (path || '')
11
22
  .replace(/\[/g, '.')
12
23
  .replace(/]/g, '')
@@ -25,7 +36,7 @@ Utilities.get = function(obj, path, def) {
25
36
  }
26
37
 
27
38
  /* https://stackoverflow.com/questions/54733539/javascript-implementation-of-lodash-set-method */
28
- Utilities.set = function(obj, path, value) {
39
+ Utilities.set = function (obj, path, value) {
29
40
  if (Object(obj) !== obj) {
30
41
  return obj;
31
42
  }; // When obj is not an object
@@ -48,7 +59,7 @@ Utilities.set = function(obj, path, value) {
48
59
 
49
60
  // https://dzone.com/articles/cross-browser-javascript-copy-and-paste
50
61
  // https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
51
- Utilities.clipboardCopy = function(input) {
62
+ Utilities.clipboardCopy = function (input) {
52
63
  var el = document.createElement('textarea');
53
64
  el.setAttribute('style','width:1px;border:0;opacity:0;');
54
65
  el.value = input && input.nodeType ? input.value || input.innerText || input.innerHTML : input;
@@ -62,4 +73,11 @@ Utilities.clipboardCopy = function(input) {
62
73
  document.body.removeChild(el);
63
74
  }
64
75
 
76
+ // Escape HTML
77
+ Utilities.escapeHTML = function (string) {
78
+ return (string || '').replace(/[&<>"'`=\/]/g, function (s) {
79
+ return htmlEscapeMap[s];
80
+ });
81
+ }
82
+
65
83
  module.exports = Utilities;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.10",
3
+ "version": "3.1.12",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,4 +28,4 @@
28
28
  "firebase": "^8.10.1",
29
29
  "lazysizes": "^5.3.2"
30
30
  }
31
- }
31
+ }