sea-platform-helpers 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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/constants/account/index.d.ts +3 -0
  4. package/dist/constants/account/index.d.ts.map +1 -0
  5. package/dist/constants/account/index.js +10 -0
  6. package/dist/constants/application/index.d.ts +16 -0
  7. package/dist/constants/application/index.d.ts.map +1 -0
  8. package/dist/constants/application/index.js +28 -0
  9. package/dist/constants/index.d.ts +6 -0
  10. package/dist/constants/index.d.ts.map +1 -0
  11. package/dist/constants/index.js +41 -0
  12. package/dist/constants/otp/index.d.ts +3 -0
  13. package/dist/constants/otp/index.d.ts.map +1 -0
  14. package/dist/constants/otp/index.js +5 -0
  15. package/dist/constants/permission/index.d.ts +45 -0
  16. package/dist/constants/permission/index.d.ts.map +1 -0
  17. package/dist/constants/permission/index.js +306 -0
  18. package/dist/constants/server/index.d.ts +7 -0
  19. package/dist/constants/server/index.d.ts.map +1 -0
  20. package/dist/constants/server/index.js +10 -0
  21. package/dist/dto/account/index.d.ts +27 -0
  22. package/dist/dto/account/index.d.ts.map +1 -0
  23. package/dist/dto/account/index.js +2 -0
  24. package/dist/dto/application/index.d.ts +16 -0
  25. package/dist/dto/application/index.d.ts.map +1 -0
  26. package/dist/dto/application/index.js +2 -0
  27. package/dist/dto/application copy/index.d.ts +15 -0
  28. package/dist/dto/application copy/index.d.ts.map +1 -0
  29. package/dist/dto/application copy/index.js +2 -0
  30. package/dist/dto/department/index.d.ts +12 -0
  31. package/dist/dto/department/index.d.ts.map +1 -0
  32. package/dist/dto/department/index.js +2 -0
  33. package/dist/dto/file/index.d.ts +8 -0
  34. package/dist/dto/file/index.d.ts.map +1 -0
  35. package/dist/dto/file/index.js +2 -0
  36. package/dist/dto/global/index.d.ts +8 -0
  37. package/dist/dto/global/index.d.ts.map +1 -0
  38. package/dist/dto/global/index.js +2 -0
  39. package/dist/dto/index.d.ts +9 -0
  40. package/dist/dto/index.d.ts.map +1 -0
  41. package/dist/dto/index.js +44 -0
  42. package/dist/dto/organization/index.d.ts +10 -0
  43. package/dist/dto/organization/index.d.ts.map +1 -0
  44. package/dist/dto/organization/index.js +2 -0
  45. package/dist/dto/organization copy/index.d.ts +9 -0
  46. package/dist/dto/organization copy/index.d.ts.map +1 -0
  47. package/dist/dto/organization copy/index.js +2 -0
  48. package/dist/dto/permission/index.d.ts +10 -0
  49. package/dist/dto/permission/index.d.ts.map +1 -0
  50. package/dist/dto/permission/index.js +2 -0
  51. package/dist/dto/request/index.d.ts +11 -0
  52. package/dist/dto/request/index.d.ts.map +1 -0
  53. package/dist/dto/request/index.js +6 -0
  54. package/dist/dto/role/index.d.ts +23 -0
  55. package/dist/dto/role/index.d.ts.map +1 -0
  56. package/dist/dto/role/index.js +2 -0
  57. package/dist/index.d.ts +4 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +42 -0
  60. package/dist/utils/array/index.d.ts +4 -0
  61. package/dist/utils/array/index.d.ts.map +1 -0
  62. package/dist/utils/array/index.js +28 -0
  63. package/dist/utils/bcrypt/index.d.ts +3 -0
  64. package/dist/utils/bcrypt/index.d.ts.map +1 -0
  65. package/dist/utils/bcrypt/index.js +53 -0
  66. package/dist/utils/dfs/index.d.ts +4 -0
  67. package/dist/utils/dfs/index.d.ts.map +1 -0
  68. package/dist/utils/dfs/index.js +53 -0
  69. package/dist/utils/index.d.ts +8 -0
  70. package/dist/utils/index.d.ts.map +1 -0
  71. package/dist/utils/index.js +44 -0
  72. package/dist/utils/moment/index.d.ts +9 -0
  73. package/dist/utils/moment/index.d.ts.map +1 -0
  74. package/dist/utils/moment/index.js +39 -0
  75. package/dist/utils/numbers/index.d.ts +3 -0
  76. package/dist/utils/numbers/index.d.ts.map +1 -0
  77. package/dist/utils/numbers/index.js +38 -0
  78. package/dist/utils/phone-number/index.d.ts +2 -0
  79. package/dist/utils/phone-number/index.d.ts.map +1 -0
  80. package/dist/utils/phone-number/index.js +9 -0
  81. package/dist/utils/string/index.d.ts +7 -0
  82. package/dist/utils/string/index.d.ts.map +1 -0
  83. package/dist/utils/string/index.js +29 -0
  84. package/dist/utils/tree/index.d.ts +6 -0
  85. package/dist/utils/tree/index.d.ts.map +1 -0
  86. package/dist/utils/tree/index.js +69 -0
  87. package/package.json +36 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmail = exports.isPhoneNumber = exports.emailRegex = exports.phoneRegExp = exports.generateRandomString = exports.normalizeString = void 0;
