@pol-studios/utils 1.0.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.
Files changed (54) hide show
  1. package/dist/array/index.d.ts +1 -0
  2. package/dist/array/index.js +136 -0
  3. package/dist/async/index.d.ts +1 -0
  4. package/dist/async/index.js +67 -0
  5. package/dist/cache/index.d.ts +1 -0
  6. package/dist/cache/index.js +42 -0
  7. package/dist/color/index.d.ts +1 -0
  8. package/dist/color/index.js +16 -0
  9. package/dist/date/index.d.ts +2 -0
  10. package/dist/date/index.js +102 -0
  11. package/dist/dev/index.d.ts +1 -0
  12. package/dist/dev/index.js +21 -0
  13. package/dist/device/index.d.ts +1 -0
  14. package/dist/device/index.js +31 -0
  15. package/dist/enum/index.d.ts +1 -0
  16. package/dist/enum/index.js +19 -0
  17. package/dist/error/index.d.ts +1 -0
  18. package/dist/error/index.js +198 -0
  19. package/dist/format/index.d.ts +1 -0
  20. package/dist/format/index.js +36 -0
  21. package/dist/index-B2oAfh_i.d.ts +63 -0
  22. package/dist/index-BDWEMkWa.d.ts +56 -0
  23. package/dist/index-BSNY-QEc.d.ts +15 -0
  24. package/dist/index-BaA8cg0E.d.ts +100 -0
  25. package/dist/index-Btn_GVfm.d.ts +13 -0
  26. package/dist/index-BxUoIlv_.d.ts +39 -0
  27. package/dist/index-ByjfWGR4.d.ts +151 -0
  28. package/dist/index-C-YwC08Y.d.ts +45 -0
  29. package/dist/index-C062CkPL.d.ts +31 -0
  30. package/dist/index-C8CxeaqZ.d.ts +24 -0
  31. package/dist/index-CZbs1QQN.d.ts +102 -0
  32. package/dist/index-Cp7KyTeB.d.ts +23 -0
  33. package/dist/index-CrplC0qf.d.ts +29 -0
  34. package/dist/index-Cvl_0aDq.d.ts +14 -0
  35. package/dist/index-D_IvPWYI.d.ts +77 -0
  36. package/dist/index-DdaZnk7j.d.ts +28 -0
  37. package/dist/index-vLuR45Km.d.ts +27 -0
  38. package/dist/index.d.ts +84 -0
  39. package/dist/index.js +1279 -0
  40. package/dist/object/index.d.ts +1 -0
  41. package/dist/object/index.js +115 -0
  42. package/dist/state/index.d.ts +1 -0
  43. package/dist/state/index.js +17 -0
  44. package/dist/string/index.d.ts +1 -0
  45. package/dist/string/index.js +55 -0
  46. package/dist/tailwind/index.d.ts +2 -0
  47. package/dist/tailwind/index.js +9 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/index.js +37 -0
  50. package/dist/uuid/index.d.ts +1 -0
  51. package/dist/uuid/index.js +10 -0
  52. package/dist/validation/index.d.ts +1 -0
  53. package/dist/validation/index.js +123 -0
  54. package/package.json +50 -0
