ask-ai-orbit 1.0.1
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/Communication/Email/html.processor.js +0 -0
- package/Communication/Email/mail.sender.js +0 -0
- package/Communication/Email/template.builder.js +0 -0
- package/Communication/Email/template.engine.js +0 -0
- package/DataProcessing/CSV/csv.exporter.js +0 -0
- package/DataProcessing/CSV/csv.importer.js +0 -0
- package/DataProcessing/CSV/csv.reader.js +0 -0
- package/DataProcessing/CSV/csv.writer.js +0 -0
- package/Database/Connection/connection.manager.js +0 -0
- package/Database/Connection/pool.manager.js +0 -0
- package/Database/Connection/retry.framework.js +0 -0
- package/Database/Execution/executeQuery.js +0 -0
- package/Database/Execution/executeWithRetry.js +0 -0
- package/Database/Execution/mysql.executor.js +0 -0
- package/Database/Execution/postgres.executor.js +0 -0
- package/Database/Execution/transaction.manager.js +0 -0
- package/Database/Persistence/bulkDelete.js +0 -0
- package/Database/Persistence/bulkInsert.js +0 -0
- package/Database/Persistence/bulkUpdate.js +0 -0
- package/Database/Persistence/persist.js +0 -0
- package/Database/QueryBuilder/join.builder.js +0 -0
- package/Database/QueryBuilder/metadata.parser.js +0 -0
- package/Database/QueryBuilder/query.builder.js +0 -0
- package/Database/QueryBuilder/sql.generator.js +0 -0
- package/Database/QueryBuilder/where.builder.js +0 -0
- package/Foundation/Helpers/array.helper.js +0 -0
- package/Foundation/Helpers/collection.helper.js +0 -0
- package/Foundation/Helpers/conversion.helper.js +0 -0
- package/Foundation/Helpers/csv.helper.js +0 -0
- package/Foundation/Helpers/date.helper.js +154 -0
- package/Foundation/Helpers/file.helper.js +0 -0
- package/Foundation/Helpers/html.helper.js +39 -0
- package/Foundation/Helpers/ip.helper.js +0 -0
- package/Foundation/Helpers/json.helper.js +0 -0
- package/Foundation/Helpers/map.helper.js +0 -0
- package/Foundation/Helpers/number.helper.js +0 -0
- package/Foundation/Helpers/object.helper.js +15 -0
- package/Foundation/Helpers/pagination.helper.js +0 -0
- package/Foundation/Helpers/placeholder.helper.js +3 -0
- package/Foundation/Helpers/random.helper.js +0 -0
- package/Foundation/Helpers/request.helper.js +0 -0
- package/Foundation/Helpers/response.helper.js +0 -0
- package/Foundation/Helpers/search.helper.js +0 -0
- package/Foundation/Helpers/string.helper.js +114 -0
- package/Foundation/Helpers/time.helper.js +83 -0
- package/Foundation/Helpers/utility.helper.js +0 -0
- package/Foundation/Helpers/validation.helper.js +11 -0
- package/README.md +2 -0
- package/create-askaiorbit.sh +129 -0
- package/package.json +24 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
|
|
2
|
+
export const formatDateToMySQL = (date) => {
|
|
3
|
+
const pad = (n) => n.toString().padStart(2, '0');
|
|
4
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
5
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Format JS Date or string as YYYYMMDD
|
|
11
|
+
* @param {Date|string} d
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const newDate = (s, f) => {
|
|
16
|
+
if (typeof s !== 'string') throw new Error('Input must be a string');
|
|
17
|
+
const m = s.match(/\d+/g);
|
|
18
|
+
const t = f.match(/YYYY|MM|DD|HH|mm|ss/g);
|
|
19
|
+
const o = Object.fromEntries(t.map((k, i) => [k, +m[i]]));
|
|
20
|
+
return new Date(o.YYYY || 0, (o.MM || 1) - 1, o.DD || 1, o.HH || 0, o.mm || 0, o.ss || 0);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const ArrayBetDatesPlusOne = (startDate, endDate, formatStr = "YYYY-MM-DD") => {
|
|
24
|
+
const result = [];
|
|
25
|
+
for (let d = new Date(startDate); d <= new Date(endDate); d.setDate(d.getDate() + 1))
|
|
26
|
+
result.push(format(new Date(d), formatStr));
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const isDateArrobjDatabykey = (objArr, key) =>objArr.filter(x => Number.isNaN(new Date(x[key]).getTime()));
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export const getDateparse = (result, key, formatStr) => {
|
|
34
|
+
for (const x of result)
|
|
35
|
+
if (!IsNullOrEmpty(x[key]))
|
|
36
|
+
x[key] = format(x[key], formatStr);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const getDateparsewithformat = (result, key, formatStr) => {
|
|
40
|
+
for (const x of result) {
|
|
41
|
+
if (!IsNullOrEmpty(x[key])) {
|
|
42
|
+
const d = new Date(x[key]);
|
|
43
|
+
if (!Number.isNaN(d.getTime()))
|
|
44
|
+
x[key] = format(d, formatStr);
|
|
45
|
+
else {
|
|
46
|
+
blog.error(`Invalid date: ${x[key]}`);
|
|
47
|
+
x[key] = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export const isValidDateOrTime = (value) => {
|
|
56
|
+
if (!value) return false;
|
|
57
|
+
|
|
58
|
+
// 🔹 TIME ONLY (10:00:00)
|
|
59
|
+
const timeRegex = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
|
|
60
|
+
if (timeRegex.test(value)) return true;
|
|
61
|
+
|
|
62
|
+
// 🔹 DATE ONLY or DATETIME
|
|
63
|
+
const normalized = value.replace(' ', 'T');
|
|
64
|
+
|
|
65
|
+
const date = new Date(normalized);
|
|
66
|
+
return !isNaN(date.getTime());
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Parse a date string in any common format and return it in the desired format.
|
|
74
|
+
* Supported input: '2025/01/10 00:00:00', '2025-01-10 00:00:00', '20250110 00:00:00', '10/01/2025 00:00:00', etc.
|
|
75
|
+
* @param {string} dateString - The input date string.
|
|
76
|
+
* @param {string} outputFormat - The desired output format, e.g. 'YYYY-MM-DD HH:mm:ss', 'YYYY/MM/DD HH:mm:ss', 'DD/MM/YYYY HH:mm:ss', 'DD-MM-YYYY HH:mm:ss'
|
|
77
|
+
* @returns {string|null}
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
export const parseDate = (value, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
81
|
+
if (!value || !format) return null;
|
|
82
|
+
|
|
83
|
+
const tokens = format.match(/YYYY|MM|DD|HH|mm|ss/g);
|
|
84
|
+
const numbers = String(value).match(/\d+/g);
|
|
85
|
+
|
|
86
|
+
if (!tokens || !numbers || tokens.length !== numbers.length)
|
|
87
|
+
return null;
|
|
88
|
+
|
|
89
|
+
const obj = {};
|
|
90
|
+
|
|
91
|
+
tokens.forEach((t, i) => obj[t] = Number(numbers[i]));
|
|
92
|
+
|
|
93
|
+
const d = new Date(
|
|
94
|
+
obj.YYYY ?? 0,
|
|
95
|
+
(obj.MM ?? 1) - 1,
|
|
96
|
+
obj.DD ?? 1,
|
|
97
|
+
obj.HH ?? 0,
|
|
98
|
+
obj.mm ?? 0,
|
|
99
|
+
obj.ss ?? 0
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return d.getFullYear() === (obj.YYYY ?? d.getFullYear()) &&
|
|
103
|
+
d.getMonth() === (obj.MM ?? 1) - 1 &&
|
|
104
|
+
d.getDate() === (obj.DD ?? 1) &&
|
|
105
|
+
d.getHours() === (obj.HH ?? 0) &&
|
|
106
|
+
d.getMinutes() === (obj.mm ?? 0) &&
|
|
107
|
+
d.getSeconds() === (obj.ss ?? 0)
|
|
108
|
+
? d
|
|
109
|
+
: null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const convertDateFormat = (value, fromFormat, toFormat = "YYYY-MM-DD HH:mm:ss") => {
|
|
113
|
+
const d = parseDate(value, fromFormat);
|
|
114
|
+
return d ? formatDate(d, toFormat) : null;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
export const formatDate = (value, format = "YYYY-MM-DD HH:mm:ss", inputFormat) => {
|
|
119
|
+
const d = inputFormat ? parseDate(value, inputFormat) : new Date(value);
|
|
120
|
+
|
|
121
|
+
if (!d || Number.isNaN(d.getTime()))
|
|
122
|
+
return null;
|
|
123
|
+
|
|
124
|
+
const pad = n => String(n).padStart(2, "0");
|
|
125
|
+
|
|
126
|
+
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, t => ({
|
|
127
|
+
YYYY: d.getFullYear(),
|
|
128
|
+
MM: pad(d.getMonth() + 1),
|
|
129
|
+
DD: pad(d.getDate()),
|
|
130
|
+
HH: pad(d.getHours()),
|
|
131
|
+
mm: pad(d.getMinutes()),
|
|
132
|
+
ss: pad(d.getSeconds())
|
|
133
|
+
})[t]);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const isValidDate = d => !Number.isNaN(new Date(d).getTime());
|
|
137
|
+
|
|
138
|
+
export const addDays = (d, n) => (d = new Date(d), d.setDate(d.getDate() + n), d);
|
|
139
|
+
|
|
140
|
+
export const addMonths = (d, n) => (d = new Date(d), d.setMonth(d.getMonth() + n), d);
|
|
141
|
+
|
|
142
|
+
export const addYears = (d, n) => (d = new Date(d), d.setFullYear(d.getFullYear() + n), d);
|
|
143
|
+
|
|
144
|
+
export const addHours = (d, n) => (d = new Date(d), d.setHours(d.getHours() + n), d);
|
|
145
|
+
|
|
146
|
+
export const addMinutes = (d, n) => (d = new Date(d), d.setMinutes(d.getMinutes() + n), d);
|
|
147
|
+
|
|
148
|
+
export const addSeconds = (d, n) => (d = new Date(d), d.setSeconds(d.getSeconds() + n), d);
|
|
149
|
+
|
|
150
|
+
export const isBefore = (a, b) => new Date(a) < new Date(b);
|
|
151
|
+
|
|
152
|
+
export const isAfter = (a, b) => new Date(a) > new Date(b);
|
|
153
|
+
|
|
154
|
+
export const isSameDay = (a, b) => format(a, "YYYYMMDD") === format(b, "YYYYMMDD");
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const entities = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'"': '"',
|
|
6
|
+
"'": ''',
|
|
7
|
+
'©': '©',
|
|
8
|
+
'®': '®',
|
|
9
|
+
'™': '™',
|
|
10
|
+
'€': '€',
|
|
11
|
+
'£': '£',
|
|
12
|
+
'¥': '¥',
|
|
13
|
+
'¢': '¢'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const htmlEncode = s => String(s ?? '').replace(/[&<>"'©®™€£¥¢]/g, c => entities[c]);
|
|
18
|
+
|
|
19
|
+
export const createCells = (obj, tag = "td") =>
|
|
20
|
+
Object.values(obj).map(v => `<${tag}>${v ?? ""}</${tag}>`).join("");
|
|
21
|
+
|
|
22
|
+
export const createHeaders = obj =>
|
|
23
|
+
Object.keys(obj).map(k => `<th>${k}</th>`).join("");
|
|
24
|
+
|
|
25
|
+
export const createHTML = (data, attrs = {}, before = "") =>
|
|
26
|
+
!Array.isArray(data) || !data.length
|
|
27
|
+
? ""
|
|
28
|
+
: `${before}<table ${Object.entries(attrs).map(([k, v]) => `${k}="${v}"`).join(" ")}>
|
|
29
|
+
<thead><tr>${createHeaders(data[0])}</tr></thead>
|
|
30
|
+
<tbody>${data.map(r => `<tr>${createCells(r)}</tr>`).join("")}</tbody>
|
|
31
|
+
</table>`;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export const processTemplateHtml = (html, { forJsonStorage = true, escapeHtml = false } = {}) =>
|
|
36
|
+
String(html ?? "")
|
|
37
|
+
.replace(forJsonStorage ? /[\r\n\t\f]/g : /$^/, c => ({ "\r": "\\r", "\n": "\\n", "\t": "\\t", "\f": "\\f" }[c]))
|
|
38
|
+
.replace(forJsonStorage ? /(?<!\\)["']/g : /$^/, c => `\\${c}`)
|
|
39
|
+
.replace(escapeHtml ? /[&<>"']/g : /$^/, c => entities[c]);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {lowerCase,upperCase,sentenceCase,titleCase,camelCase,pascalCase,snakeCase,kebabCase } from "./string.helper";
|
|
2
|
+
|
|
3
|
+
export const normalizeKey = (key, type = "lower", separator = "") => ({
|
|
4
|
+
lower: lowerCase,
|
|
5
|
+
upper: upperCase,
|
|
6
|
+
sentence: sentenceCase,
|
|
7
|
+
title: titleCase,
|
|
8
|
+
camel: camelCase,
|
|
9
|
+
pascal: pascalCase,
|
|
10
|
+
snake: snakeCase,
|
|
11
|
+
kebab: kebabCase
|
|
12
|
+
}[type]?.(key)?.replace(/[\s_-]+/g, separator) ?? key);
|
|
13
|
+
|
|
14
|
+
export const normalizeObjectKeys = (obj, type = "lower", separator = "") =>
|
|
15
|
+
Object.fromEntries(Object.entries(obj).map(([k, v]) => [normalizeKey(k, type, separator), v]));
|
|
File without changes
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const mapPlaceholdersToIndexes = s => String(s || '').replace(/\{([^{}]+)\}/g, ((m, i) => (a, b) => ((b = b.trim()), !b ? a : /^\d+$/.test(b) ? `{${b}}` : `{${m.has(b) ? m.get(b) : (m.set(b, i++), m.get(b))}}`))(new Map(), 0));
|
|
2
|
+
|
|
3
|
+
export const mapIndexesToValues = (s, paramArr) => String(s || '').replace(/\{(\d+)\}/g, (m, i) => paramArr[Number(i)] || '');
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { IsNullOrEmpty } from "./validation.helper";
|
|
2
|
+
|
|
3
|
+
export const ReturnValidString = (x) => !IsNullOrEmpty(x) ? String(x) : '';
|
|
4
|
+
|
|
5
|
+
export const trimRAndLSpaces = str => (typeof str === 'string' ? str.trim() : str);
|
|
6
|
+
|
|
7
|
+
export const stripHtmlTags = input => typeof input === 'string' ? input.replace(/<[^>]+>/g, '') : input;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export const stringToBoolean = s => typeof s !== "string" ? s : ({true:1,yes:1,1:1,false:0,no:0,0:0}[s.trim().toLowerCase()] ?? !!s);
|
|
11
|
+
|
|
12
|
+
export const findAllOccurence = (str, search) => { const r = new RegExp(search, "gi"), a = []; for (let m; (m = r.exec(str));) a.push(m.index); return a; };
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const keypattern = (arr, pattern = '@', wrap = true) => {
|
|
17
|
+
return arr.map(key =>
|
|
18
|
+
wrap ? `${pattern}${key}${pattern}` : `${pattern}${key}`
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const str_replaceReg = (str, searchArr, replacement, isKeyPair = false) => {
|
|
23
|
+
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
24
|
+
|
|
25
|
+
let result = str;
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < searchArr.length; i++) {
|
|
28
|
+
const key = searchArr[i];
|
|
29
|
+
const value = isKeyPair ? replacement[key] : replacement[i];
|
|
30
|
+
|
|
31
|
+
result = result.replace(new RegExp(escapeRegExp(key), 'gi'), value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Replace placeholders in a string using either an array or an object via str_replaceReg.
|
|
41
|
+
* - If replacements is an object, set isKeyPair=true to map keys to values.
|
|
42
|
+
* - If replacements is an array, provide searchArr and replacementArr in order.
|
|
43
|
+
* @param {string} original - Source string
|
|
44
|
+
* @param {Array|string|Object} searchOrReplacements - Array of search terms or an object of key->value
|
|
45
|
+
* @param {Array} [replacementArr] - Array of replacement values (used when searchOrReplacements is Array)
|
|
46
|
+
* @param {boolean} [isKeyPair=false] - Treat replacements as key-value pairs (object mode)
|
|
47
|
+
* @param {string} [pattern='@'] - Placeholder wrapper, e.g., '@key@'
|
|
48
|
+
* @param {boolean} [isBeforeAfter=true] - Wrap search tokens with pattern before and after
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
export const replaceDollarPlaceholders = (input, search, startIndex = 0) => {
|
|
52
|
+
if (typeof input !== 'string') return input;
|
|
53
|
+
|
|
54
|
+
const tokens = Array.isArray(search) ? search : [search];
|
|
55
|
+
|
|
56
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
57
|
+
const regex = new RegExp(tokens.map(escape).join('|'), 'g');
|
|
58
|
+
|
|
59
|
+
if (startIndex === -1) {
|
|
60
|
+
const matches = [];
|
|
61
|
+
let m;
|
|
62
|
+
|
|
63
|
+
while ((m = regex.exec(input)) !== null) {
|
|
64
|
+
matches.push({ index: m.index, match: m[0] });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return matches;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let counter = startIndex;
|
|
71
|
+
|
|
72
|
+
return input.replace(regex, () => {
|
|
73
|
+
counter += 1;
|
|
74
|
+
return `$${counter}`;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export const strRepArrORJsonObj = (
|
|
80
|
+
originalStr,
|
|
81
|
+
obj,
|
|
82
|
+
isKeyPair = false,
|
|
83
|
+
pattern = '@',
|
|
84
|
+
wrap = true
|
|
85
|
+
) => {
|
|
86
|
+
const keys = _.keys(obj);
|
|
87
|
+
|
|
88
|
+
const searchArr = keypattern(keys, pattern, wrap);
|
|
89
|
+
|
|
90
|
+
return str_replaceReg(
|
|
91
|
+
originalStr,
|
|
92
|
+
searchArr,
|
|
93
|
+
obj,
|
|
94
|
+
isKeyPair
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const words = s => String(s ?? '').trim().match(/[A-Za-z0-9]+/g) || [];
|
|
99
|
+
|
|
100
|
+
export const upperCase = s => String(s ?? '').toUpperCase();
|
|
101
|
+
|
|
102
|
+
export const lowerCase = s => String(s ?? '').toLowerCase();
|
|
103
|
+
|
|
104
|
+
export const sentenceCase = s => (s = String(s ?? '').trim(), s ? s[0].toUpperCase() + s.slice(1).toLowerCase() : '');
|
|
105
|
+
|
|
106
|
+
export const titleCase = s => words(s).map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(' ');
|
|
107
|
+
|
|
108
|
+
export const camelCase = s => words(s).map((w, i) => i ? w[0].toUpperCase() + w.slice(1).toLowerCase() : w.toLowerCase()).join('');
|
|
109
|
+
|
|
110
|
+
export const pascalCase = s => words(s).map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join('');
|
|
111
|
+
|
|
112
|
+
export const snakeCase = s => words(s).map(w => w.toLowerCase()).join('_');
|
|
113
|
+
|
|
114
|
+
export const kebabCase = s => words(s).map(w => w.toLowerCase()).join('-');
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Foundation/Helpers/time.helper.js
|
|
2
|
+
|
|
3
|
+
// -------------------------------
|
|
4
|
+
// CURRENT TIME
|
|
5
|
+
// -------------------------------
|
|
6
|
+
export const now = () => new Date();
|
|
7
|
+
|
|
8
|
+
export const timestamp = () => Date.now();
|
|
9
|
+
|
|
10
|
+
// -------------------------------
|
|
11
|
+
// FORMAT DATE
|
|
12
|
+
// -------------------------------
|
|
13
|
+
export const format = (d,f="YYYY-MM-DD HH:mm:ss") => {
|
|
14
|
+
d=new Date(d);
|
|
15
|
+
const p=n=>String(n).padStart(2,"0");
|
|
16
|
+
return f.replace(/YYYY|MM|DD|HH|mm|ss/g,k=>({
|
|
17
|
+
YYYY:d.getFullYear(),
|
|
18
|
+
MM:p(d.getMonth()+1),
|
|
19
|
+
DD:p(d.getDate()),
|
|
20
|
+
HH:p(d.getHours()),
|
|
21
|
+
mm:p(d.getMinutes()),
|
|
22
|
+
ss:p(d.getSeconds())
|
|
23
|
+
}[k]));
|
|
24
|
+
};
|
|
25
|
+
// -------------------------------
|
|
26
|
+
// TIME DIFFERENCE
|
|
27
|
+
// -------------------------------
|
|
28
|
+
export const timeDifference = (a,b=new Date()) => {
|
|
29
|
+
const d=Math.abs(new Date(b)-new Date(a));
|
|
30
|
+
return {
|
|
31
|
+
milliseconds:d,
|
|
32
|
+
seconds:Math.floor(d/1e3),
|
|
33
|
+
minutes:Math.floor(d/6e4),
|
|
34
|
+
hours:Math.floor(d/36e5),
|
|
35
|
+
days:Math.floor(d/864e5)
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// -------------------------------
|
|
40
|
+
// TIME AGO
|
|
41
|
+
// -------------------------------
|
|
42
|
+
export const timeAgo = d => {
|
|
43
|
+
const s=Math.floor((Date.now()-new Date(d))/1e3);
|
|
44
|
+
const m=s/60|0,h=m/60|0,da=h/24|0,mo=da/30|0,y=da/365|0;
|
|
45
|
+
return s<60?`${s}s ago`:m<60?`${m}m ago`:h<24?`${h}h ago`:da<30?`${da}d ago`:mo<12?`${mo}mo ago`:`${y}y ago`;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// -------------------------------
|
|
49
|
+
// ADD TIME
|
|
50
|
+
// -------------------------------
|
|
51
|
+
export const addTime = (d,{seconds=0,minutes=0,hours=0,days=0}) =>
|
|
52
|
+
new Date(new Date(d).setSeconds(new Date(d).getSeconds()+seconds)
|
|
53
|
+
+minutes*6e4+hours*36e5+days*864e5);
|
|
54
|
+
|
|
55
|
+
// -------------------------------
|
|
56
|
+
// SUBTRACT TIME
|
|
57
|
+
// -------------------------------
|
|
58
|
+
export const subtractTime = (d,v) =>
|
|
59
|
+
addTime(d,{seconds:-(v.seconds||0),minutes:-(v.minutes||0),hours:-(v.hours||0),days:-(v.days||0)});
|
|
60
|
+
|
|
61
|
+
// -------------------------------
|
|
62
|
+
// CHECKS
|
|
63
|
+
// -------------------------------
|
|
64
|
+
export const isExpired = d => new Date(d) < Date.now();
|
|
65
|
+
export const isFuture = d => new Date(d) > Date.now();
|
|
66
|
+
// -------------------------------
|
|
67
|
+
// START / END OF DAY
|
|
68
|
+
// -------------------------------
|
|
69
|
+
export const startOfDay = (d=new Date()) => (d=new Date(d),d.setHours(0,0,0,0),d);
|
|
70
|
+
|
|
71
|
+
export const endOfDay = (d=new Date()) => (d=new Date(d),d.setHours(23,59,59,999),d);
|
|
72
|
+
|
|
73
|
+
// -------------------------------
|
|
74
|
+
// DURATION (ms → breakdown)
|
|
75
|
+
// -------------------------------
|
|
76
|
+
export const duration = ms => ({
|
|
77
|
+
seconds:Math.floor(ms/1e3),
|
|
78
|
+
minutes:Math.floor(ms/6e4),
|
|
79
|
+
hours:Math.floor(ms/36e5),
|
|
80
|
+
days:Math.floor(ms/864e5)
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const sleep = (h = 0, m = 0, s = 0) => new Promise(r => setTimeout(r, (h * 3600 + m * 60 + s) * 1000));
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
export const isUndefined = (x) =>typeof x === undefined;
|
|
3
|
+
|
|
4
|
+
export const isEmpty = value => value == null ? true : ((typeof value === 'string' || Array.isArray(value)) ? value.length === 0 : Object.keys(value).length === 0);
|
|
5
|
+
|
|
6
|
+
export const IsNullOrEmpty = x => (isUndefined(x) || x === null || x === false || x === "" || (typeof x === 'number' ? isNaN(x) : isEmpty(x)) || x.length === 0 || (x?.length === 'number' && x.length === 0) || (typeof x === 'string' && x.trim().length === 0));
|
|
7
|
+
|
|
8
|
+
export const IsNullOrEmptyNZero = x => (isUndefined(x) || x === null || x === false || x === "" || (typeof x === 'number' ? x == 0 ? true : isEmpty(x) : x === '') || (x?.length === 'number' && x.length === 0 || (typeof x === 'string' && x.trim().length === 0)));
|
|
9
|
+
|
|
10
|
+
export const IsEmpty = x => (isUndefined(x) || x === false || x === "" || x.length === 0);
|
|
11
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
# AskAIOrbit
|
|
2
|
+
Since this has evolved beyond just a utility library and now includes: SQL Query Builder ORM-like CRUD Auto SQL Generator Auto Index Optimizer Schema Validation Retry Framework Connection Pooling Database Engine HTML/CSV Utilities Security Utilities Response Builder Template Engine Notification Helpers
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
PROJECT="AskAIOrbit"
|
|
4
|
+
|
|
5
|
+
echo "Creating $PROJECT structure..."
|
|
6
|
+
|
|
7
|
+
mkdir -p "$PROJECT"
|
|
8
|
+
cd "$PROJECT" || exit
|
|
9
|
+
|
|
10
|
+
############################################
|
|
11
|
+
# CORE
|
|
12
|
+
############################################
|
|
13
|
+
mkdir -p Core/{Bootstrap,Configuration,Environment,CLI,PluginManager,ServiceContainer}
|
|
14
|
+
|
|
15
|
+
############################################
|
|
16
|
+
# FOUNDATION
|
|
17
|
+
############################################
|
|
18
|
+
mkdir -p Foundation/Helpers
|
|
19
|
+
mkdir -p Foundation/{Constants,Enums,Exceptions,Types}
|
|
20
|
+
|
|
21
|
+
touch Foundation/Helpers/array.helper.js
|
|
22
|
+
touch Foundation/Helpers/object.helper.js
|
|
23
|
+
touch Foundation/Helpers/string.helper.js
|
|
24
|
+
touch Foundation/Helpers/number.helper.js
|
|
25
|
+
touch Foundation/Helpers/date.helper.js
|
|
26
|
+
touch Foundation/Helpers/time.helper.js
|
|
27
|
+
touch Foundation/Helpers/random.helper.js
|
|
28
|
+
touch Foundation/Helpers/file.helper.js
|
|
29
|
+
touch Foundation/Helpers/csv.helper.js
|
|
30
|
+
touch Foundation/Helpers/html.helper.js
|
|
31
|
+
touch Foundation/Helpers/json.helper.js
|
|
32
|
+
touch Foundation/Helpers/ip.helper.js
|
|
33
|
+
touch Foundation/Helpers/validation.helper.js
|
|
34
|
+
touch Foundation/Helpers/request.helper.js
|
|
35
|
+
touch Foundation/Helpers/response.helper.js
|
|
36
|
+
touch Foundation/Helpers/pagination.helper.js
|
|
37
|
+
touch Foundation/Helpers/collection.helper.js
|
|
38
|
+
touch Foundation/Helpers/map.helper.js
|
|
39
|
+
touch Foundation/Helpers/conversion.helper.js
|
|
40
|
+
touch Foundation/Helpers/search.helper.js
|
|
41
|
+
touch Foundation/Helpers/utility.helper.js
|
|
42
|
+
|
|
43
|
+
############################################
|
|
44
|
+
# DATABASE
|
|
45
|
+
############################################
|
|
46
|
+
mkdir -p Database/{ORM,Models,Repository,Schema,Migration,Seeder,Drivers}
|
|
47
|
+
mkdir -p Database/QueryBuilder
|
|
48
|
+
mkdir -p Database/Persistence
|
|
49
|
+
mkdir -p Database/Execution
|
|
50
|
+
mkdir -p Database/Connection
|
|
51
|
+
|
|
52
|
+
touch Database/QueryBuilder/query.builder.js
|
|
53
|
+
touch Database/QueryBuilder/where.builder.js
|
|
54
|
+
touch Database/QueryBuilder/join.builder.js
|
|
55
|
+
touch Database/QueryBuilder/sql.generator.js
|
|
56
|
+
touch Database/QueryBuilder/metadata.parser.js
|
|
57
|
+
|
|
58
|
+
touch Database/Persistence/persist.js
|
|
59
|
+
touch Database/Persistence/bulkInsert.js
|
|
60
|
+
touch Database/Persistence/bulkUpdate.js
|
|
61
|
+
touch Database/Persistence/bulkDelete.js
|
|
62
|
+
|
|
63
|
+
touch Database/Execution/executeQuery.js
|
|
64
|
+
touch Database/Execution/executeWithRetry.js
|
|
65
|
+
touch Database/Execution/postgres.executor.js
|
|
66
|
+
touch Database/Execution/mysql.executor.js
|
|
67
|
+
touch Database/Execution/transaction.manager.js
|
|
68
|
+
|
|
69
|
+
touch Database/Connection/pool.manager.js
|
|
70
|
+
touch Database/Connection/connection.manager.js
|
|
71
|
+
touch Database/Connection/retry.framework.js
|
|
72
|
+
|
|
73
|
+
############################################
|
|
74
|
+
# SECURITY
|
|
75
|
+
############################################
|
|
76
|
+
mkdir -p Security/{Authentication,Authorization,Encryption,JWT,Audit,RateLimiter,Sanitizer,SQLProtection,XSSProtection,Validation}
|
|
77
|
+
|
|
78
|
+
############################################
|
|
79
|
+
# COMMUNICATION
|
|
80
|
+
############################################
|
|
81
|
+
mkdir -p Communication/{SMS,Notification,Queue,WhatsApp,WebSocket}
|
|
82
|
+
mkdir -p Communication/Email
|
|
83
|
+
|
|
84
|
+
touch Communication/Email/template.engine.js
|
|
85
|
+
touch Communication/Email/html.processor.js
|
|
86
|
+
touch Communication/Email/mail.sender.js
|
|
87
|
+
touch Communication/Email/template.builder.js
|
|
88
|
+
|
|
89
|
+
############################################
|
|
90
|
+
# HTTP
|
|
91
|
+
############################################
|
|
92
|
+
mkdir -p HTTP/{Request,Response,Middleware,Pagination,API,StatusCodes}
|
|
93
|
+
|
|
94
|
+
############################################
|
|
95
|
+
# DATA PROCESSING
|
|
96
|
+
############################################
|
|
97
|
+
mkdir -p DataProcessing/{Excel,PDF,Reports,Import,Export}
|
|
98
|
+
mkdir -p DataProcessing/CSV
|
|
99
|
+
|
|
100
|
+
touch DataProcessing/CSV/csv.reader.js
|
|
101
|
+
touch DataProcessing/CSV/csv.writer.js
|
|
102
|
+
touch DataProcessing/CSV/csv.importer.js
|
|
103
|
+
touch DataProcessing/CSV/csv.exporter.js
|
|
104
|
+
|
|
105
|
+
############################################
|
|
106
|
+
# AI
|
|
107
|
+
############################################
|
|
108
|
+
mkdir -p AI/{DocumentationAI,QueryAI,CodeGenAI,ReviewAI,RefactorAI,TestAI,MigrationAI,ChatAI}
|
|
109
|
+
|
|
110
|
+
############################################
|
|
111
|
+
# ENTERPRISE
|
|
112
|
+
############################################
|
|
113
|
+
mkdir -p Enterprise/{ERP,CRM,HRMS,Inventory,POS,Accounting,Payroll}
|
|
114
|
+
|
|
115
|
+
############################################
|
|
116
|
+
# DEVELOPER
|
|
117
|
+
############################################
|
|
118
|
+
mkdir -p Developer/{Logger,Scheduler,Storage,Cache,Monitoring,Testing,Benchmark,Debugger}
|
|
119
|
+
|
|
120
|
+
############################################
|
|
121
|
+
# CLOUD
|
|
122
|
+
############################################
|
|
123
|
+
mkdir -p Cloud/{Docker,Kubernetes,AWS,Azure,GCP,CICD}
|
|
124
|
+
|
|
125
|
+
echo ""
|
|
126
|
+
echo "✔ AskAIOrbit structure created successfully"
|
|
127
|
+
echo ""
|
|
128
|
+
|
|
129
|
+
tree .
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ask-ai-orbit",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "enterprise orbit ai",
|
|
5
|
+
"main": "app.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node app.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/kaiyumnadaf/AskAIOrbit.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"backend",
|
|
15
|
+
"application",
|
|
16
|
+
"framework"
|
|
17
|
+
],
|
|
18
|
+
"author": "Kaiyum Nadaf",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/kaiyumnadaf/AskAIOrbit/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/kaiyumnadaf/AskAIOrbit#readme"
|
|
24
|
+
}
|