4
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
5
+ const normalizeString = (str) => {
6
+ if (str)
7
+ return str.trim().toLowerCase();
8
+ return null;
9
+ };
10
+ exports.normalizeString = normalizeString;
11
+ const generateRandomString = (length = 6) => {
12
+ let result = "";
13
+ for (let i = 0; i < length; i++) {
14
+ const randomIndex = Math.floor(Math.random() * characters.length);
15
+ result += characters[randomIndex];
16
+ }
17
+ return result;
18
+ };
19
+ exports.generateRandomString = generateRandomString;
20
+ exports.phoneRegExp = /^\+?[1-9]\d{1,3}\d{6,14}$/;
21
+ exports.emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
22
+ const isPhoneNumber = (str) => {
23
+ return exports.phoneRegExp.test(str);
24
+ };
25
+ exports.isPhoneNumber = isPhoneNumber;
26
+ const isEmail = (str) => {
27
+ return exports.emailRegex.test(str);
28
+ };
29
+ exports.isEmail = isEmail;
@@ -0,0 +1,6 @@
1
+ export declare const editTree: <T, G>(root: T, editFn: (value: T) => G, childrenKey: keyof T) => G;
2
+ export declare const DFS: <T>(root: T, walk: (value: T) => void, childrenKey: keyof T) => void;
3
+ export declare const findNode: <T>(root: T, predicate: (node: T) => boolean, childrenKey: keyof T) => T | undefined;
4
+ export declare const flattenTree: <T, K extends keyof T>(node: T, childrenKey: K) => T[];
5
+ export declare const getAllLeafNodes: <T, K extends keyof T>(node: T, childrenKey: K) => T[];
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/tree/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,QACrB,CAAC,UACC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,eACV,MAAM,CAAC,KACnB,CAeF,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,CAAC,QACb,CAAC,QACD,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,eACX,MAAM,CAAC,KACnB,IAOF,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,CAAC,QAClB,CAAC,aACI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,eAClB,MAAM,CAAC,KACnB,CAAC,GAAG,SAgBN,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,QACxC,CAAC,eACM,CAAC,KACb,CAAC,EAeH,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,QAC5C,CAAC,eACM,CAAC,KACb,CAAC,EAeH,CAAC"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllLeafNodes = exports.flattenTree = exports.findNode = exports.DFS = exports.editTree = void 0;
4
+ const editTree = (root, editFn, childrenKey) => {
5
+ // Access children using the provided key
6
+ const children = root[childrenKey];
7
+ let newChildren = [];
8
+ if (children) {
9
+ // Update the children recursively
10
+ newChildren = children.map((child) => (0, exports.editTree)(child, editFn, childrenKey));
11
+ }
12
+ // Apply the edit function to the root value
13
+ const updated = editFn(root);
14
+ updated[childrenKey] = newChildren;
15
+ return updated;
16
+ };
17
+ exports.editTree = editTree;
18
+ const DFS = (root, walk, childrenKey) => {
19
+ const children = root[childrenKey];
20
+ if (children) {
21
+ children.forEach((child) => (0, exports.DFS)(child, walk, childrenKey));
22
+ }
23
+ walk(root);
24
+ };
25
+ exports.DFS = DFS;
26
+ const findNode = (root, predicate, childrenKey) => {
27
+ if (predicate(root)) {
28
+ return root;
29
+ }
30
+ const children = root[childrenKey];
31
+ if (children) {
32
+ for (const child of children) {
33
+ const result = (0, exports.findNode)(child, predicate, childrenKey);
34
+ if (result) {
35
+ return result;
36
+ }
37
+ }
38
+ }
39
+ return undefined;
40
+ };
41
+ exports.findNode = findNode;
42
+ const flattenTree = (node, childrenKey) => {
43
+ // Start with the current node
44
+ const result = [node];
45
+ // Retrieve children from the given key, ensuring it's not null or undefined
46
+ const children = node[childrenKey];
47
+ // If children exist, recursively process them and add to the result
48
+ if (children) {
49
+ for (let child of children) {
50
+ result.push(...(0, exports.flattenTree)(child, childrenKey)); // Flatten the results
51
+ }
52
+ }
53
+ return result;
54
+ };
55
+ exports.flattenTree = flattenTree;
56
+ const getAllLeafNodes = (node, childrenKey) => {
57
+ const children = node[childrenKey];
58
+ // If the node has no children or the children array is empty, it's a leaf
59
+ if (!children || children.length === 0) {
60
+ return [node];
61
+ }
62
+ // Otherwise, recursively get leaf nodes from all children
63
+ const leafNodes = [];
64
+ for (let child of children) {
65
+ leafNodes.push(...(0, exports.getAllLeafNodes)(child, childrenKey));
66
+ }
67
+ return leafNodes;
68
+ };
69
+ exports.getAllLeafNodes = getAllLeafNodes;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "sea-platform-helpers",
3
+ "description": "SEA platform helpers library",
4
+ "version": "1.0.0",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "build": "tsc --build",
8
+ "watch": "tsc --watch"
9
+ },
10
+ "files": [
11
+ "dist/**/*"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "keywords": [],
20
+ "author": "",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "@nestjs/swagger": "^8.0.7",
24
+ "bcrypt": "^5.1.1",
25
+ "class-transformer": "^0.5.1",
26
+ "class-validator": "^0.14.1",
27
+ "moment": "^2.30.1",
28
+ "moment-timezone": "^0.5.46",
29
+ "numeral": "^2.0.6",
30
+ "sea-platform-helpers": "file:"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bcrypt": "^5.0.2",
34
+ "@types/numeral": "^2.0.5"
35
+ }
36
+ }