@putkoff/abstract-utilities 0.1.123 → 0.1.125

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 (70) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +1 -1
  4. package/dist/esm/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/dist/functions/auth_utils/imports.js +0 -1
  7. package/dist/functions/auth_utils/index.js +0 -1
  8. package/dist/functions/auth_utils/src/index.js +0 -1
  9. package/dist/functions/auth_utils/src/token_utils.js +0 -95
  10. package/dist/functions/config_utils/imports.js +0 -1
  11. package/dist/functions/config_utils/index.js +0 -1
  12. package/dist/functions/config_utils/src/config_utils.js +0 -33
  13. package/dist/functions/config_utils/src/index.js +0 -1
  14. package/dist/functions/constants_utils/index.js +0 -1
  15. package/dist/functions/constants_utils/src/constants.js +0 -7
  16. package/dist/functions/constants_utils/src/index.js +0 -1
  17. package/dist/functions/env_utils/imports.js +0 -1
  18. package/dist/functions/env_utils/index.js +0 -1
  19. package/dist/functions/env_utils/src/index.js +0 -1
  20. package/dist/functions/env_utils/src/window_utils.js +0 -47
  21. package/dist/functions/fetch_utils/imports.js +0 -7
  22. package/dist/functions/fetch_utils/index.js +0 -1
  23. package/dist/functions/fetch_utils/src/fetchIt_utils.js +0 -116
  24. package/dist/functions/fetch_utils/src/index.js +0 -1
  25. package/dist/functions/fetch_utils/src/utils.js +0 -171
  26. package/dist/functions/index.js +0 -12
  27. package/dist/functions/path_utils/imports.js +0 -26
  28. package/dist/functions/path_utils/index.js +0 -1
  29. package/dist/functions/path_utils/src/base_dirs.js +0 -17
  30. package/dist/functions/path_utils/src/function_dirs.js +0 -42
  31. package/dist/functions/path_utils/src/index.js +0 -6
  32. package/dist/functions/path_utils/src/misc_dirs.js +0 -15
  33. package/dist/functions/path_utils/src/path_utils.js +0 -75
  34. package/dist/functions/path_utils/src/paths.js +0 -12
  35. package/dist/functions/path_utils/src/src_dirs.js +0 -25
  36. package/dist/functions/read_utils/imports.js +0 -1
  37. package/dist/functions/read_utils/index.js +0 -1
  38. package/dist/functions/read_utils/src/index.js +0 -1
  39. package/dist/functions/read_utils/src/read_utils.js +0 -55
  40. package/dist/functions/rndm_utils/imports.js +0 -1
  41. package/dist/functions/rndm_utils/index.js +0 -1
  42. package/dist/functions/rndm_utils/src/index.js +0 -1
  43. package/dist/functions/rndm_utils/src/utils.js +0 -12
  44. package/dist/functions/string_utils/index.js +0 -1
  45. package/dist/functions/string_utils/src/index.js +0 -1
  46. package/dist/functions/string_utils/src/string_utils.js +0 -113
  47. package/dist/functions/type_utils/imports.js +0 -1
  48. package/dist/functions/type_utils/index.js +0 -1
  49. package/dist/functions/type_utils/src/index.js +0 -1
  50. package/dist/functions/type_utils/src/type_utils.js +0 -4
  51. package/dist/functions/ui_utils/imports.js +0 -5
  52. package/dist/functions/ui_utils/index.js +0 -1
  53. package/dist/functions/ui_utils/src/button.js +0 -32
  54. package/dist/functions/ui_utils/src/checkbox.js +0 -16
  55. package/dist/functions/ui_utils/src/index.js +0 -4
  56. package/dist/functions/ui_utils/src/input.js +0 -16
  57. package/dist/functions/ui_utils/src/spinner.js +0 -4
  58. package/dist/index.js +0 -5
  59. package/dist/types/index.js +0 -1
  60. package/dist/types/src/ChangePassword.js +0 -1
  61. package/dist/types/src/Files.js +0 -1
  62. package/dist/types/src/index.js +0 -5
  63. package/dist/types/src/login.js +0 -1
  64. package/dist/types/src/logout.js +0 -1
  65. package/dist/types/src/utils.js +0 -1
  66. package/dist/utils/imports.js +0 -1
  67. package/dist/utils/index.js +0 -1
  68. package/dist/utils/src/Input.js +0 -2
  69. package/dist/utils/src/config.js +0 -20
  70. package/dist/utils/src/index.js +0 -2
