@putkoff/abstract-utilities 0.1.170 → 0.1.172

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.
package/dist/esm/index.js CHANGED
@@ -1,6 +1,19 @@
1
1
  export { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
 
4
+ function getSafeDocument() {
5
+ return typeof document !== 'undefined' ? document : undefined;
6
+ }
7
+ function getDocumentProp(...keys) {
8
+ let obj = getSafeDocument();
9
+ for (const k of keys) {
10
+ if (obj == null || typeof obj !== 'object')
11
+ return undefined;
12
+ obj = obj[k];
13
+ }
14
+ return obj;
15
+ }
16
+
4
17
  /**
5
18
  * Returns `window` if running in a browser, otherwise `undefined`.
6
19
  */
@@ -36,6 +49,45 @@ function callStorage(method, ...args) {
36
49
  return undefined;
37
50
  }
38
51
  }
52
+ /**
53
+ * Safely call localStorage / sessionStorage / any Storage API.
54
+ *
55
+ * @param storageName "localStorage" or "sessionStorage"
56
+ * @param method one of the Storage methods, e.g. "getItem", "setItem", etc.
57
+ * @param args arguments to pass along (e.g. key, value)
58
+ * @returns whatever the underlying method returns, or undefined if unavailable/fails
59
+ */
60
+ function safeStorage(storageName, method, ...args) {
61
+ try {
62
+ const storage = globalThis[storageName];
63
+ if (!storage)
64
+ return undefined;
65
+ const fn = storage[method];
66
+ if (typeof fn !== "function")
67
+ return undefined;
68
+ // @ts-ignore
69
+ return fn.apply(storage, args);
70
+ }
71
+ catch (_a) {
72
+ return undefined;
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Safely walk `window` or `document` to grab nested props without blowing up in Node.
78
+ *
79
+ * @param rootName "window" or "document"
80
+ * @param path sequence of property names, e.g. ["location","host"] or ["baseURI"]
81
+ */
82
+ function safeGlobalProp(rootName, ...path) {
83
+ let obj = globalThis[rootName];
84
+ for (const key of path) {
85
+ if (obj == null)
86
+ return undefined;
87
+ obj = obj[key];
88
+ }
89
+ return obj;
90
+ }
39
91
 
40
92
  /**
41
93
  * Returns the global window object if it exists, otherwise undefined.
@@ -80,19 +132,6 @@ function getWindowHost() {
80
132
  return getWindowProp('location', 'host');
81
133
  }
82
134
 
83
- function getSafeDocument() {
84
- return typeof document !== 'undefined' ? document : undefined;
85
- }
86
- function getDocumentProp(...keys) {
87
- let obj = getSafeDocument();
88
- for (const k of keys) {
89
- if (obj == null || typeof obj !== 'object')
90
- return undefined;
91
- obj = obj[k];
92
- }
93
- return obj;
94
- }
95
-
96
135
  /**
97
136
  ***Changes**:
98
137
  *- Updated import path for `InputProps` to `../../types/interfaces`.
@@ -1304,6 +1343,7 @@ function stripHost(str) {
1304
1343
  function get_app_config_url(endpoint) {
1305
1344
  return __awaiter(this, void 0, void 0, function* () {
1306
1345
  // 1) normalize your input
1346
+ endpoint = endpoint || '';
1307
1347
  stripHost(endpoint.trim().toLowerCase());
1308
1348
  yield loadConfig();
1309
1349
  const base = yield fetchIt('https://abstractendeavors.com/api/secure_env', { "key": 'BASE_API_URL', 'path': '/var/www/abstractendeavors/secure-files/public/config.json' }, 'POST', null, false, true);
@@ -1471,5 +1511,5 @@ function readJsonFile(relativeOrAbsolutePath) {
1471
1511
  });
1472
1512
  }
1473
1513
 
1474
- export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, callStorage, callWindowMethod, checkResponse, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureAbstractUrl, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_app_config_url, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isTokenExpired, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
1514
+ export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, callStorage, callWindowMethod, checkResponse, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureAbstractUrl, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_app_config_url, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isTokenExpired, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, readFileContents, readJsonFile, requestPatch, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
1475
1515
  //# sourceMappingURL=index.js.map