@widget-js/core 0.1.6 → 0.1.12

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.
Files changed (75) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/api/ApiConstants.js +8 -8
  3. package/dist/cjs/api/AppApi.js +31 -31
  4. package/dist/cjs/api/BroadcastApi.js +20 -20
  5. package/dist/cjs/api/BrowserWindowApi.js +58 -24
  6. package/dist/cjs/api/Channel.js +12 -11
  7. package/dist/cjs/api/DialogApi.js +16 -0
  8. package/dist/cjs/api/ElectronApi.js +13 -13
  9. package/dist/cjs/api/NotificationApi.js +83 -83
  10. package/dist/cjs/api/WidgetApi.js +58 -49
  11. package/dist/cjs/index.js +36 -34
  12. package/dist/cjs/model/HostedMode.js +14 -0
  13. package/dist/cjs/model/Notification.js +15 -15
  14. package/dist/cjs/model/SocialInfo.js +10 -10
  15. package/dist/cjs/model/Widget.js +79 -79
  16. package/dist/cjs/model/WidgetData.js +16 -16
  17. package/dist/cjs/model/WidgetPackage.js +21 -6
  18. package/dist/cjs/model/WidgetParams.js +139 -144
  19. package/dist/cjs/model/event/BroadcastEvent.js +14 -14
  20. package/dist/cjs/model/event/WebSocketEvent.js +14 -14
  21. package/dist/cjs/model/interface/IHostedWidget.js +2 -0
  22. package/dist/cjs/repository/WidgetDataRepository.js +71 -71
  23. package/dist/cjs/router/encoding.js +144 -144
  24. package/dist/cjs/router/query.js +84 -84
  25. package/dist/cjs/utils/ElectronUtils.js +24 -24
  26. package/dist/esm/api/ApiConstants.js +4 -4
  27. package/dist/esm/api/AppApi.js +27 -27
  28. package/dist/esm/api/BroadcastApi.js +16 -16
  29. package/dist/esm/api/BrowserWindowApi.js +54 -20
  30. package/dist/esm/api/Channel.js +9 -8
  31. package/dist/esm/api/DialogApi.js +12 -0
  32. package/dist/esm/api/ElectronApi.js +9 -9
  33. package/dist/esm/api/NotificationApi.js +79 -79
  34. package/dist/esm/api/WidgetApi.js +54 -45
  35. package/dist/esm/index.js +20 -18
  36. package/dist/esm/model/HostedMode.js +11 -0
  37. package/dist/esm/model/Notification.js +11 -11
  38. package/dist/esm/model/SocialInfo.js +6 -6
  39. package/dist/esm/model/Widget.js +75 -75
  40. package/dist/esm/model/WidgetData.js +12 -12
  41. package/dist/esm/model/WidgetPackage.js +17 -2
  42. package/dist/esm/model/WidgetParams.js +135 -140
  43. package/dist/esm/model/event/BroadcastEvent.js +10 -10
  44. package/dist/esm/model/event/WebSocketEvent.js +10 -10
  45. package/dist/esm/model/interface/IHostedWidget.js +1 -0
  46. package/dist/esm/repository/WidgetDataRepository.js +64 -64
  47. package/dist/esm/router/encoding.js +135 -135
  48. package/dist/esm/router/query.js +79 -79
  49. package/dist/esm/utils/ElectronUtils.js +20 -20
  50. package/dist/types/api/ApiConstants.d.ts +4 -4
  51. package/dist/types/api/AppApi.d.ts +10 -10
  52. package/dist/types/api/BroadcastApi.d.ts +6 -6
  53. package/dist/types/api/BrowserWindowApi.d.ts +37 -10
  54. package/dist/types/api/Channel.d.ts +8 -7
  55. package/dist/types/api/DialogApi.d.ts +8 -0
  56. package/dist/types/api/ElectronApi.d.ts +4 -4
  57. package/dist/types/api/NotificationApi.d.ts +14 -14
  58. package/dist/types/api/WidgetApi.d.ts +30 -24
  59. package/dist/types/index.d.ts +20 -18
  60. package/dist/types/model/HostedMode.d.ts +10 -0
  61. package/dist/types/model/Notification.d.ts +16 -16
  62. package/dist/types/model/SocialInfo.d.ts +6 -6
  63. package/dist/types/model/Widget.d.ts +96 -85
  64. package/dist/types/model/WidgetData.d.ts +35 -35
  65. package/dist/types/model/WidgetPackage.d.ts +43 -41
  66. package/dist/types/model/WidgetParams.d.ts +60 -63
  67. package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
  68. package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
  69. package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
  70. package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
  71. package/dist/types/router/encoding.d.ts +62 -62
  72. package/dist/types/router/query.d.ts +53 -53
  73. package/dist/types/utils/ElectronUtils.d.ts +8 -8
  74. package/dist/umd/index.js +1 -1
  75. package/package.json +15 -16
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BroadcastEvent = void 0;
4
- class BroadcastEvent {
5
- constructor(type, from, payload) {
6
- this.type = type;
7
- this.from = from;
8
- this.payload = payload;
9
- }
10
- }
11
- exports.BroadcastEvent = BroadcastEvent;
12
- BroadcastEvent.TYPE_WIDGET_UPDATED = "broadcast::cn.widgetjs.core.widget_updated";
13
- BroadcastEvent.TYPE_APP_CONFIG_UPDATED = "broadcast::cn.widgetjs.core.app_config_updated";
14
- BroadcastEvent.TYPE_THEME_CHANGED = "broadcast::cn.widgetjs.core.theme_changed";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BroadcastEvent = void 0;
4
+ class BroadcastEvent {
5
+ constructor(type, from, payload) {
6
+ this.type = type;
7
+ this.from = from;
8
+ this.payload = payload;
9
+ }
10
+ }
11
+ exports.BroadcastEvent = BroadcastEvent;
12
+ BroadcastEvent.TYPE_WIDGET_UPDATED = "broadcast::cn.widgetjs.core.widget_updated";
13
+ BroadcastEvent.TYPE_APP_CONFIG_UPDATED = "broadcast::cn.widgetjs.core.app_config_updated";
14
+ BroadcastEvent.TYPE_THEME_CHANGED = "broadcast::cn.widgetjs.core.theme_changed";
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketEvent = exports.WebSocketEventType = void 0;
4
- var WebSocketEventType;
5
- (function (WebSocketEventType) {
6
- WebSocketEventType["RESISTER_WIDGETS"] = "ws::cn.widgetjs.core.resister_widgets";
7
- })(WebSocketEventType = exports.WebSocketEventType || (exports.WebSocketEventType = {}));
8
- class WebSocketEvent {
9
- constructor(type, payload) {
10
- this.type = type;
11
- this.payload = payload;
12
- }
13
- }
14
- exports.WebSocketEvent = WebSocketEvent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocketEvent = exports.WebSocketEventType = void 0;
4
+ var WebSocketEventType;
5
+ (function (WebSocketEventType) {
6
+ WebSocketEventType["RESISTER_WIDGETS"] = "ws::cn.widgetjs.core.resister_widgets";
7
+ })(WebSocketEventType = exports.WebSocketEventType || (exports.WebSocketEventType = {}));
8
+ class WebSocketEvent {
9
+ constructor(type, payload) {
10
+ this.type = type;
11
+ this.payload = payload;
12
+ }
13
+ }
14
+ exports.WebSocketEvent = WebSocketEvent;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,71 +1,71 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WidgetDataRepository = void 0;
7
- const localforage_1 = __importDefault(require("localforage"));
8
- const BroadcastEvent_1 = require("../model/event/BroadcastEvent");
9
- const BroadcastApi_1 = require("../api/BroadcastApi");
10
- class WidgetDataRepository {
11
- /**
12
- * 保存组件数据
13
- * @param data
14
- */
15
- static async save(data) {
16
- let store = this.getStore(data.name);
17
- const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
18
- const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
19
- await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
20
- return result;
21
- }
22
- /**
23
- * 获取组件 LocalForage 存储实例
24
- * @param name
25
- */
26
- static getStore(name) {
27
- if (this.stores.has(name)) {
28
- return this.stores.get(name);
29
- }
30
- const store = localforage_1.default.createInstance({ name: name });
31
- this.stores.set(name, store);
32
- return store;
33
- }
34
- /**
35
- * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
36
- * @param data
37
- */
38
- static async saveByName(data) {
39
- const store = this.getStore(data.name);
40
- const json = JSON.stringify(data);
41
- const result = await store.setItem(data.name, json);
42
- const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
43
- await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
44
- return result;
45
- }
46
- static async findByName(name, type) {
47
- let store = this.getStore(name);
48
- let result = await store.getItem(name);
49
- if (result) {
50
- const widgetData = new type(name);
51
- widgetData.parseJSON(JSON.parse(result));
52
- return widgetData;
53
- }
54
- return undefined;
55
- }
56
- static async find(name, id, type) {
57
- let store = this.getStore(name);
58
- let result = await store.getItem(this.getKey(name, id));
59
- if (result) {
60
- const widgetData = new type(name, id);
61
- widgetData.parseJSON(JSON.parse(result));
62
- return widgetData;
63
- }
64
- return undefined;
65
- }
66
- static getKey(name, id) {
67
- return `${name}@${id}`;
68
- }
69
- }
70
- exports.WidgetDataRepository = WidgetDataRepository;
71
- WidgetDataRepository.stores = new Map();
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WidgetDataRepository = void 0;
7
+ const localforage_1 = __importDefault(require("localforage"));
8
+ const BroadcastEvent_1 = require("../model/event/BroadcastEvent");
9
+ const BroadcastApi_1 = require("../api/BroadcastApi");
10
+ class WidgetDataRepository {
11
+ /**
12
+ * 保存组件数据
13
+ * @param data
14
+ */
15
+ static async save(data) {
16
+ let store = this.getStore(data.name);
17
+ const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
18
+ const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
19
+ await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
20
+ return result;
21
+ }
22
+ /**
23
+ * 获取组件 LocalForage 存储实例
24
+ * @param name
25
+ */
26
+ static getStore(name) {
27
+ if (this.stores.has(name)) {
28
+ return this.stores.get(name);
29
+ }
30
+ const store = localforage_1.default.createInstance({ name: name });
31
+ this.stores.set(name, store);
32
+ return store;
33
+ }
34
+ /**
35
+ * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
36
+ * @param data
37
+ */
38
+ static async saveByName(data) {
39
+ const store = this.getStore(data.name);
40
+ const json = JSON.stringify(data);
41
+ const result = await store.setItem(data.name, json);
42
+ const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
43
+ await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
44
+ return result;
45
+ }
46
+ static async findByName(name, type) {
47
+ let store = this.getStore(name);
48
+ let result = await store.getItem(name);
49
+ if (result) {
50
+ const widgetData = new type(name);
51
+ widgetData.parseJSON(JSON.parse(result));
52
+ return widgetData;
53
+ }
54
+ return undefined;
55
+ }
56
+ static async find(name, id, type) {
57
+ let store = this.getStore(name);
58
+ let result = await store.getItem(this.getKey(name, id));
59
+ if (result) {
60
+ const widgetData = new type(name, id);
61
+ widgetData.parseJSON(JSON.parse(result));
62
+ return widgetData;
63
+ }
64
+ return undefined;
65
+ }
66
+ static getKey(name, id) {
67
+ return `${name}@${id}`;
68
+ }
69
+ }
70
+ exports.WidgetDataRepository = WidgetDataRepository;
71
+ WidgetDataRepository.stores = new Map();
@@ -1,144 +1,144 @@
1
- "use strict";
2
- /**
3
- * Encoding Rules ␣ = Space Path: ␣ " < > # ? { } Query: ␣ " < > # & = Hash: ␣ "
4
- * < > `
5
- *
6
- * On top of that, the RFC3986 (https://tools.ietf.org/html/rfc3986#section-2.2)
7
- * defines some extra characters to be encoded. Most browsers do not encode them
8
- * in encodeURI https://github.com/whatwg/url/issues/369, so it may be safer to
9
- * also encode `!'()*`. Leaving un-encoded only ASCII alphanumeric(`a-zA-Z0-9`)
10
- * plus `-._~`. This extra safety should be applied to query by patching the
11
- * string returned by encodeURIComponent encodeURI also encodes `[\]^`. `\`
12
- * should be encoded to avoid ambiguity. Browsers (IE, FF, C) transform a `\`
13
- * into a `/` if directly typed in. The _backtick_ (`````) should also be
14
- * encoded everywhere because some browsers like FF encode it when directly
15
- * written while others don't. Safari and IE don't encode ``"<>{}``` in hash.
16
- */
17
- // const EXTRA_RESERVED_RE = /[!'()*]/g
18
- // const encodeReservedReplacer = (c: string) => '%' + c.charCodeAt(0).toString(16)
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.decode = exports.encodeParam = exports.encodePath = exports.encodeQueryKey = exports.encodeQueryValue = exports.encodeHash = exports.PLUS_RE = void 0;
21
- const HASH_RE = /#/g; // %23
22
- const AMPERSAND_RE = /&/g; // %26
23
- const SLASH_RE = /\//g; // %2F
24
- const EQUAL_RE = /=/g; // %3D
25
- const IM_RE = /\?/g; // %3F
26
- exports.PLUS_RE = /\+/g; // %2B
27
- /**
28
- * NOTE: It's not clear to me if we should encode the + symbol in queries, it
29
- * seems to be less flexible than not doing so and I can't find out the legacy
30
- * systems requiring this for regular requests like text/html. In the standard,
31
- * the encoding of the plus character is only mentioned for
32
- * application/x-www-form-urlencoded
33
- * (https://url.spec.whatwg.org/#urlencoded-parsing) and most browsers seems lo
34
- * leave the plus character as is in queries. To be more flexible, we allow the
35
- * plus character on the query, but it can also be manually encoded by the user.
36
- *
37
- * Resources:
38
- * - https://url.spec.whatwg.org/#urlencoded-parsing
39
- * - https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20
40
- */
41
- const ENC_BRACKET_OPEN_RE = /%5B/g; // [
42
- const ENC_BRACKET_CLOSE_RE = /%5D/g; // ]
43
- const ENC_CARET_RE = /%5E/g; // ^
44
- const ENC_BACKTICK_RE = /%60/g; // `
45
- const ENC_CURLY_OPEN_RE = /%7B/g; // {
46
- const ENC_PIPE_RE = /%7C/g; // |
47
- const ENC_CURLY_CLOSE_RE = /%7D/g; // }
48
- const ENC_SPACE_RE = /%20/g; // }
49
- /**
50
- * Encode characters that need to be encoded on the path, search and hash
51
- * sections of the URL.
52
- *
53
- * @internal
54
- * @param text - string to encode
55
- * @returns encoded string
56
- */
57
- function commonEncode(text) {
58
- return encodeURI('' + text)
59
- .replace(ENC_PIPE_RE, '|')
60
- .replace(ENC_BRACKET_OPEN_RE, '[')
61
- .replace(ENC_BRACKET_CLOSE_RE, ']');
62
- }
63
- /**
64
- * Encode characters that need to be encoded on the hash section of the URL.
65
- *
66
- * @param text - string to encode
67
- * @returns encoded string
68
- */
69
- function encodeHash(text) {
70
- return commonEncode(text)
71
- .replace(ENC_CURLY_OPEN_RE, '{')
72
- .replace(ENC_CURLY_CLOSE_RE, '}')
73
- .replace(ENC_CARET_RE, '^');
74
- }
75
- exports.encodeHash = encodeHash;
76
- /**
77
- * Encode characters that need to be encoded query values on the query
78
- * section of the URL.
79
- *
80
- * @param text - string to encode
81
- * @returns encoded string
82
- */
83
- function encodeQueryValue(text) {
84
- return (commonEncode(text)
85
- // Encode the space as +, encode the + to differentiate it from the space
86
- .replace(exports.PLUS_RE, '%2B')
87
- .replace(ENC_SPACE_RE, '+')
88
- .replace(HASH_RE, '%23')
89
- .replace(AMPERSAND_RE, '%26')
90
- .replace(ENC_BACKTICK_RE, '`')
91
- .replace(ENC_CURLY_OPEN_RE, '{')
92
- .replace(ENC_CURLY_CLOSE_RE, '}')
93
- .replace(ENC_CARET_RE, '^'));
94
- }
95
- exports.encodeQueryValue = encodeQueryValue;
96
- /**
97
- * Like `encodeQueryValue` but also encodes the `=` character.
98
- *
99
- * @param text - string to encode
100
- */
101
- function encodeQueryKey(text) {
102
- return encodeQueryValue(text).replace(EQUAL_RE, '%3D');
103
- }
104
- exports.encodeQueryKey = encodeQueryKey;
105
- /**
106
- * Encode characters that need to be encoded on the path section of the URL.
107
- *
108
- * @param text - string to encode
109
- * @returns encoded string
110
- */
111
- function encodePath(text) {
112
- return commonEncode(text).replace(HASH_RE, '%23').replace(IM_RE, '%3F');
113
- }
114
- exports.encodePath = encodePath;
115
- /**
116
- * Encode characters that need to be encoded on the path section of the URL as a
117
- * param. This function encodes everything {@link encodePath} does plus the
118
- * slash (`/`) character. If `text` is `null` or `undefined`, returns an empty
119
- * string instead.
120
- *
121
- * @param text - string to encode
122
- * @returns encoded string
123
- */
124
- function encodeParam(text) {
125
- return text == null ? '' : encodePath(text).replace(SLASH_RE, '%2F');
126
- }
127
- exports.encodeParam = encodeParam;
128
- /**
129
- * Decode text using `decodeURIComponent`. Returns the original text if it
130
- * fails.
131
- *
132
- * @param text - string to decode
133
- * @returns decoded string
134
- */
135
- function decode(text) {
136
- try {
137
- return decodeURIComponent('' + text);
138
- }
139
- catch (err) {
140
- // __DEV__ && warn(`Error decoding "${text}". Using original value`)
141
- }
142
- return '' + text;
143
- }
144
- exports.decode = decode;
1
+ "use strict";
2
+ /**
3
+ * Encoding Rules ␣ = Space Path: ␣ " < > # ? { } Query: ␣ " < > # & = Hash: ␣ "
4
+ * < > `
5
+ *
6
+ * On top of that, the RFC3986 (https://tools.ietf.org/html/rfc3986#section-2.2)
7
+ * defines some extra characters to be encoded. Most browsers do not encode them
8
+ * in encodeURI https://github.com/whatwg/url/issues/369, so it may be safer to
9
+ * also encode `!'()*`. Leaving un-encoded only ASCII alphanumeric(`a-zA-Z0-9`)
10
+ * plus `-._~`. This extra safety should be applied to query by patching the
11
+ * string returned by encodeURIComponent encodeURI also encodes `[\]^`. `\`
12
+ * should be encoded to avoid ambiguity. Browsers (IE, FF, C) transform a `\`
13
+ * into a `/` if directly typed in. The _backtick_ (`````) should also be
14
+ * encoded everywhere because some browsers like FF encode it when directly
15
+ * written while others don't. Safari and IE don't encode ``"<>{}``` in hash.
16
+ */
17
+ // const EXTRA_RESERVED_RE = /[!'()*]/g
18
+ // const encodeReservedReplacer = (c: string) => '%' + c.charCodeAt(0).toString(16)
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.decode = exports.encodeParam = exports.encodePath = exports.encodeQueryKey = exports.encodeQueryValue = exports.encodeHash = exports.PLUS_RE = void 0;
21
+ const HASH_RE = /#/g; // %23
22
+ const AMPERSAND_RE = /&/g; // %26
23
+ const SLASH_RE = /\//g; // %2F
24
+ const EQUAL_RE = /=/g; // %3D
25
+ const IM_RE = /\?/g; // %3F
26
+ exports.PLUS_RE = /\+/g; // %2B
27
+ /**
28
+ * NOTE: It's not clear to me if we should encode the + symbol in queries, it
29
+ * seems to be less flexible than not doing so and I can't find out the legacy
30
+ * systems requiring this for regular requests like text/html. In the standard,
31
+ * the encoding of the plus character is only mentioned for
32
+ * application/x-www-form-urlencoded
33
+ * (https://url.spec.whatwg.org/#urlencoded-parsing) and most browsers seems lo
34
+ * leave the plus character as is in queries. To be more flexible, we allow the
35
+ * plus character on the query, but it can also be manually encoded by the user.
36
+ *
37
+ * Resources:
38
+ * - https://url.spec.whatwg.org/#urlencoded-parsing
39
+ * - https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20
40
+ */
41
+ const ENC_BRACKET_OPEN_RE = /%5B/g; // [
42
+ const ENC_BRACKET_CLOSE_RE = /%5D/g; // ]
43
+ const ENC_CARET_RE = /%5E/g; // ^
44
+ const ENC_BACKTICK_RE = /%60/g; // `
45
+ const ENC_CURLY_OPEN_RE = /%7B/g; // {
46
+ const ENC_PIPE_RE = /%7C/g; // |
47
+ const ENC_CURLY_CLOSE_RE = /%7D/g; // }
48
+ const ENC_SPACE_RE = /%20/g; // }
49
+ /**
50
+ * Encode characters that need to be encoded on the path, search and hash
51
+ * sections of the URL.
52
+ *
53
+ * @internal
54
+ * @param text - string to encode
55
+ * @returns encoded string
56
+ */
57
+ function commonEncode(text) {
58
+ return encodeURI('' + text)
59
+ .replace(ENC_PIPE_RE, '|')
60
+ .replace(ENC_BRACKET_OPEN_RE, '[')
61
+ .replace(ENC_BRACKET_CLOSE_RE, ']');
62
+ }
63
+ /**
64
+ * Encode characters that need to be encoded on the hash section of the URL.
65
+ *
66
+ * @param text - string to encode
67
+ * @returns encoded string
68
+ */
69
+ function encodeHash(text) {
70
+ return commonEncode(text)
71
+ .replace(ENC_CURLY_OPEN_RE, '{')
72
+ .replace(ENC_CURLY_CLOSE_RE, '}')
73
+ .replace(ENC_CARET_RE, '^');
74
+ }
75
+ exports.encodeHash = encodeHash;
76
+ /**
77
+ * Encode characters that need to be encoded query values on the query
78
+ * section of the URL.
79
+ *
80
+ * @param text - string to encode
81
+ * @returns encoded string
82
+ */
83
+ function encodeQueryValue(text) {
84
+ return (commonEncode(text)
85
+ // Encode the space as +, encode the + to differentiate it from the space
86
+ .replace(exports.PLUS_RE, '%2B')
87
+ .replace(ENC_SPACE_RE, '+')
88
+ .replace(HASH_RE, '%23')
89
+ .replace(AMPERSAND_RE, '%26')
90
+ .replace(ENC_BACKTICK_RE, '`')
91
+ .replace(ENC_CURLY_OPEN_RE, '{')
92
+ .replace(ENC_CURLY_CLOSE_RE, '}')
93
+ .replace(ENC_CARET_RE, '^'));
94
+ }
95
+ exports.encodeQueryValue = encodeQueryValue;
96
+ /**
97
+ * Like `encodeQueryValue` but also encodes the `=` character.
98
+ *
99
+ * @param text - string to encode
100
+ */
101
+ function encodeQueryKey(text) {
102
+ return encodeQueryValue(text).replace(EQUAL_RE, '%3D');
103
+ }
104
+ exports.encodeQueryKey = encodeQueryKey;
105
+ /**
106
+ * Encode characters that need to be encoded on the path section of the URL.
107
+ *
108
+ * @param text - string to encode
109
+ * @returns encoded string
110
+ */
111
+ function encodePath(text) {
112
+ return commonEncode(text).replace(HASH_RE, '%23').replace(IM_RE, '%3F');
113
+ }
114
+ exports.encodePath = encodePath;
115
+ /**
116
+ * Encode characters that need to be encoded on the path section of the URL as a
117
+ * param. This function encodes everything {@link encodePath} does plus the
118
+ * slash (`/`) character. If `text` is `null` or `undefined`, returns an empty
119
+ * string instead.
120
+ *
121
+ * @param text - string to encode
122
+ * @returns encoded string
123
+ */
124
+ function encodeParam(text) {
125
+ return text == null ? '' : encodePath(text).replace(SLASH_RE, '%2F');
126
+ }
127
+ exports.encodeParam = encodeParam;
128
+ /**
129
+ * Decode text using `decodeURIComponent`. Returns the original text if it
130
+ * fails.
131
+ *
132
+ * @param text - string to decode
133
+ * @returns decoded string
134
+ */
135
+ function decode(text) {
136
+ try {
137
+ return decodeURIComponent('' + text);
138
+ }
139
+ catch (err) {
140
+ // __DEV__ && warn(`Error decoding "${text}". Using original value`)
141
+ }
142
+ return '' + text;
143
+ }
144
+ exports.decode = decode;