@@ -1,75 +0,0 @@
1
- import * as path from 'path-browserify';
2
- import { eatOuter, eatInner, ensure_list } from './../imports';
3
- export function get_dirname(filePath) {
4
- if (!filePath)
5
- return '';
6
- return path.dirname(filePath);
7
- }
8
- export function get_basename(filePath) {
9
- if (!filePath)
10
- return '';
11
- return path.basename(filePath);
12
- }
13
- export function get_filename(file_path) {
14
- const ext = path.extname(file_path);
15
- return path.basename(file_path, ext);
16
- }
17
- export function get_extname(filePath) {
18
- if (!filePath)
19
- return '';
20
- return path.extname(filePath);
21
- }
22
- export function get_splitext(filePath) {
23
- if (!filePath)
24
- return { filename: '', extname: '' };
25
- const ext = path.extname(filePath);
26
- // Get the basename without the extension
27
- const filename = path.basename(filePath, ext);
28
- return { filename, ext };
29
- }
30
- export function make_path(...segments) {
31
- const list = ensure_list(segments);
32
- let real_path = '';
33
- for (let i = 0; i < list.length; i++) {
34
- let segment = list[i]; // renamed, no shadowing
35
- if (i === 0) {
36
- real_path = segment;
37
- }
38
- else {
39
- segment = eatInner(segment, ['/']);
40
- real_path = eatOuter(real_path, ['/']);
41
- real_path = `${real_path}/${segment}`;
42
- }
43
- }
44
- return real_path || '';
45
- }
46
- export function sanitizeFilename(filename) {
47
- return filename
48
- .toLowerCase()
49
- .replace(/\s+|-/g, '-') // Replace spaces and hyphens with single hyphen
50
- .replace(/_/g, '-') // Replace underscores with hyphens
51
- .replace(/[^a-z0-9-.]/g, '') // Remove all non-alphanumeric chars except hyphen and dot
52
- .replace(/-+/g, '-') // Collapse multiple hyphens into one
53
- .replace(/^-|-$/, ''); // Remove leading/trailing hyphens
54
- }
55
- export function make_sanitized_path(...paths) {
56
- let real_path = '';
57
- for (let i = 0; i < paths.length; i++) {
58
- const sanitized = sanitizeFilename(eatInner(paths[i], ['/']));
59
- if (i === 0) {
60
- real_path = sanitized;
61
- }
62
- else if (sanitized) { // Only append if there's a non-empty segment
63
- real_path = `${real_path}/${sanitized}`;
64
- }
65
- }
66
- return real_path || '';
67
- }
68
- export function normalizeUrl(base, p) {
69
- if (!p)
70
- return base;
71
- const cleanBase = base.replace(/\/+$/, ''); // regex literal
72
- const cleanPath = p.replace(/^\/+/, '');
73
- // collapse multiple “//” into one, but keep the “://” after protocol
74
- return `${cleanBase}/${cleanPath}`.replace(/([^:])\/{2,}/g, '$1/');
75
- }
@@ -1,12 +0,0 @@
1
- import { getAbsolutePath } from './../imports';
2
- import { get_dirname, make_path } from './path_utils';
3
- /**
4
- * Returns the absolute path of the current file.
5
- */
6
- export function getAbsDir() {
7
- return get_dirname(getAbsolutePath());
8
- }
9
- ;
10
- export function getAbsPath(subPath) {
11
- return make_path(getAbsDir(), subPath);
12
- }
@@ -1,25 +0,0 @@
1
- import { make_path, get_dirname } from './path_utils';
2
- import { getFunctionsDir } from './function_dirs';
3
- export function getSrcDir() {
4
- return get_dirname(getFunctionsDir());
5
- }
6
- ;
7
- export function geStaticDirectory() {
8
- return make_path(getSrcDir(), 'static');
9
- }
10
- ;
11
- export function getLibUtilsDirectory() {
12
- return make_path(getSrcDir(), 'lib');
13
- }
14
- export function getHooksUtilsDirectory() {
15
- return make_path(getSrcDir(), 'hooks');
16
- }
17
- ;
18
- export function getFunctionsUtilsDirectory() {
19
- return make_path(getSrcDir(), 'functions');
20
- }
21
- ;
22
- export function getComponentsUtilsDirectory() {
23
- return make_path(getSrcDir(), 'components');
24
- }
25
- ;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export * from './read_utils';
@@ -1,55 +0,0 @@
1
- // src/read_utils.ts
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- /**
12
- * Attempt to load the Node-only modules.
13
- * Returns { fs: null, path: null } in the browser.
14
- */
15
- function tryNodeModules() {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- try {
18
- const fsMod = yield import('fs');
19
- const pathMod = yield import('path');
20
- return {
21
- fs: fsMod.promises, // keep the `promises` API
22
- path: pathMod
23
- };
24
- }
25
- catch (_a) {
26
- return { fs: null, path: null };
27
- }
28
- });
29
- }
30
- /**
31
- * Reads a file at `relativeOrAbsolutePath` and returns its contents as a string.
32
- * In a browser this will reject immediately.
33
- */
34
- export function readFileContents(relativeOrAbsolutePath) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const { fs, path } = yield tryNodeModules();
37
- if (!fs || !path) {
38
- throw new Error('readFileContents can only be used in Node.js');
39
- }
40
- // resolve absolute
41
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
42
- ? relativeOrAbsolutePath
43
- : path.resolve(__dirname, relativeOrAbsolutePath);
44
- return fs.readFile(filePath, 'utf8');
45
- });
46
- }
47
- /**
48
- * Reads a JSON file and returns the parsed object.
49
- */
50
- export function readJsonFile(relativeOrAbsolutePath) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const text = yield readFileContents(relativeOrAbsolutePath);
53
- return JSON.parse(text);
54
- });
55
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export * from './utils';
@@ -1,12 +0,0 @@
1
- // src/functions/rndm_utils/utils.ts
2
- export function alertit(obj = null) {
3
- let msg;
4
- try {
5
- msg = JSON.stringify(obj);
6
- }
7
- catch (_a) {
8
- // If JSON.stringify fails (circular refs, etc.), fall back to a simple string
9
- msg = String(obj);
10
- }
11
- alert(msg);
12
- }
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export * from './string_utils';
@@ -1,113 +0,0 @@
1
- export function getSubstring(obj, maxLength = null, minLength = null) {
2
- const objLength = obj.length;
3
- const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
4
- const effectiveMinLength = minLength !== null && minLength !== void 0 ? minLength : 0;
5
- // Ensure bounds are valid
6
- const clampedMaxLength = Math.min(Math.max(effectiveMaxLength, 0), objLength);
7
- const clampedMinLength = Math.min(Math.max(effectiveMinLength, 0), objLength);
8
- // If minLength exceeds maxLength, return empty string or adjust logic as needed
9
- if (clampedMinLength >= clampedMaxLength) {
10
- return '';
11
- }
12
- return obj.substring(clampedMinLength, clampedMaxLength);
13
- }
14
- export function truncateString(obj, maxLength = 20) {
15
- const objLength = obj.length;
16
- if (objLength > maxLength && maxLength) {
17
- obj = getSubstring(obj, maxLength) + '...';
18
- }
19
- return obj;
20
- }
21
- /**
22
- * Remove *every* occurrence of any prefix in `bases` from the *beginning*
23
- * of `str`, looping until no prefix matches.
24
- *
25
- * @example
26
- * stripPrefixes('/site/site/docs', ['/site', '/static']);
27
- * // → '/docs'
28
- */
29
- export function stripPrefixes(str, bases = []) {
30
- // normalise to a non-empty array of strings
31
- const prefixes = (Array.isArray(bases) ? bases : [bases])
32
- .filter(Boolean)
33
- // longest first ⇒ '/site/files' is checked before '/site'
34
- .sort((a, b) => b.length - a.length);
35
- let changed = true;
36
- while (changed) {
37
- changed = false;
38
- for (const prefix of prefixes) {
39
- if (str.startsWith(prefix)) {
40
- str = str.slice(prefix.length);
41
- changed = true; // start the loop again
42
- break; // restart prefix scan from the longest one
43
- }
44
- }
45
- }
46
- return str;
47
- }
48
- /**
49
- * Removes characters from the beginning of the string
50
- * if they are found in the list of characters.
51
- *
52
- * @param str - The input string.
53
- * @param listObjects - A string or an array of characters to remove.
54
- * @returns The modified string.
55
- */
56
- export function eatInner(str, listObjects) {
57
- if (!Array.isArray(listObjects)) {
58
- listObjects = [listObjects];
59
- }
60
- // Ensure str is a string
61
- str = String(str);
62
- // Remove characters from the beginning while they are in listObjects
63
- while (str.length > 0 && listObjects.includes(str[0])) {
64
- str = str.slice(1);
65
- }
66
- return str;
67
- }
68
- /**
69
- * Removes characters from the end of the string
70
- * if they are found in the list of characters.
71
- *
72
- * @param str - The input string.
73
- * @param listObjects - A string or an array of characters to remove.
74
- * @returns The modified string.
75
- */
76
- export function eatOuter(str, listObjects) {
77
- if (!Array.isArray(listObjects)) {
78
- listObjects = [listObjects];
79
- }
80
- // Ensure str is a string
81
- str = String(str);
82
- // Remove characters from the end while they are in listObjects
83
- while (str.length > 0 && listObjects.includes(str[str.length - 1])) {
84
- str = str.slice(0, -1);
85
- }
86
- return str;
87
- }
88
- /**
89
- * Removes characters from both the beginning and the end of the string
90
- * if they are found in the list of characters.
91
- *
92
- * @param str - The input string.
93
- * @param listObjects - A string or an array of characters to remove.
94
- * @returns The modified string.
95
- */
96
- export function eatAll(str, listObjects) {
97
- return eatOuter(eatInner(str, listObjects), listObjects);
98
- }
99
- export function eatEnd(obj, endings = ['/']) {
100
- let result = obj;
101
- let modified = true;
102
- while (modified) {
103
- modified = false;
104
- for (const ending of endings) {
105
- if (result.endsWith(ending)) {
106
- result = result.slice(0, -ending.length);
107
- modified = true;
108
- break;
109
- }
110
- }
111
- }
112
- return result;
113
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export * from './type_utils';
@@ -1,4 +0,0 @@
1
- export function ensure_list(obj) {
2
- const objArray = Array.isArray(obj) ? obj : [obj];
3
- return objArray;
4
- }
@@ -1,5 +0,0 @@
1
- //src/components/UI/UI.tsx
2
- import React from 'react';
3
- export const { useState, useEffect, useCallback } = React;
4
- export { fetchIt } from './../fetch_utils';
5
- export { currentUsername, isTokenExpired, getToken } from './../auth_utils';
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1,32 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- export function Button(_a) {
14
- var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
15
- const base = 'rounded px-3 py-1 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors duration-150';
16
- const variantStyles = {
17
- default: '',
18
- icon: 'p-1 bg-transparent hover:bg-gray-100',
19
- primary: 'text-white',
20
- secondary: '',
21
- };
22
- const palette = {
23
- gray: variant === 'primary'
24
- ? 'bg-gray-600 hover:bg-gray-700 focus:ring-gray-500'
25
- : 'bg-gray-200 hover:bg-gray-300 focus:ring-gray-400',
26
- green: 'bg-green-600 text-white hover:bg-green-700 focus:ring-green-500',
27
- blue: variant === 'primary'
28
- ? 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'
29
- : 'bg-blue-200 hover:bg-blue-300 focus:ring-blue-400',
30
- };
31
- return (_jsx("button", Object.assign({ className: `${base} ${variantStyles[variant]} ${palette[color]} ${className}` }, rest, { children: children })));
32
- }
@@ -1,16 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- export function Checkbox(_a) {
14
- var { label } = _a, rest = __rest(_a, ["label"]);
15
- return (_jsxs("label", { className: 'flex items-center gap-2 mb-4', children: [_jsx("input", Object.assign({ type: 'checkbox' }, rest)), _jsx("span", { children: label })] }));
16
- }
@@ -1,4 +0,0 @@
1
- export * from './button';
2
- export * from './checkbox';
3
- export * from './input';
4
- export * from './spinner';
@@ -1,16 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- export function Input(_a) {
14
- var { label, trailing } = _a, rest = __rest(_a, ["label", "trailing"]);
15
- return (_jsxs("label", { className: 'mb-4 block', children: [_jsx("span", { className: 'block text-sm font-medium mb-1', children: label }), _jsxs("div", { className: 'flex gap-2', children: [_jsx("input", Object.assign({ className: 'flex-1 rounded border px-2 py-1 disabled:bg-gray-100' }, rest)), trailing] })] }));
16
- }
@@ -1,4 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export function Spinner() {
3
- return (_jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
4
- }
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- export * from './functions';
2
- export * from './types';
3
- export { loadConfig } from './utils';
4
- import { get_app_config_url } from './functions';
5
- console.log(get_app_config_url('api'));
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export * from './Files';
2
- export * from './ChangePassword';
3
- export * from './utils';
4
- export * from './logout';
5
- export * from './login';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1,2 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- export const Input = ({ label, type, value, onValueChange, placeholder, disabled, error, directory, multiple, accept, }) => (_jsxs("label", { className: "block", children: [_jsx("span", { className: "text-sm", children: label }), _jsx("input", Object.assign({ type: type, className: `mt-1 w-full border rounded px-2 py-1 ${error ? "border-red-500" : ""}`, value: value, onChange: (e) => onValueChange(e.target.value), placeholder: placeholder, disabled: disabled }, (type === "file" && directory ? { webkitdirectory: "true", directory: "" } : {}), (type === "file" && multiple ? { multiple: true } : {}), (type === "file" && accept ? { accept } : {}))), error && _jsx("p", { className: "text-sm text-red-600", children: error })] }));
@@ -1,20 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export let AppConfig;
11
- export function loadConfig() {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- const base = (process.env.BASE_API_URL || "").replace(/\/+$/, "");
14
- const url = `${base}/config.json`;
15
- const res = yield fetch(url);
16
- if (!res.ok)
17
- throw new Error(`Failed to load ${url}: ${res.status}`);
18
- AppConfig = yield res.json();
19
- });
20
- }
@@ -1,2 +0,0 @@
1
- export * from "./Input";
2
- export * from './config';