drapcode-utility 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.
- package/build/encryption/index.d.ts +15 -0
- package/build/encryption/index.js +255 -0
- package/build/errors/app-error.d.ts +6 -0
- package/build/errors/app-error.js +30 -0
- package/build/errors/axios-error.d.ts +13 -0
- package/build/errors/axios-error.js +78 -0
- package/build/errors/bad-request-error.d.ts +9 -0
- package/build/errors/bad-request-error.js +32 -0
- package/build/errors/custom-error.d.ts +8 -0
- package/build/errors/custom-error.js +26 -0
- package/build/errors/not-found.d.ts +8 -0
- package/build/errors/not-found.js +31 -0
- package/build/index.d.ts +17 -0
- package/build/index.js +29 -0
- package/build/middlewares/api-limiter.d.ts +1 -0
- package/build/middlewares/api-limiter.js +21 -0
- package/build/middlewares/error-logger.d.ts +3 -0
- package/build/middlewares/error-logger.js +74 -0
- package/build/middlewares/interceptor-logger-new.d.ts +2 -0
- package/build/middlewares/interceptor-logger-new.js +54 -0
- package/build/middlewares/interceptor-logger.d.ts +2 -0
- package/build/middlewares/interceptor-logger.js +42 -0
- package/build/middlewares/redis/request-log.d.ts +1 -0
- package/build/middlewares/redis/request-log.js +79 -0
- package/build/utils/check-error.d.ts +9 -0
- package/build/utils/check-error.js +188 -0
- package/build/utils/date-util.d.ts +8 -0
- package/build/utils/date-util.js +104 -0
- package/build/utils/prepare-query.d.ts +132 -0
- package/build/utils/prepare-query.js +94 -0
- package/build/utils/query-parser.d.ts +11 -0
- package/build/utils/query-parser.js +778 -0
- package/build/utils/query-paser-new.d.ts +1 -0
- package/build/utils/query-paser-new.js +682 -0
- package/build/utils/util.d.ts +27 -0
- package/build/utils/util.js +373 -0
- package/build/utils/uuid-generator.d.ts +1 -0
- package/build/utils/uuid-generator.js +65 -0
- package/package.json +47 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const validateString: (str: string) => false | "String should not contain special characters" | "String should not contain any number";
|
|
2
|
+
export declare const camelize: (str: string) => string;
|
|
3
|
+
export declare const clearSpaceAndReformat: (text: string, separator?: string | undefined) => string;
|
|
4
|
+
export declare const isEmpty: (obj: any) => boolean;
|
|
5
|
+
export declare const isEmptyObject: (object: any) => boolean;
|
|
6
|
+
export declare const isObject: (item: any) => any;
|
|
7
|
+
export declare const checkValidArray: (object: any) => any;
|
|
8
|
+
export declare const dynamicSort: (property: any) => (a: any, b: any) => number;
|
|
9
|
+
export declare const snakeCaseToTitleCase: (str: string, checkForUnderscore?: boolean) => string;
|
|
10
|
+
export declare const validateEmail: (email: string) => false | RegExpMatchArray | null;
|
|
11
|
+
export declare const validateUuidString: (uuid: string) => false | RegExpMatchArray | null;
|
|
12
|
+
export declare const getSpecialCharectorReplacedExpression: (expression: string) => string;
|
|
13
|
+
export declare const expressionToString: (ex: string) => string;
|
|
14
|
+
export declare const stringToExpression: (str: string) => string;
|
|
15
|
+
export declare const cleanCollectionAndFieldName: (str: string) => string;
|
|
16
|
+
export declare const formatCollectionAndFieldName: (str: string) => string;
|
|
17
|
+
export declare const restructureData: (data: any) => any[];
|
|
18
|
+
export declare const checkAndCompareValue: (input1: any, input2: any) => boolean;
|
|
19
|
+
export declare const arraysEqual: (array1: any, array2: any) => boolean;
|
|
20
|
+
export declare const convertItemToArray: (itemValue: any) => any[];
|
|
21
|
+
export declare const validateAlphanumericString: (str: string) => false | "String should contain only numbers and letters";
|
|
22
|
+
export declare const formatCustomCSSClasses: (projectCustomCSSClasses: any) => string;
|
|
23
|
+
export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, sessionValue: any, envConstants: any, sessionFormValue: any) => string;
|
|
24
|
+
export declare const parseJsonString: (str: string) => any;
|
|
25
|
+
export declare const parseValueFromData: (data: any, fieldName: string) => any;
|
|
26
|
+
export declare const unflattenObject: (obj: any) => {};
|
|
27
|
+
export declare const replaceTransferObjectValueIntoExpression: (expression: string, transferObject: any) => string;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
|
|
7
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
var validateString = function (str) {
|
|
9
|
+
var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
|
|
10
|
+
var isNumber = str.match(/\d+/g);
|
|
11
|
+
if (specialChar.test(str))
|
|
12
|
+
return "String should not contain special characters";
|
|
13
|
+
if (isNumber)
|
|
14
|
+
return "String should not contain any number";
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
exports.validateString = validateString;
|
|
18
|
+
var camelize = function (str) {
|
|
19
|
+
str = exports.clearSpaceAndReformat(str);
|
|
20
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
21
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.camelize = camelize;
|
|
25
|
+
var clearSpaceAndReformat = function (text, separator) {
|
|
26
|
+
if (!text) {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
return text
|
|
30
|
+
.toString()
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.replace(/\s+/g, separator ? separator : "");
|
|
33
|
+
};
|
|
34
|
+
exports.clearSpaceAndReformat = clearSpaceAndReformat;
|
|
35
|
+
var isEmpty = function (obj) {
|
|
36
|
+
return Object.keys(obj).length === 0;
|
|
37
|
+
};
|
|
38
|
+
exports.isEmpty = isEmpty;
|
|
39
|
+
var isEmptyObject = function (object) {
|
|
40
|
+
return Object.keys(object).length === 0 && object.constructor === Object;
|
|
41
|
+
};
|
|
42
|
+
exports.isEmptyObject = isEmptyObject;
|
|
43
|
+
var isObject = function (item) {
|
|
44
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
45
|
+
};
|
|
46
|
+
exports.isObject = isObject;
|
|
47
|
+
var checkValidArray = function (object) {
|
|
48
|
+
return (object &&
|
|
49
|
+
object !== "null" &&
|
|
50
|
+
object !== undefined &&
|
|
51
|
+
Object.keys(object).length > 0);
|
|
52
|
+
};
|
|
53
|
+
exports.checkValidArray = checkValidArray;
|
|
54
|
+
var dynamicSort = function (property) {
|
|
55
|
+
return function (a, b) {
|
|
56
|
+
var result = 0;
|
|
57
|
+
if (a[property] &&
|
|
58
|
+
b[property] &&
|
|
59
|
+
a[property] !== "undefined" &&
|
|
60
|
+
b[property] !== "undefined") {
|
|
61
|
+
if (typeof a[property] === "number" || typeof b[property] === "number") {
|
|
62
|
+
result =
|
|
63
|
+
a[property] < b[property] ? -1 : a[property] > b[property] ? 1 : 0;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
result =
|
|
67
|
+
a[property].toLowerCase() < b[property].toLowerCase()
|
|
68
|
+
? -1
|
|
69
|
+
: a[property].toLowerCase() > b[property].toLowerCase()
|
|
70
|
+
? 1
|
|
71
|
+
: 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
result = 0;
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
exports.dynamicSort = dynamicSort;
|
|
81
|
+
var snakeCaseToTitleCase = function (str, checkForUnderscore) {
|
|
82
|
+
if (checkForUnderscore === void 0) { checkForUnderscore = false; }
|
|
83
|
+
if (!str)
|
|
84
|
+
return str;
|
|
85
|
+
if (typeof str === "string" && !checkForUnderscore) {
|
|
86
|
+
return str
|
|
87
|
+
.toLowerCase()
|
|
88
|
+
.split("_")
|
|
89
|
+
.map(function (word) {
|
|
90
|
+
return word.replace(word[0], word[0].toUpperCase());
|
|
91
|
+
})
|
|
92
|
+
.join(" ");
|
|
93
|
+
}
|
|
94
|
+
return str;
|
|
95
|
+
};
|
|
96
|
+
exports.snakeCaseToTitleCase = snakeCaseToTitleCase;
|
|
97
|
+
var validateEmail = function (email) {
|
|
98
|
+
if (!email) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
var regexCode = new RegExp(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/);
|
|
102
|
+
return email.match(regexCode);
|
|
103
|
+
};
|
|
104
|
+
exports.validateEmail = validateEmail;
|
|
105
|
+
var validateUuidString = function (uuid) {
|
|
106
|
+
if (!uuid)
|
|
107
|
+
return false;
|
|
108
|
+
var regexCode = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i);
|
|
109
|
+
return uuid.match(regexCode);
|
|
110
|
+
};
|
|
111
|
+
exports.validateUuidString = validateUuidString;
|
|
112
|
+
var getSpecialCharectorReplacedExpression = function (expression) {
|
|
113
|
+
return expression
|
|
114
|
+
.replace(/##@@##@@##/g, " ")
|
|
115
|
+
.replace(/##@@##@@@@/g, ">")
|
|
116
|
+
.replace(/@@@@##@@@@/g, "<")
|
|
117
|
+
.replace(/U\+000A/g, "<br/>");
|
|
118
|
+
};
|
|
119
|
+
exports.getSpecialCharectorReplacedExpression = getSpecialCharectorReplacedExpression;
|
|
120
|
+
var expressionToString = function (ex) {
|
|
121
|
+
return ex
|
|
122
|
+
.replace(/##@@##@@##/g, " ")
|
|
123
|
+
.replace(/##@@##@@@@/g, ">")
|
|
124
|
+
.replace(/@@@@##@@@@/g, "<")
|
|
125
|
+
.replace(/U\+0022/g, '"')
|
|
126
|
+
.replace(/U\+0027/g, "'")
|
|
127
|
+
.replace(/U\+000A/g, "\n");
|
|
128
|
+
};
|
|
129
|
+
exports.expressionToString = expressionToString;
|
|
130
|
+
var stringToExpression = function (str) {
|
|
131
|
+
return str
|
|
132
|
+
.replace(/ /g, "##@@##@@##")
|
|
133
|
+
.replace(/>/g, "##@@##@@@@")
|
|
134
|
+
.replace(/</g, "@@@@##@@@@")
|
|
135
|
+
.replace(/\n/g, "U+000A")
|
|
136
|
+
.replace(/"/g, "U+0022")
|
|
137
|
+
.replace(/'/g, "U+0027");
|
|
138
|
+
};
|
|
139
|
+
exports.stringToExpression = stringToExpression;
|
|
140
|
+
var cleanCollectionAndFieldName = function (str) {
|
|
141
|
+
str = str.replace(/[^a-zA-Z0-9 ]/, "");
|
|
142
|
+
return str;
|
|
143
|
+
};
|
|
144
|
+
exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
|
|
145
|
+
var formatCollectionAndFieldName = function (str) {
|
|
146
|
+
var updateString = exports.cleanCollectionAndFieldName(str);
|
|
147
|
+
return exports.clearSpaceAndReformat(updateString.trim(), "_");
|
|
148
|
+
};
|
|
149
|
+
exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
|
|
150
|
+
var restructureData = function (data) {
|
|
151
|
+
if (!data)
|
|
152
|
+
return [];
|
|
153
|
+
var dataType = typeof data;
|
|
154
|
+
if (Array.isArray(data)) {
|
|
155
|
+
if (data.length) {
|
|
156
|
+
var firstEle = data[0];
|
|
157
|
+
if (!firstEle)
|
|
158
|
+
return [];
|
|
159
|
+
if (typeof firstEle === "string" || typeof firstEle === "number") {
|
|
160
|
+
return data.map(function (el) {
|
|
161
|
+
return { value: el };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return data;
|
|
165
|
+
}
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (dataType === "string" || dataType === "number") {
|
|
170
|
+
return [{ value: data }];
|
|
171
|
+
}
|
|
172
|
+
return [data];
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
exports.restructureData = restructureData;
|
|
176
|
+
var checkAndCompareValue = function (input1, input2) {
|
|
177
|
+
return Array.isArray(input2)
|
|
178
|
+
? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
|
|
179
|
+
: input1 === input2.value;
|
|
180
|
+
};
|
|
181
|
+
exports.checkAndCompareValue = checkAndCompareValue;
|
|
182
|
+
var arraysEqual = function (array1, array2) {
|
|
183
|
+
if (array1 instanceof Array && array2 instanceof Array) {
|
|
184
|
+
if (array1.length != array2.length)
|
|
185
|
+
return false;
|
|
186
|
+
for (var i = 0; i < array1.length; i++ // assert each element equal
|
|
187
|
+
)
|
|
188
|
+
if (!exports.arraysEqual(array1[i], array2[i]))
|
|
189
|
+
return false;
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
return array1 == array2; // if not both arrays, should be the same
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
exports.arraysEqual = arraysEqual;
|
|
197
|
+
var convertItemToArray = function (itemValue) {
|
|
198
|
+
if (Array.isArray(itemValue)) {
|
|
199
|
+
return itemValue;
|
|
200
|
+
}
|
|
201
|
+
return [itemValue];
|
|
202
|
+
};
|
|
203
|
+
exports.convertItemToArray = convertItemToArray;
|
|
204
|
+
var validateAlphanumericString = function (str) {
|
|
205
|
+
if (/[^a-zA-Z0-9 ]/.test(str)) {
|
|
206
|
+
return "String should contain only numbers and letters";
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
};
|
|
210
|
+
exports.validateAlphanumericString = validateAlphanumericString;
|
|
211
|
+
var formatCustomCSSClasses = function (projectCustomCSSClasses) {
|
|
212
|
+
if (!projectCustomCSSClasses || !Array.isArray(projectCustomCSSClasses)) {
|
|
213
|
+
return "";
|
|
214
|
+
}
|
|
215
|
+
var projectCustomCSSClassesData = "";
|
|
216
|
+
projectCustomCSSClasses.forEach(function (element) {
|
|
217
|
+
if (element.classProperty) {
|
|
218
|
+
var classWithProp = JSON.stringify(element.classProperty);
|
|
219
|
+
var unquotedClassWithProp = classWithProp
|
|
220
|
+
.replace(/"([^"]+)"/g, "$1")
|
|
221
|
+
.split(",")
|
|
222
|
+
.join(";");
|
|
223
|
+
projectCustomCSSClassesData += "" + (element.class.startsWith(".") ? element.class : "." + element.class) + (element.pseudoClass ? ":" + element.pseudoClass : "") + unquotedClassWithProp + " ";
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return projectCustomCSSClassesData;
|
|
227
|
+
};
|
|
228
|
+
exports.formatCustomCSSClasses = formatCustomCSSClasses;
|
|
229
|
+
var replaceDataValueIntoExpression = function (expression, data, user, sessionValue, envConstants, sessionFormValue) {
|
|
230
|
+
var _a;
|
|
231
|
+
var contentList = (_a = expression
|
|
232
|
+
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
233
|
+
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
234
|
+
var needle = "{{" + prop + "}}";
|
|
235
|
+
var dataOfItem = "";
|
|
236
|
+
if (prop.includes("current_user")) {
|
|
237
|
+
prop = prop.replace("current_user.", "");
|
|
238
|
+
if (Object.keys(user).length > 0) {
|
|
239
|
+
dataOfItem = exports.parseValueFromData(user, prop);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (prop.includes("current_session")) {
|
|
243
|
+
prop = prop.replace("current_session.", "");
|
|
244
|
+
if (Object.keys(sessionValue).length > 0) {
|
|
245
|
+
//Session will contain multi level data
|
|
246
|
+
dataOfItem = lodash_1.default.get(sessionValue, prop);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else if (prop.includes("form_data_session")) {
|
|
250
|
+
prop = prop.replace("form_data_session.", "");
|
|
251
|
+
if (Object.keys(sessionFormValue).length > 0) {
|
|
252
|
+
//Form Session will contain multi level data
|
|
253
|
+
dataOfItem = lodash_1.default.get(sessionFormValue, prop);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (prop.includes("environment_variable")) {
|
|
257
|
+
prop = prop.replace("environment_variable.", "");
|
|
258
|
+
if (Object.keys(envConstants).length > 0) {
|
|
259
|
+
var selectedConstant = envConstants.find(function (constant) { return constant.name === prop; });
|
|
260
|
+
dataOfItem = selectedConstant ? selectedConstant.value : "";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
if (Object.keys(data).length > 0) {
|
|
265
|
+
dataOfItem = exports.parseValueFromData(data, prop);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
expression = replaceValueInExpression(needle, dataOfItem, expression);
|
|
269
|
+
});
|
|
270
|
+
return expression;
|
|
271
|
+
};
|
|
272
|
+
exports.replaceDataValueIntoExpression = replaceDataValueIntoExpression;
|
|
273
|
+
var replaceValueInExpression = function (needle, replacement, expression) {
|
|
274
|
+
var match = new RegExp(needle, "ig");
|
|
275
|
+
replacement = replacement ? replacement : "";
|
|
276
|
+
return expression.replace(match, replacement);
|
|
277
|
+
};
|
|
278
|
+
var parseJsonString = function (str) {
|
|
279
|
+
try {
|
|
280
|
+
str = str
|
|
281
|
+
.replace(/\\n/g, "\\n")
|
|
282
|
+
.replace(/\\'/g, "\\'")
|
|
283
|
+
.replace(/\\"/g, '\\"')
|
|
284
|
+
.replace(/\\&/g, "\\&")
|
|
285
|
+
.replace(/\\r/g, "\\r")
|
|
286
|
+
.replace(/\\t/g, "\\t")
|
|
287
|
+
.replace(/\\b/g, "\\b")
|
|
288
|
+
.replace(/\\f/g, "\\f");
|
|
289
|
+
// Remove non-printable and other non-valid JSON characters
|
|
290
|
+
// eslint-disable-next-line no-control-regex
|
|
291
|
+
str = str.replace(/[\u0000-\u0019]+/g, "");
|
|
292
|
+
return JSON.parse(str);
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
console.log("Error: ", e);
|
|
296
|
+
return {};
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
exports.parseJsonString = parseJsonString;
|
|
300
|
+
var parseValueFromData = function (data, fieldName) {
|
|
301
|
+
var value = "";
|
|
302
|
+
if (fieldName && fieldName.includes(".")) {
|
|
303
|
+
var fullNameParts = fieldName.split(".");
|
|
304
|
+
var prefix_1 = "";
|
|
305
|
+
var stack = data || "";
|
|
306
|
+
for (var k = 0; k < fullNameParts.length; k++) {
|
|
307
|
+
prefix_1 = fullNameParts[k];
|
|
308
|
+
if (Array.isArray(stack)) {
|
|
309
|
+
stack[prefix_1] = stack.map(function (item) {
|
|
310
|
+
if (item[prefix_1])
|
|
311
|
+
return item[prefix_1];
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (stack && !stack[prefix_1]) {
|
|
315
|
+
stack[prefix_1] = "";
|
|
316
|
+
}
|
|
317
|
+
stack = stack[prefix_1];
|
|
318
|
+
}
|
|
319
|
+
value = stack ? stack : "";
|
|
320
|
+
if (Array.isArray(value)) {
|
|
321
|
+
value = value.filter(function () { return true; });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
value = data ? data[fieldName] : "";
|
|
326
|
+
}
|
|
327
|
+
if (value && Array.isArray(value) && typeof value[0] === "string") {
|
|
328
|
+
return value.join(", ");
|
|
329
|
+
}
|
|
330
|
+
if (value && typeof value === "number") {
|
|
331
|
+
return value.toString();
|
|
332
|
+
}
|
|
333
|
+
return value;
|
|
334
|
+
};
|
|
335
|
+
exports.parseValueFromData = parseValueFromData;
|
|
336
|
+
var unflattenObject = function (obj) {
|
|
337
|
+
var result = {}, temp, substrings, property, i;
|
|
338
|
+
for (property in obj) {
|
|
339
|
+
substrings = property.split(".");
|
|
340
|
+
temp = result;
|
|
341
|
+
for (i = 0; i < substrings.length - 1; i++) {
|
|
342
|
+
if (!(substrings[i] in temp)) {
|
|
343
|
+
if (isFinite(substrings[i + 1])) {
|
|
344
|
+
temp[substrings[i]] = [];
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
temp[substrings[i]] = {};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
temp = temp[substrings[i]];
|
|
351
|
+
}
|
|
352
|
+
temp[substrings[substrings.length - 1]] = obj[property];
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
};
|
|
356
|
+
exports.unflattenObject = unflattenObject;
|
|
357
|
+
var replaceTransferObjectValueIntoExpression = function (expression, transferObject) {
|
|
358
|
+
var _a;
|
|
359
|
+
if (transferObject && Object.keys(transferObject).length > 0) {
|
|
360
|
+
var contentList = (_a = expression
|
|
361
|
+
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
362
|
+
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
363
|
+
var needle = "{{" + prop + "}}";
|
|
364
|
+
var dataOfItem = "";
|
|
365
|
+
dataOfItem = transferObject[prop] ? transferObject[prop] : "";
|
|
366
|
+
expression = dataOfItem
|
|
367
|
+
? replaceValueInExpression(needle, dataOfItem, expression)
|
|
368
|
+
: expression;
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return expression;
|
|
372
|
+
};
|
|
373
|
+
exports.replaceTransferObjectValueIntoExpression = replaceTransferObjectValueIntoExpression;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const nextGeneratedString: (str: string, prepend: string, minLength: number, append: string, algorithm: string) => string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.nextGeneratedString = void 0;
|
|
7
|
+
var voca_1 = __importDefault(require("voca"));
|
|
8
|
+
var allowedAlphaNumericChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
9
|
+
var allowedNumericChars = "0123456789";
|
|
10
|
+
var nextGeneratedString = function (str, prepend, minLength, append, algorithm) {
|
|
11
|
+
var allowedChars = "";
|
|
12
|
+
if (algorithm === "alphanumeric") {
|
|
13
|
+
allowedChars = allowedAlphaNumericChars;
|
|
14
|
+
}
|
|
15
|
+
else if (algorithm === "numeric") {
|
|
16
|
+
allowedChars = allowedNumericChars;
|
|
17
|
+
}
|
|
18
|
+
var nextIds = calculateNext(str, allowedChars);
|
|
19
|
+
console.log("nextIds 1", nextIds);
|
|
20
|
+
if (!nextIds || nextIds.length === 0) {
|
|
21
|
+
nextIds = [0];
|
|
22
|
+
}
|
|
23
|
+
console.log("next 2", nextIds);
|
|
24
|
+
var r = [];
|
|
25
|
+
for (var _i = 0, nextIds_1 = nextIds; _i < nextIds_1.length; _i++) {
|
|
26
|
+
var char = nextIds_1[_i];
|
|
27
|
+
r.unshift(allowedChars[char]);
|
|
28
|
+
}
|
|
29
|
+
console.log("r 3", r);
|
|
30
|
+
var finalValue = r.join("");
|
|
31
|
+
console.log("finalValue 5", finalValue);
|
|
32
|
+
if (voca_1.default.isDigit(finalValue) && !+finalValue) {
|
|
33
|
+
r[0] = "1";
|
|
34
|
+
finalValue = r.join("");
|
|
35
|
+
}
|
|
36
|
+
console.log("finalValue", finalValue);
|
|
37
|
+
if (minLength) {
|
|
38
|
+
finalValue = voca_1.default.padLeft(finalValue, minLength, "0");
|
|
39
|
+
}
|
|
40
|
+
if (prepend) {
|
|
41
|
+
finalValue = "" + prepend + finalValue;
|
|
42
|
+
}
|
|
43
|
+
if (append) {
|
|
44
|
+
finalValue = "" + finalValue + append;
|
|
45
|
+
}
|
|
46
|
+
return finalValue;
|
|
47
|
+
};
|
|
48
|
+
exports.nextGeneratedString = nextGeneratedString;
|
|
49
|
+
var calculateNext = function (str, allowedChars) {
|
|
50
|
+
var nnext = str.split("").map(function (key, index) { return allowedChars.indexOf(key); });
|
|
51
|
+
console.log("final calculateNext", nnext);
|
|
52
|
+
nnext = nnext.reverse();
|
|
53
|
+
for (var i = 0; i < nnext.length; i++) {
|
|
54
|
+
var val = ++nnext[i];
|
|
55
|
+
if (val >= allowedChars.length) {
|
|
56
|
+
nnext[i] = 0;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return nnext;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.log("calculateNext nnext", nnext);
|
|
63
|
+
nnext.push(0);
|
|
64
|
+
return nnext;
|
|
65
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "drapcode-utility",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "del ./build/*",
|
|
12
|
+
"build": "npm run clean && tsc"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"drapcode",
|
|
16
|
+
"constant",
|
|
17
|
+
"logger",
|
|
18
|
+
"redis"
|
|
19
|
+
],
|
|
20
|
+
"author": "Drapcode",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/lodash": "^4.14.179",
|
|
24
|
+
"del-cli": "^5.0.0",
|
|
25
|
+
"typescript": "^4.0.2"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@types/cookie-session": "^2.0.41",
|
|
29
|
+
"@types/express": "^4.17.7",
|
|
30
|
+
"@types/redis": "^2.8.27",
|
|
31
|
+
"@types/voca": "^1.4.2",
|
|
32
|
+
"aws-sdk": "^2.1324.0",
|
|
33
|
+
"axios": "^1.1.2",
|
|
34
|
+
"drapcode-constant": "^1.0.0",
|
|
35
|
+
"drapcode-logger": "^1.0.0",
|
|
36
|
+
"drapcode-redis": "^1.0.0",
|
|
37
|
+
"express": "^4.17.1",
|
|
38
|
+
"express-rate-limit": "^5.1.3",
|
|
39
|
+
"express-validator": "^6.6.1",
|
|
40
|
+
"lodash": "^4.17.21",
|
|
41
|
+
"moment": "^2.29.0",
|
|
42
|
+
"redis": "^3.0.2",
|
|
43
|
+
"stringify-object": "^3.3.0",
|
|
44
|
+
"voca": "^1.4.0",
|
|
45
|
+
"winston": "^3.8.2"
|
|
46
|
+
}
|
|
47
|
+
}
|