dry-ux 1.39.0 → 1.41.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.
@@ -7,8 +7,9 @@ export declare const preventDefault: (handler?: (event: any) => void) => (event:
7
7
  * Imports a script and returns a promise that resolves when the script is loaded.
8
8
  * @param resourceUrl The url of the script to load.
9
9
  * @param singleton If true, the script will only be loaded once.
10
+ * @param placement "body" or "head" to specify where the script should be placed.
10
11
  */
11
- export declare const importScript: (resourceUrl: string, singleton?: boolean) => Promise<void>;
12
+ export declare const importScript: (resourceUrl: string, singleton?: boolean, placement?: "body" | "head") => Promise<void>;
12
13
  /**
13
14
  * Imports a stylesheet and adds it to the head.
14
15
  * @param resourceUrl The url of the stylesheet to load.
@@ -53,3 +54,4 @@ export declare class Deferred<T> {
53
54
  get resolve(): (result: T) => void;
54
55
  get reject(): (error: any) => void;
55
56
  }
57
+ export declare const tryParseJson: <T = any>(json: string, errorValue?: {}) => {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deferred = exports.getUrlParams = exports.insertUrlParams = exports.insertUrlParam = exports.toHashCode = exports.StorageUtils = exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
3
+ exports.tryParseJson = exports.Deferred = exports.getUrlParams = exports.insertUrlParams = exports.insertUrlParam = exports.toHashCode = exports.StorageUtils = exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
4
4
  const React = require("react");
5
5
  /**
6
6
  * Returns a function that will call the given handler and prevent the default event behavior.
@@ -15,15 +15,21 @@ exports.preventDefault = preventDefault;
15
15
  * Imports a script and returns a promise that resolves when the script is loaded.
16
16
  * @param resourceUrl The url of the script to load.
17
17
  * @param singleton If true, the script will only be loaded once.
18
+ * @param placement "body" or "head" to specify where the script should be placed.
18
19
  */
19
- const importScript = (resourceUrl, singleton = true) => new Promise(resolve => {
20
+ const importScript = (resourceUrl, singleton = true, placement = "body") => new Promise(resolve => {
20
21
  React.useEffect(() => {
21
22
  const script = document.createElement("script");
22
23
  if (!$(`script[src='${resourceUrl}']`).length) {
23
24
  script.src = resourceUrl;
24
25
  script.async = true;
25
26
  script.onload = () => resolve();
26
- document.body.appendChild(script);
27
+ if (placement === "head") {
28
+ document.head.appendChild(script);
29
+ }
30
+ else {
31
+ document.body.appendChild(script);
32
+ }
27
33
  }
28
34
  else {
29
35
  resolve();
@@ -169,3 +175,12 @@ class Deferred {
169
175
  }
170
176
  }
171
177
  exports.Deferred = Deferred;
178
+ const tryParseJson = (json, errorValue = {}) => {
179
+ try {
180
+ return JSON.parse(json);
181
+ }
182
+ catch (e) {
183
+ return errorValue;
184
+ }
185
+ };
186
+ exports.tryParseJson = tryParseJson;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.39.0",
3
+ "version": "1.41.0",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "scripts": {