-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
74 lines (63 loc) · 1.68 KB
/
shared.js
File metadata and controls
74 lines (63 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(function(root, factory) {
const api = factory();
if (typeof module !== 'undefined' && module.exports) {
module.exports = api;
}
root.DevFeedbackShared = api;
})(typeof globalThis !== 'undefined' ? globalThis : this, function() {
'use strict';
const SUPPORTED_HOSTNAMES = Object.freeze([
'localhost',
'127.0.0.1',
'0.0.0.0',
'::1'
]);
const SUPPORTED_MATCH_PATTERNS = Object.freeze([
'http://localhost/*',
'https://localhost/*',
'http://127.0.0.1/*',
'https://127.0.0.1/*',
'http://0.0.0.0/*',
'https://0.0.0.0/*',
'http://[::1]/*',
'https://[::1]/*'
]);
const SHORTCUT_LABEL = 'Ctrl+Shift+F';
const MAC_SHORTCUT_LABEL = 'Command+Shift+F';
const MAX_NOTE_LENGTH = 2000;
function normalizeHostname(hostname) {
return String(hostname || '').replace(/^\[|\]$/g, '').toLowerCase();
}
function isLocalDevUrl(rawUrl) {
try {
const url = new URL(rawUrl);
return (
(url.protocol === 'http:' || url.protocol === 'https:') &&
SUPPORTED_HOSTNAMES.includes(normalizeHostname(url.hostname))
);
} catch (error) {
return false;
}
}
function makeStorageKey(rawUrl) {
const url = new URL(rawUrl);
return `dev-feedback-${url.origin}`;
}
function escapeCssIdentifier(value) {
if (typeof CSS !== 'undefined' && typeof CSS.escape === 'function') {
return CSS.escape(value);
}
return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\$&');
}
return {
SUPPORTED_HOSTNAMES,
SUPPORTED_MATCH_PATTERNS,
SHORTCUT_LABEL,
MAC_SHORTCUT_LABEL,
MAX_NOTE_LENGTH,
escapeCssIdentifier,
isLocalDevUrl,
makeStorageKey,
normalizeHostname
};
});