@@ -0,0 +1 @@
1
+ export { e as deepEquals, d as diff, g as getPath, b as getValueByPath, a as includeOnly, f as isDeepEqual, o as omit, p as pick, s as setPath, c as setValueByPath } from '../index-CZbs1QQN.js';
@@ -0,0 +1,115 @@
1
+ // src/object/omit.ts
2
+ function omit(obj, keys) {
3
+ const keysArray = Array.isArray(keys) ? keys : [keys];
4
+ const newObj = { ...obj };
5
+ keysArray.forEach((key) => {
6
+ if (key in newObj) {
7
+ delete newObj[key];
8
+ }
9
+ });
10
+ return newObj;
11
+ }
12
+
13
+ // src/object/pick.ts
14
+ function pick(obj, keys) {
15
+ const newValue = {};
16
+ keys.forEach((key) => {
17
+ if (key in obj) {
18
+ newValue[key] = obj[key];
19
+ }
20
+ });
21
+ return newValue;
22
+ }
23
+ var includeOnly = pick;
24
+
25
+ // src/internal/isUsable.ts
26
+ function isUsable(value) {
27
+ return value !== void 0 && value !== null && (typeof value !== "number" || isNaN(value) === false);
28
+ }
29
+
30
+ // src/object/diff.ts
31
+ function diff(oldValue, newValue) {
32
+ if (isUsable(oldValue) === false) {
33
+ return { ...newValue };
34
+ }
35
+ const result = {};
36
+ function compare(o1, o2, res) {
37
+ for (const key in o1) {
38
+ if (o1.hasOwnProperty(key)) {
39
+ if (typeof o1[key] === "object" && o1[key] !== null && typeof o2[key] === "object" && o2[key] !== null) {
40
+ const nestedDiff = diff(o1[key], o2[key]);
41
+ if (Object.keys(nestedDiff).length > 0) {
42
+ res[key] = nestedDiff;
43
+ }
44
+ } else if (o1[key] !== o2[key]) {
45
+ res[key] = o2[key];
46
+ }
47
+ }
48
+ }
49
+ for (const key in o2) {
50
+ if (o2.hasOwnProperty(key) && !o1.hasOwnProperty(key)) {
51
+ res[key] = o2[key];
52
+ }
53
+ }
54
+ }
55
+ compare(oldValue, newValue, result);
56
+ return result;
57
+ }
58
+
59
+ // src/object/getPath.ts
60
+ function getPath(obj, path) {
61
+ const keys = path.split(".");
62
+ let current = obj;
63
+ for (const key of keys) {
64
+ if (current[key] === void 0) {
65
+ return void 0;
66
+ }
67
+ current = current[key];
68
+ }
69
+ return current;
70
+ }
71
+ var getValueByPath = getPath;
72
+
73
+ // src/object/setPath.ts
74
+ function setPath(obj, path, value) {
75
+ const keys = path.split(".");
76
+ let current = obj;
77
+ for (let i = 0; i < keys.length - 1; i++) {
78
+ const key = keys[i];
79
+ if (current[key] === void 0) {
80
+ current[key] = {};
81
+ }
82
+ current = current[key];
83
+ }
84
+ const lastKey = keys[keys.length - 1];
85
+ current[lastKey] = value;
86
+ }
87
+ var setValueByPath = setPath;
88
+
89
+ // src/object/deepEqual.ts
90
+ function deepEquals(obj1, obj2) {
91
+ const keys1 = Object.keys(obj1);
92
+ const keys2 = Object.keys(obj2);
93
+ if (keys1.length !== keys2.length) {
94
+ return false;
95
+ }
96
+ for (const key of keys1) {
97
+ if (obj1[key] !== obj2[key]) {
98
+ return false;
99
+ }
100
+ }
101
+ return true;
102
+ }
103
+ var isDeepEqual = deepEquals;
104
+ export {
105
+ deepEquals,
106
+ diff,
107
+ getPath,
108
+ getValueByPath,
109
+ includeOnly,
110
+ isDeepEqual,
111
+ omit,
112
+ pick,
113
+ setPath,
114
+ setValueByPath
115
+ };
@@ -0,0 +1 @@
1
+ export { g as getObjectChanges, w as withUpdate } from '../index-C8CxeaqZ.js';
@@ -0,0 +1,17 @@
1
+ // src/state/index.ts
2
+ function withUpdate(item, updates) {
3
+ return { ...item, ...updates };
4
+ }
5
+ function getObjectChanges(oldObj, newObj) {
6
+ const changes = {};
7
+ for (const key of Object.keys(newObj)) {
8
+ if (newObj[key] !== oldObj[key]) {
9
+ changes[key] = newObj[key];
10
+ }
11
+ }
12
+ return changes;
13
+ }
14
+ export {
15
+ getObjectChanges,
16
+ withUpdate
17
+ };
@@ -0,0 +1 @@
1
+ export { c as camelize, g as generateSlug, d as isBlank, e as isNullOrWhitespace, p as pascalize, a as pascalizeWithSpaces, b as sanitizeInput, s as slugify } from '../index-D_IvPWYI.js';
@@ -0,0 +1,55 @@
1
+ // src/string/camelize.ts
2
+ function camelize(str) {
3
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
4
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
5
+ }).replace(/\s+/g, "");
6
+ }
7
+
8
+ // src/internal/isUsable.ts
9
+ function isUsable(value) {
10
+ return value !== void 0 && value !== null && (typeof value !== "number" || isNaN(value) === false);
11
+ }
12
+
13
+ // src/string/pascalize.ts
14
+ function pascalize(str) {
15
+ return str.replace(/(\w)(\w*)/g, function(g0, g1, g2) {
16
+ return g1.toUpperCase() + g2.toLowerCase();
17
+ });
18
+ }
19
+ function pascalizeWithSpaces(input) {
20
+ if (isUsable(input) === false) return input;
21
+ return input.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(" ");
22
+ }
23
+
24
+ // src/string/slugify.ts
25
+ function slugify(text) {
26
+ return text.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
27
+ }
28
+ var generateSlug = slugify;
29
+
30
+ // src/string/sanitize.ts
31
+ function sanitizeInput(value) {
32
+ return value.replace(/"/g, '""').replace(/'/g, "''");
33
+ }
34
+
35
+ // src/string/isBlank.ts
36
+ function isBlank(value) {
37
+ if (value === null || value === void 0) {
38
+ return true;
39
+ }
40
+ if (typeof value === "string" && value.trim().length === 0) {
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+ var isNullOrWhitespace = isBlank;
46
+ export {
47
+ camelize,
48
+ generateSlug,
49
+ isBlank,
50
+ isNullOrWhitespace,
51
+ pascalize,
52
+ pascalizeWithSpaces,
53
+ sanitizeInput,
54
+ slugify
55
+ };
@@ -0,0 +1,2 @@
1
+ export { ClassValue } from 'clsx';
2
+ export { c as cn } from '../index-BSNY-QEc.js';
@@ -0,0 +1,9 @@
1
+ // src/tailwind/index.ts
2
+ import { clsx } from "clsx";
3
+ import { twMerge } from "tailwind-merge";
4
+ function cn(...inputs) {
5
+ return twMerge(clsx(inputs));
6
+ }
7
+ export {
8
+ cn
9
+ };
@@ -0,0 +1 @@
1
+ export { d as EntityAccessRecord, b as EntityAction, c as EntityPermissionCheck, a as EntityPermissionLevel, E as EntityType, I as ItemType, K as KeyOfStringOrNumber, P as PermissionEffect, S as StorageObjectMetadata, g as getContentType, e as isImageType, h as isPdfType, j as isRenderableType, k as isUsable, f as isVideoType } from '../index-BaA8cg0E.js';
@@ -0,0 +1,37 @@
1
+ // src/types/guards.ts
2
+ function isUsable(value) {
3
+ return value !== void 0 && value !== null && (typeof value !== "number" || isNaN(value) === false);
4
+ }
5
+
6
+ // src/types/StorageObjectMetadata.ts
7
+ function getContentType(metadata, path) {
8
+ if (metadata?.contentType) {
9
+ return metadata.contentType;
10
+ }
11
+ const ext = path.split(".").pop()?.toUpperCase();
12
+ return ext || "Unknown";
13
+ }
14
+ function isImageType(contentType) {
15
+ return ["JPEG", "JPG", "PNG", "GIF", "WEBP", "SVG", "HEIC", "HEIF"].includes(
16
+ contentType.toUpperCase()
17
+ );
18
+ }
19
+ function isVideoType(contentType) {
20
+ return ["MP4", "QUICKTIME", "MOV", "WEBM", "AVI", "MKV"].includes(
21
+ contentType.toUpperCase()
22
+ );
23
+ }
24
+ function isPdfType(contentType) {
25
+ return contentType.toUpperCase() === "PDF";
26
+ }
27
+ function isRenderableType(contentType) {
28
+ return isImageType(contentType) || isVideoType(contentType) || isPdfType(contentType);
29
+ }
30
+ export {
31
+ getContentType,
32
+ isImageType,
33
+ isPdfType,
34
+ isRenderableType,
35
+ isUsable,
36
+ isVideoType
37
+ };
@@ -0,0 +1 @@
1
+ export { n as newUuid } from '../index-Btn_GVfm.js';
@@ -0,0 +1,10 @@
1
+ // src/uuid/index.ts
2
+ function newUuid() {
3
+ return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, () => {
4
+ const r = Math.random() * 16 | 0;
5
+ return r.toString(16);
6
+ });
7
+ }
8
+ export {
9
+ newUuid
10
+ };
@@ -0,0 +1 @@
1
+ export { P as PasswordStrength, g as PasswordStrengthResult, a as ValidationResult, V as ValidationRule, h as calculatePasswordStrength, b as validateEmail, e as validateMaxLength, d as validateMinLength, f as validatePattern, c as validateRequired, v as validateValue } from '../index-BxUoIlv_.js';
@@ -0,0 +1,123 @@
1
+ // src/validation/validators.ts
2
+ function validateValue(value, rules) {
3
+ for (const rule of rules) {
4
+ if (!rule.validate(value)) {
5
+ return { isValid: false, error: rule.message };
6
+ }
7
+ }
8
+ return { isValid: true };
9
+ }
10
+ function validateEmail(email) {
11
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
12
+ if (!email || email.trim().length === 0) {
13
+ return { isValid: false, error: "Email is required" };
14
+ }
15
+ if (!emailRegex.test(email)) {
16
+ return { isValid: false, error: "Please enter a valid email address" };
17
+ }
18
+ return { isValid: true };
19
+ }
20
+ function validateRequired(value) {
21
+ if (value === null || value === void 0 || value === "") {
22
+ return { isValid: false, error: "This field is required" };
23
+ }
24
+ if (typeof value === "string" && value.trim().length === 0) {
25
+ return { isValid: false, error: "This field is required" };
26
+ }
27
+ return { isValid: true };
28
+ }
29
+ function validateMinLength(min) {
30
+ return (value) => {
31
+ if (!value || value.length < min) {
32
+ return {
33
+ isValid: false,
34
+ error: `Must be at least ${min} characters`
35
+ };
36
+ }
37
+ return { isValid: true };
38
+ };
39
+ }
40
+ function validateMaxLength(max) {
41
+ return (value) => {
42
+ if (value && value.length > max) {
43
+ return {
44
+ isValid: false,
45
+ error: `Must be no more than ${max} characters`
46
+ };
47
+ }
48
+ return { isValid: true };
49
+ };
50
+ }
51
+ function validatePattern(pattern, message) {
52
+ return (value) => {
53
+ if (value && !pattern.test(value)) {
54
+ return { isValid: false, error: message };
55
+ }
56
+ return { isValid: true };
57
+ };
58
+ }
59
+
60
+ // src/validation/password.ts
61
+ function calculatePasswordStrength(password) {
62
+ if (!password || password.length === 0) {
63
+ return {
64
+ strength: "weak",
65
+ score: 0,
66
+ feedback: []
67
+ };
68
+ }
69
+ let score = 0;
70
+ const feedback = [];
71
+ if (password.length >= 8) {
72
+ score += 1;
73
+ } else {
74
+ feedback.push("Use at least 8 characters");
75
+ }
76
+ if (password.length >= 12) {
77
+ score += 1;
78
+ }
79
+ if (/[a-z]/.test(password)) {
80
+ score += 1;
81
+ } else {
82
+ feedback.push("Add lowercase letters");
83
+ }
84
+ if (/[A-Z]/.test(password)) {
85
+ score += 1;
86
+ } else {
87
+ feedback.push("Add uppercase letters");
88
+ }
89
+ if (/[0-9]/.test(password)) {
90
+ score += 1;
91
+ } else {
92
+ feedback.push("Add numbers");
93
+ }
94
+ if (/[^a-zA-Z0-9]/.test(password)) {
95
+ score += 1;
96
+ } else {
97
+ feedback.push("Add special characters");
98
+ }
99
+ let strength;
100
+ if (score <= 2) {
101
+ strength = "weak";
102
+ } else if (score <= 3) {
103
+ strength = "fair";
104
+ } else if (score <= 4) {
105
+ strength = "good";
106
+ } else {
107
+ strength = "strong";
108
+ }
109
+ return {
110
+ strength,
111
+ score,
112
+ feedback: feedback.length > 0 ? feedback : []
113
+ };
114
+ }
115
+ export {
116
+ calculatePasswordStrength,
117
+ validateEmail,
118
+ validateMaxLength,
119
+ validateMinLength,
120
+ validatePattern,
121
+ validateRequired,
122
+ validateValue
123
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@pol-studios/utils",
3
+ "version": "1.0.0",
4
+ "description": "Utility functions for POL applications",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": ["dist"],
10
+ "keywords": ["utils", "utilities", "helpers"],
11
+ "exports": {
12
+ ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" },
13
+ "./string": { "import": "./dist/string/index.js", "types": "./dist/string/index.d.ts" },
14
+ "./array": { "import": "./dist/array/index.js", "types": "./dist/array/index.d.ts" },
15
+ "./object": { "import": "./dist/object/index.js", "types": "./dist/object/index.d.ts" },
16
+ "./date": { "import": "./dist/date/index.js", "types": "./dist/date/index.d.ts" },
17
+ "./async": { "import": "./dist/async/index.js", "types": "./dist/async/index.d.ts" },
18
+ "./format": { "import": "./dist/format/index.js", "types": "./dist/format/index.d.ts" },
19
+ "./tailwind": { "import": "./dist/tailwind/index.js", "types": "./dist/tailwind/index.d.ts" },
20
+ "./cache": { "import": "./dist/cache/index.js", "types": "./dist/cache/index.d.ts" },
21
+ "./types": { "import": "./dist/types/index.js", "types": "./dist/types/index.d.ts" },
22
+ "./color": { "import": "./dist/color/index.js", "types": "./dist/color/index.d.ts" },
23
+ "./validation": { "import": "./dist/validation/index.js", "types": "./dist/validation/index.d.ts" },
24
+ "./error": { "import": "./dist/error/index.js", "types": "./dist/error/index.d.ts" },
25
+ "./device": { "import": "./dist/device/index.js", "types": "./dist/device/index.d.ts" },
26
+ "./uuid": { "import": "./dist/uuid/index.js", "types": "./dist/uuid/index.d.ts" },
27
+ "./state": { "import": "./dist/state/index.js", "types": "./dist/state/index.d.ts" },
28
+ "./enum": { "import": "./dist/enum/index.js", "types": "./dist/enum/index.d.ts" },
29
+ "./dev": { "import": "./dist/dev/index.js", "types": "./dist/dev/index.d.ts" }
30
+ },
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "dev": "tsup --watch",
34
+ "prepublishOnly": "pnpm build"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "dependencies": {
40
+ "clsx": "^2.0.0",
41
+ "tailwind-merge": "^2.0.0"
42
+ },
43
+ "peerDependencies": {
44
+ "moment": "^2.29.4"
45
+ },
46
+ "devDependencies": {
47
+ "tsup": "^8.0.0",
48
+ "typescript": "^5.0.0"
49
+ }
50
+ }