@decaf-ts/decorator-validation 1.5.1 → 1.5.2
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/package.json +15 -9
- package/dist/decorator-validation.bundle.min.js +0 -2
- package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -14
- package/dist/esm/decorator-validation.bundle.min.esm.js +0 -2
- package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -14
- package/lib/esm/index.d.ts +0 -42
- package/lib/esm/index.js +0 -42
- package/lib/esm/model/Model.d.ts +0 -138
- package/lib/esm/model/Model.js +0 -296
- package/lib/esm/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/esm/model/ModelErrorDefinition.js +0 -52
- package/lib/esm/model/Registry.d.ts +0 -59
- package/lib/esm/model/Registry.js +0 -73
- package/lib/esm/model/constants.d.ts +0 -56
- package/lib/esm/model/constants.js +0 -69
- package/lib/esm/model/construction.d.ts +0 -29
- package/lib/esm/model/construction.js +0 -63
- package/lib/esm/model/decorators.d.ts +0 -25
- package/lib/esm/model/decorators.js +0 -62
- package/lib/esm/model/index.d.ts +0 -9
- package/lib/esm/model/index.js +0 -9
- package/lib/esm/model/types.d.ts +0 -79
- package/lib/esm/model/types.js +0 -1
- package/lib/esm/model/utils.d.ts +0 -11
- package/lib/esm/model/utils.js +0 -25
- package/lib/esm/model/validation.d.ts +0 -14
- package/lib/esm/model/validation.js +0 -135
- package/lib/esm/utils/constants.d.ts +0 -26
- package/lib/esm/utils/constants.js +0 -27
- package/lib/esm/utils/dates.d.ts +0 -76
- package/lib/esm/utils/dates.js +0 -243
- package/lib/esm/utils/decorators.d.ts +0 -2
- package/lib/esm/utils/decorators.js +0 -18
- package/lib/esm/utils/hashing.d.ts +0 -52
- package/lib/esm/utils/hashing.js +0 -99
- package/lib/esm/utils/index.d.ts +0 -7
- package/lib/esm/utils/index.js +0 -7
- package/lib/esm/utils/registry.d.ts +0 -68
- package/lib/esm/utils/registry.js +0 -1
- package/lib/esm/utils/serialization.d.ts +0 -79
- package/lib/esm/utils/serialization.js +0 -88
- package/lib/esm/utils/strings.d.ts +0 -25
- package/lib/esm/utils/strings.js +0 -31
- package/lib/esm/validation/Validation.d.ts +0 -51
- package/lib/esm/validation/Validation.js +0 -71
- package/lib/esm/validation/Validators/DateValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/DateValidator.js +0 -54
- package/lib/esm/validation/Validators/EmailValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/EmailValidator.js +0 -50
- package/lib/esm/validation/Validators/ListValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/ListValidator.js +0 -65
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +0 -31
- package/lib/esm/validation/Validators/MaxLengthValidator.js +0 -52
- package/lib/esm/validation/Validators/MaxValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/MaxValidator.js +0 -57
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +0 -31
- package/lib/esm/validation/Validators/MinLengthValidator.js +0 -52
- package/lib/esm/validation/Validators/MinValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/MinValidator.js +0 -57
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/PasswordValidator.js +0 -50
- package/lib/esm/validation/Validators/PatternValidator.d.ts +0 -39
- package/lib/esm/validation/Validators/PatternValidator.js +0 -70
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/RequiredValidator.js +0 -57
- package/lib/esm/validation/Validators/StepValidator.d.ts +0 -31
- package/lib/esm/validation/Validators/StepValidator.js +0 -52
- package/lib/esm/validation/Validators/TypeValidator.d.ts +0 -29
- package/lib/esm/validation/Validators/TypeValidator.js +0 -60
- package/lib/esm/validation/Validators/URLValidator.d.ts +0 -32
- package/lib/esm/validation/Validators/URLValidator.js +0 -46
- package/lib/esm/validation/Validators/Validator.d.ts +0 -43
- package/lib/esm/validation/Validators/Validator.js +0 -47
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -80
- package/lib/esm/validation/Validators/constants.d.ts +0 -96
- package/lib/esm/validation/Validators/constants.js +0 -134
- package/lib/esm/validation/Validators/decorators.d.ts +0 -12
- package/lib/esm/validation/Validators/decorators.js +0 -25
- package/lib/esm/validation/Validators/index.d.ts +0 -52
- package/lib/esm/validation/Validators/index.js +0 -52
- package/lib/esm/validation/Validators/types.d.ts +0 -51
- package/lib/esm/validation/Validators/types.js +0 -1
- package/lib/esm/validation/decorators.d.ts +0 -178
- package/lib/esm/validation/decorators.js +0 -288
- package/lib/esm/validation/index.d.ts +0 -4
- package/lib/esm/validation/index.js +0 -4
- package/lib/esm/validation/types.d.ts +0 -46
- package/lib/esm/validation/types.js +0 -1
- package/lib/index.cjs +0 -59
- package/lib/index.d.ts +0 -42
- package/lib/model/Model.cjs +0 -300
- package/lib/model/Model.d.ts +0 -138
- package/lib/model/ModelErrorDefinition.cjs +0 -56
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/Registry.cjs +0 -78
- package/lib/model/Registry.d.ts +0 -59
- package/lib/model/constants.cjs +0 -72
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/construction.cjs +0 -68
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/decorators.cjs +0 -67
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/index.cjs +0 -25
- package/lib/model/index.d.ts +0 -9
- package/lib/model/types.cjs +0 -2
- package/lib/model/types.d.ts +0 -79
- package/lib/model/utils.cjs +0 -29
- package/lib/model/utils.d.ts +0 -11
- package/lib/model/validation.cjs +0 -138
- package/lib/model/validation.d.ts +0 -14
- package/lib/utils/constants.cjs +0 -30
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/dates.cjs +0 -251
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/decorators.cjs +0 -22
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/hashing.cjs +0 -106
- package/lib/utils/hashing.d.ts +0 -52
- package/lib/utils/index.cjs +0 -23
- package/lib/utils/index.d.ts +0 -7
- package/lib/utils/registry.cjs +0 -2
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/serialization.cjs +0 -93
- package/lib/utils/serialization.d.ts +0 -79
- package/lib/utils/strings.cjs +0 -35
- package/lib/utils/strings.d.ts +0 -25
- package/lib/validation/Validation.cjs +0 -75
- package/lib/validation/Validation.d.ts +0 -51
- package/lib/validation/Validators/DateValidator.cjs +0 -57
- package/lib/validation/Validators/DateValidator.d.ts +0 -30
- package/lib/validation/Validators/EmailValidator.cjs +0 -53
- package/lib/validation/Validators/EmailValidator.d.ts +0 -27
- package/lib/validation/Validators/ListValidator.cjs +0 -68
- package/lib/validation/Validators/ListValidator.d.ts +0 -30
- package/lib/validation/Validators/MaxLengthValidator.cjs +0 -55
- package/lib/validation/Validators/MaxLengthValidator.d.ts +0 -31
- package/lib/validation/Validators/MaxValidator.cjs +0 -60
- package/lib/validation/Validators/MaxValidator.d.ts +0 -30
- package/lib/validation/Validators/MinLengthValidator.cjs +0 -55
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -31
- package/lib/validation/Validators/MinValidator.cjs +0 -60
- package/lib/validation/Validators/MinValidator.d.ts +0 -30
- package/lib/validation/Validators/PasswordValidator.cjs +0 -53
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -27
- package/lib/validation/Validators/PatternValidator.cjs +0 -73
- package/lib/validation/Validators/PatternValidator.d.ts +0 -39
- package/lib/validation/Validators/RequiredValidator.cjs +0 -60
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -27
- package/lib/validation/Validators/StepValidator.cjs +0 -55
- package/lib/validation/Validators/StepValidator.d.ts +0 -31
- package/lib/validation/Validators/TypeValidator.cjs +0 -63
- package/lib/validation/Validators/TypeValidator.d.ts +0 -29
- package/lib/validation/Validators/URLValidator.cjs +0 -49
- package/lib/validation/Validators/URLValidator.d.ts +0 -32
- package/lib/validation/Validators/Validator.cjs +0 -51
- package/lib/validation/Validators/Validator.d.ts +0 -43
- package/lib/validation/Validators/ValidatorRegistry.cjs +0 -85
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/constants.cjs +0 -137
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/Validators/decorators.cjs +0 -28
- package/lib/validation/Validators/index.cjs +0 -69
- package/lib/validation/Validators/types.cjs +0 -2
- package/lib/validation/decorators.cjs +0 -304
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/index.cjs +0 -20
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.cjs +0 -2
- package/lib/validation/types.d.ts +0 -46
package/lib/utils/constants.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Defines the various Model keys used for reflection
|
|
3
|
-
*
|
|
4
|
-
* @property {string} REFLECT prefix to all other keys
|
|
5
|
-
* @property {string} TYPE type key
|
|
6
|
-
* @property {string} PARAMS method params key
|
|
7
|
-
* @property {string} RETURN method return key
|
|
8
|
-
* @property {string} MODEL model key
|
|
9
|
-
* @property {string} ANCHOR anchor key. will serve as a ghost property in the model
|
|
10
|
-
*
|
|
11
|
-
* @constant ModelKeys
|
|
12
|
-
* @memberOf module:decorator-validation.Model
|
|
13
|
-
* @category Model
|
|
14
|
-
*/
|
|
15
|
-
export declare enum ModelKeys {
|
|
16
|
-
REFLECT = "decaf.model.",
|
|
17
|
-
TYPE = "design:type",
|
|
18
|
-
PARAMS = "design:paramtypes",
|
|
19
|
-
RETURN = "design:returntype",
|
|
20
|
-
MODEL = "model",
|
|
21
|
-
ANCHOR = "__model",
|
|
22
|
-
CONSTRUCTION = "constructed-by",
|
|
23
|
-
ATTRIBUTE = "__attributes",
|
|
24
|
-
HASHING = "hashing",
|
|
25
|
-
SERIALIZATION = "serialization"
|
|
26
|
-
}
|
package/lib/utils/dates.cjs
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dateFromFormat = dateFromFormat;
|
|
4
|
-
exports.bindDateToString = bindDateToString;
|
|
5
|
-
exports.isValidDate = isValidDate;
|
|
6
|
-
exports.twoDigitPad = twoDigitPad;
|
|
7
|
-
exports.formatDate = formatDate;
|
|
8
|
-
exports.parseDate = parseDate;
|
|
9
|
-
require("reflect-metadata");
|
|
10
|
-
const constants_1 = require("../validation/Validators/constants.cjs");
|
|
11
|
-
const strings_1 = require("./strings.cjs");
|
|
12
|
-
/**
|
|
13
|
-
* @summary Reverses the process from {@link formatDate}
|
|
14
|
-
*
|
|
15
|
-
* @param {string} date the date string to be converted back into date
|
|
16
|
-
* @param {string} format the date format
|
|
17
|
-
* @return {Date} the date from the format or the standard new Date({@prop date}) if the string couldn't be parsed (are you sure the format matches the string?)
|
|
18
|
-
*
|
|
19
|
-
* @function dateFromFormat
|
|
20
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
21
|
-
* @category Format
|
|
22
|
-
*/
|
|
23
|
-
function dateFromFormat(date, format) {
|
|
24
|
-
let formatRegexp = format;
|
|
25
|
-
// Hour
|
|
26
|
-
if (formatRegexp.match(/hh/))
|
|
27
|
-
formatRegexp = formatRegexp.replace("hh", "(?<hour>\\d{2})");
|
|
28
|
-
else if (formatRegexp.match(/h/))
|
|
29
|
-
formatRegexp = formatRegexp.replace("h", "(?<hour>\\d{1,2})");
|
|
30
|
-
else if (formatRegexp.match(/HH/))
|
|
31
|
-
formatRegexp = formatRegexp.replace("HH", "(?<hour>\\d{2})");
|
|
32
|
-
else if (formatRegexp.match(/H/))
|
|
33
|
-
formatRegexp = formatRegexp.replace("H", "(?<hour>\\d{1,2})");
|
|
34
|
-
// Minutes
|
|
35
|
-
if (formatRegexp.match(/mm/))
|
|
36
|
-
formatRegexp = formatRegexp.replace("mm", "(?<minutes>\\d{2})");
|
|
37
|
-
else if (formatRegexp.match(/m/))
|
|
38
|
-
formatRegexp = formatRegexp.replace("m", "(?<minutes>\\d{1,2})");
|
|
39
|
-
// Seconds
|
|
40
|
-
if (formatRegexp.match(/ss/))
|
|
41
|
-
formatRegexp = formatRegexp.replace("ss", "(?<seconds>\\d{2})");
|
|
42
|
-
else if (formatRegexp.match(/s/))
|
|
43
|
-
formatRegexp = formatRegexp.replace("s", "(?<seconds>\\d{1,2})");
|
|
44
|
-
// Day
|
|
45
|
-
if (formatRegexp.match(/dd/))
|
|
46
|
-
formatRegexp = formatRegexp.replace("dd", "(?<day>\\d{2})");
|
|
47
|
-
else if (formatRegexp.match(/d/))
|
|
48
|
-
formatRegexp = formatRegexp.replace("d", "(?<day>\\d{1,2})");
|
|
49
|
-
// Day Of Week
|
|
50
|
-
if (formatRegexp.match(/EEEE/))
|
|
51
|
-
formatRegexp = formatRegexp.replace("EEEE", "(?<dayofweek>\\w+)");
|
|
52
|
-
// eslint-disable-next-line no-dupe-else-if
|
|
53
|
-
else if (formatRegexp.match(/EEEE/))
|
|
54
|
-
formatRegexp = formatRegexp.replace("EEE", "(?<dayofweek>\\w+)");
|
|
55
|
-
// Year
|
|
56
|
-
if (formatRegexp.match(/yyyy/))
|
|
57
|
-
formatRegexp = formatRegexp.replace("yyyy", "(?<year>\\d{4})");
|
|
58
|
-
else if (formatRegexp.match(/yy/))
|
|
59
|
-
formatRegexp = formatRegexp.replace("yy", "(?<year>\\d{2})");
|
|
60
|
-
// Month
|
|
61
|
-
if (formatRegexp.match(/MMMM/))
|
|
62
|
-
formatRegexp = formatRegexp.replace("MMMM", "(?<monthname>\\w+)");
|
|
63
|
-
else if (formatRegexp.match(/MMM/))
|
|
64
|
-
formatRegexp = formatRegexp.replace("MMM", "(?<monthnamesmall>\\w+)");
|
|
65
|
-
if (formatRegexp.match(/MM/))
|
|
66
|
-
formatRegexp = formatRegexp.replace("MM", "(?<month>\\d{2})");
|
|
67
|
-
else if (formatRegexp.match(/M/))
|
|
68
|
-
formatRegexp = formatRegexp.replace("M", "(?<month>\\d{1,2})");
|
|
69
|
-
// Milis and Am Pm
|
|
70
|
-
formatRegexp = formatRegexp
|
|
71
|
-
.replace("S", "(?<milis>\\d{1,3})")
|
|
72
|
-
.replace("aaa", "(?<ampm>\\w{2})");
|
|
73
|
-
const regexp = new RegExp(formatRegexp, "g");
|
|
74
|
-
const match = regexp.exec(date);
|
|
75
|
-
if (!match || !match.groups)
|
|
76
|
-
return new Date(date);
|
|
77
|
-
const safeParseInt = function (n) {
|
|
78
|
-
if (!n)
|
|
79
|
-
return 0;
|
|
80
|
-
const result = parseInt(n);
|
|
81
|
-
return isNaN(result) ? 0 : result;
|
|
82
|
-
};
|
|
83
|
-
const year = safeParseInt(match.groups.year);
|
|
84
|
-
const day = safeParseInt(match.groups.day);
|
|
85
|
-
const amPm = match.groups.ampm;
|
|
86
|
-
let hour = safeParseInt(match.groups.hour);
|
|
87
|
-
if (amPm)
|
|
88
|
-
hour = amPm === "PM" ? hour + 12 : hour;
|
|
89
|
-
const minutes = safeParseInt(match.groups.minutes);
|
|
90
|
-
const seconds = safeParseInt(match.groups.seconds);
|
|
91
|
-
const ms = safeParseInt(match.groups.milis);
|
|
92
|
-
const monthName = match.groups.monthname;
|
|
93
|
-
const monthNameSmall = match.groups.monthnamesmall;
|
|
94
|
-
let month = match.groups.month;
|
|
95
|
-
if (monthName)
|
|
96
|
-
month = constants_1.MONTH_NAMES.indexOf(monthName);
|
|
97
|
-
else if (monthNameSmall) {
|
|
98
|
-
const m = constants_1.MONTH_NAMES.find((m) => m.toLowerCase().startsWith(monthNameSmall.toLowerCase()));
|
|
99
|
-
if (!m)
|
|
100
|
-
return new Date(date);
|
|
101
|
-
month = constants_1.MONTH_NAMES.indexOf(m);
|
|
102
|
-
}
|
|
103
|
-
else
|
|
104
|
-
month = safeParseInt(`${month}`);
|
|
105
|
-
return new Date(year, month - 1, day, hour, minutes, seconds, ms);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @summary Binds a date format to a string
|
|
109
|
-
* @param {Date} [date]
|
|
110
|
-
* @param {string} [format]
|
|
111
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
112
|
-
* @category Utilities
|
|
113
|
-
*/
|
|
114
|
-
function bindDateToString(date, format) {
|
|
115
|
-
if (!date)
|
|
116
|
-
return;
|
|
117
|
-
const func = () => formatDate(date, format);
|
|
118
|
-
Object.defineProperty(date, "toISOString", {
|
|
119
|
-
enumerable: false,
|
|
120
|
-
configurable: false,
|
|
121
|
-
value: func,
|
|
122
|
-
});
|
|
123
|
-
Object.defineProperty(date, "toString", {
|
|
124
|
-
enumerable: false,
|
|
125
|
-
configurable: false,
|
|
126
|
-
value: func,
|
|
127
|
-
});
|
|
128
|
-
// Object.setPrototypeOf(date, Date.prototype);
|
|
129
|
-
return date;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* @summary Helper function to be used instead of instanceOf Date
|
|
133
|
-
* @param date
|
|
134
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
135
|
-
* @category Validation
|
|
136
|
-
*/
|
|
137
|
-
function isValidDate(date) {
|
|
138
|
-
return (date &&
|
|
139
|
-
Object.prototype.toString.call(date) === "[object Date]" &&
|
|
140
|
-
!Number.isNaN(date));
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* @summary Util function to pad numbers
|
|
144
|
-
* @param {number} num
|
|
145
|
-
*
|
|
146
|
-
* @return {string}
|
|
147
|
-
*
|
|
148
|
-
* @function twoDigitPad
|
|
149
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
150
|
-
* @category Format
|
|
151
|
-
*/
|
|
152
|
-
function twoDigitPad(num) {
|
|
153
|
-
return num < 10 ? "0" + num : num.toString();
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* @summary Date Format Handling
|
|
157
|
-
* @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
|
|
158
|
-
*
|
|
159
|
-
* <pre>
|
|
160
|
-
* Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
|
|
161
|
-
* I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
|
|
162
|
-
* You can display date, time, AM/PM, etc.
|
|
163
|
-
*
|
|
164
|
-
* Date and Time Patterns
|
|
165
|
-
* yy = 2-digit year; yyyy = full year
|
|
166
|
-
* M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
|
|
167
|
-
* EEEE = full weekday name; EEE = short weekday name
|
|
168
|
-
* d = digit day; dd = 2-digit day
|
|
169
|
-
* h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
|
|
170
|
-
* m = minutes; mm = 2-digit minutes; aaa = AM/PM
|
|
171
|
-
* s = seconds; ss = 2-digit seconds
|
|
172
|
-
* S = miliseconds
|
|
173
|
-
* </pre>
|
|
174
|
-
*
|
|
175
|
-
* @param {Date} date
|
|
176
|
-
* @param {string} [patternStr] defaults to 'yyyy/MM/dd'
|
|
177
|
-
* @return {string} the formatted date
|
|
178
|
-
*
|
|
179
|
-
* @function formatDate
|
|
180
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
181
|
-
* @category Format
|
|
182
|
-
*/
|
|
183
|
-
function formatDate(date, patternStr = "yyyy/MM/dd") {
|
|
184
|
-
const day = date.getDate(), month = date.getMonth(), year = date.getFullYear(), hour = date.getHours(), minute = date.getMinutes(), second = date.getSeconds(), miliseconds = date.getMilliseconds(), h = hour % 12, hh = twoDigitPad(h), HH = twoDigitPad(hour), mm = twoDigitPad(minute), ss = twoDigitPad(second), aaa = hour < 12 ? "AM" : "PM", EEEE = constants_1.DAYS_OF_WEEK_NAMES[date.getDay()], EEE = EEEE.substr(0, 3), dd = twoDigitPad(day), M = month + 1, MM = twoDigitPad(M), MMMM = constants_1.MONTH_NAMES[month], MMM = MMMM.substr(0, 3), yyyy = year + "", yy = yyyy.substr(2, 2);
|
|
185
|
-
// checks to see if month name will be used
|
|
186
|
-
patternStr = patternStr
|
|
187
|
-
.replace("hh", hh)
|
|
188
|
-
.replace("h", h.toString())
|
|
189
|
-
.replace("HH", HH)
|
|
190
|
-
.replace("H", hour.toString())
|
|
191
|
-
.replace("mm", mm)
|
|
192
|
-
.replace("m", minute.toString())
|
|
193
|
-
.replace("ss", ss)
|
|
194
|
-
.replace("s", second.toString())
|
|
195
|
-
.replace("S", miliseconds.toString())
|
|
196
|
-
.replace("dd", dd)
|
|
197
|
-
.replace("d", day.toString())
|
|
198
|
-
.replace("EEEE", EEEE)
|
|
199
|
-
.replace("EEE", EEE)
|
|
200
|
-
.replace("yyyy", yyyy)
|
|
201
|
-
.replace("yy", yy)
|
|
202
|
-
.replace("aaa", aaa);
|
|
203
|
-
if (patternStr.indexOf("MMM") > -1) {
|
|
204
|
-
patternStr = patternStr.replace("MMMM", MMMM).replace("MMM", MMM);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
patternStr = patternStr.replace("MM", MM).replace("M", M.toString());
|
|
208
|
-
}
|
|
209
|
-
return patternStr;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* @summary Parses a date from a specified format
|
|
213
|
-
* @param {string} format
|
|
214
|
-
* @param {string | Date | number} [v]
|
|
215
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
216
|
-
* @category Format
|
|
217
|
-
*/
|
|
218
|
-
function parseDate(format, v) {
|
|
219
|
-
let value = undefined;
|
|
220
|
-
if (!v)
|
|
221
|
-
return undefined;
|
|
222
|
-
if (v instanceof Date)
|
|
223
|
-
try {
|
|
224
|
-
value = dateFromFormat(formatDate(v, format), format);
|
|
225
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
226
|
-
}
|
|
227
|
-
catch (e) {
|
|
228
|
-
throw new Error((0, strings_1.sf)("Could not convert date {0} to format: {1}", v.toString(), format));
|
|
229
|
-
}
|
|
230
|
-
else if (typeof v === "string") {
|
|
231
|
-
value = dateFromFormat(v, format);
|
|
232
|
-
}
|
|
233
|
-
else if (typeof v === "number") {
|
|
234
|
-
const d = new Date(v);
|
|
235
|
-
value = dateFromFormat(formatDate(d, format), format);
|
|
236
|
-
}
|
|
237
|
-
else if (isValidDate(v)) {
|
|
238
|
-
try {
|
|
239
|
-
const d = new Date(v);
|
|
240
|
-
value = dateFromFormat(formatDate(d, format), format);
|
|
241
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
242
|
-
}
|
|
243
|
-
catch (e) {
|
|
244
|
-
throw new Error((0, strings_1.sf)("Could not convert date {0} to format: {1}", v, format));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
throw new Error(`Invalid value provided ${v}`);
|
|
249
|
-
}
|
|
250
|
-
return bindDateToString(value, format);
|
|
251
|
-
}
|
package/lib/utils/dates.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Reverses the process from {@link formatDate}
|
|
4
|
-
*
|
|
5
|
-
* @param {string} date the date string to be converted back into date
|
|
6
|
-
* @param {string} format the date format
|
|
7
|
-
* @return {Date} the date from the format or the standard new Date({@prop date}) if the string couldn't be parsed (are you sure the format matches the string?)
|
|
8
|
-
*
|
|
9
|
-
* @function dateFromFormat
|
|
10
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
11
|
-
* @category Format
|
|
12
|
-
*/
|
|
13
|
-
export declare function dateFromFormat(date: string, format: string): Date;
|
|
14
|
-
/**
|
|
15
|
-
* @summary Binds a date format to a string
|
|
16
|
-
* @param {Date} [date]
|
|
17
|
-
* @param {string} [format]
|
|
18
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
19
|
-
* @category Utilities
|
|
20
|
-
*/
|
|
21
|
-
export declare function bindDateToString(date: Date | undefined, format: string): Date | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* @summary Helper function to be used instead of instanceOf Date
|
|
24
|
-
* @param date
|
|
25
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
26
|
-
* @category Validation
|
|
27
|
-
*/
|
|
28
|
-
export declare function isValidDate(date: any): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* @summary Util function to pad numbers
|
|
31
|
-
* @param {number} num
|
|
32
|
-
*
|
|
33
|
-
* @return {string}
|
|
34
|
-
*
|
|
35
|
-
* @function twoDigitPad
|
|
36
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
37
|
-
* @category Format
|
|
38
|
-
*/
|
|
39
|
-
export declare function twoDigitPad(num: number): string;
|
|
40
|
-
/**
|
|
41
|
-
* @summary Date Format Handling
|
|
42
|
-
* @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
|
|
43
|
-
*
|
|
44
|
-
* <pre>
|
|
45
|
-
* Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
|
|
46
|
-
* I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
|
|
47
|
-
* You can display date, time, AM/PM, etc.
|
|
48
|
-
*
|
|
49
|
-
* Date and Time Patterns
|
|
50
|
-
* yy = 2-digit year; yyyy = full year
|
|
51
|
-
* M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
|
|
52
|
-
* EEEE = full weekday name; EEE = short weekday name
|
|
53
|
-
* d = digit day; dd = 2-digit day
|
|
54
|
-
* h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
|
|
55
|
-
* m = minutes; mm = 2-digit minutes; aaa = AM/PM
|
|
56
|
-
* s = seconds; ss = 2-digit seconds
|
|
57
|
-
* S = miliseconds
|
|
58
|
-
* </pre>
|
|
59
|
-
*
|
|
60
|
-
* @param {Date} date
|
|
61
|
-
* @param {string} [patternStr] defaults to 'yyyy/MM/dd'
|
|
62
|
-
* @return {string} the formatted date
|
|
63
|
-
*
|
|
64
|
-
* @function formatDate
|
|
65
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
66
|
-
* @category Format
|
|
67
|
-
*/
|
|
68
|
-
export declare function formatDate(date: Date, patternStr?: string): string;
|
|
69
|
-
/**
|
|
70
|
-
* @summary Parses a date from a specified format
|
|
71
|
-
* @param {string} format
|
|
72
|
-
* @param {string | Date | number} [v]
|
|
73
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
74
|
-
* @category Format
|
|
75
|
-
*/
|
|
76
|
-
export declare function parseDate(format: string, v?: string | Date | number): Date | undefined;
|
package/lib/utils/decorators.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prop = prop;
|
|
4
|
-
exports.propMetadata = propMetadata;
|
|
5
|
-
const reflection_1 = require("@decaf-ts/reflection");
|
|
6
|
-
const constants_1 = require("./constants.cjs");
|
|
7
|
-
function prop(key = constants_1.ModelKeys.ATTRIBUTE) {
|
|
8
|
-
return (model, propertyKey) => {
|
|
9
|
-
let props;
|
|
10
|
-
if (Object.prototype.hasOwnProperty.call(model, key)) {
|
|
11
|
-
props = model[key];
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
props = model[key] = [];
|
|
15
|
-
}
|
|
16
|
-
if (!props.includes(propertyKey))
|
|
17
|
-
props.push(propertyKey);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function propMetadata(key, value) {
|
|
21
|
-
return (0, reflection_1.apply)(prop(), (0, reflection_1.metadata)(key, value));
|
|
22
|
-
}
|
package/lib/utils/hashing.cjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Hashing = exports.DefaultHashingMethod = void 0;
|
|
4
|
-
exports.hashCode = hashCode;
|
|
5
|
-
exports.hashSerialization = hashSerialization;
|
|
6
|
-
exports.hashObj = hashObj;
|
|
7
|
-
const serialization_1 = require("./serialization.cjs");
|
|
8
|
-
/**
|
|
9
|
-
* @summary Mimics Java's String's Hash implementation
|
|
10
|
-
*
|
|
11
|
-
* @param {string | number | symbol | Date} obj
|
|
12
|
-
* @return {number} hash value of obj
|
|
13
|
-
*
|
|
14
|
-
* @function hashCode
|
|
15
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
16
|
-
* @category Hashing
|
|
17
|
-
*/
|
|
18
|
-
function hashCode(obj) {
|
|
19
|
-
obj = String(obj);
|
|
20
|
-
let hash = 0;
|
|
21
|
-
for (let i = 0; i < obj.length; i++) {
|
|
22
|
-
const character = obj.charCodeAt(i);
|
|
23
|
-
hash = (hash << 5) - hash + character;
|
|
24
|
-
hash = hash & hash; // Convert to 32bit integer
|
|
25
|
-
}
|
|
26
|
-
return hash.toString();
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @summary Hashes an object serializing it and then hashing the string
|
|
30
|
-
* @description The Serialization algorithm used by default (JSON.stringify)
|
|
31
|
-
* is not deterministic and should not be used for hashing
|
|
32
|
-
*
|
|
33
|
-
* @param {Record<string, any>} obj
|
|
34
|
-
* @return {string} the resulting hash
|
|
35
|
-
*
|
|
36
|
-
* @function hashSerialization
|
|
37
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
38
|
-
*
|
|
39
|
-
* @category Hashing
|
|
40
|
-
*/
|
|
41
|
-
function hashSerialization(obj) {
|
|
42
|
-
return hashCode(serialization_1.Serialization.serialize(obj));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @summary Hashes an object by combining the hash of all its properties
|
|
46
|
-
*
|
|
47
|
-
* @param {Record<string, any>} obj
|
|
48
|
-
* @return {string} the resulting hash
|
|
49
|
-
*
|
|
50
|
-
* @function hashObj
|
|
51
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
52
|
-
* @category Hashing
|
|
53
|
-
*/
|
|
54
|
-
function hashObj(obj) {
|
|
55
|
-
const hashReducer = function (h, el) {
|
|
56
|
-
const elHash = hashFunction(el);
|
|
57
|
-
if (typeof elHash === "string")
|
|
58
|
-
return hashFunction((h || "") + hashFunction(el));
|
|
59
|
-
h = h || 0;
|
|
60
|
-
h = (h << 5) - h + elHash;
|
|
61
|
-
return h & h;
|
|
62
|
-
};
|
|
63
|
-
const func = hashCode;
|
|
64
|
-
const hashFunction = function (value) {
|
|
65
|
-
if (typeof value === "undefined")
|
|
66
|
-
return "";
|
|
67
|
-
if (["string", "number", "symbol"].indexOf(typeof value) !== -1)
|
|
68
|
-
return func(value.toString());
|
|
69
|
-
if (value instanceof Date)
|
|
70
|
-
return func(value.getTime());
|
|
71
|
-
if (Array.isArray(value))
|
|
72
|
-
return value.reduce(hashReducer, undefined);
|
|
73
|
-
return Object.values(value).reduce(hashReducer, undefined);
|
|
74
|
-
};
|
|
75
|
-
const result = Object.values(obj).reduce(hashReducer, 0);
|
|
76
|
-
return (typeof result === "number" ? Math.abs(result) : result).toString();
|
|
77
|
-
}
|
|
78
|
-
exports.DefaultHashingMethod = "default";
|
|
79
|
-
class Hashing {
|
|
80
|
-
static { this.current = exports.DefaultHashingMethod; }
|
|
81
|
-
static { this.cache = {
|
|
82
|
-
default: hashObj,
|
|
83
|
-
}; }
|
|
84
|
-
constructor() { }
|
|
85
|
-
static get(key) {
|
|
86
|
-
if (key in this.cache)
|
|
87
|
-
return this.cache[key];
|
|
88
|
-
throw new Error(`No hashing method registered under ${key}`);
|
|
89
|
-
}
|
|
90
|
-
static register(key, func, setDefault = false) {
|
|
91
|
-
if (key in this.cache)
|
|
92
|
-
throw new Error(`Hashing method ${key} already registered`);
|
|
93
|
-
this.cache[key] = func;
|
|
94
|
-
if (setDefault)
|
|
95
|
-
this.current = key;
|
|
96
|
-
}
|
|
97
|
-
static hash(obj, method, ...args) {
|
|
98
|
-
if (!method)
|
|
99
|
-
return this.get(this.current)(obj, ...args);
|
|
100
|
-
return this.get(method)(obj, ...args);
|
|
101
|
-
}
|
|
102
|
-
static setDefault(method) {
|
|
103
|
-
this.current = this.get(method);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.Hashing = Hashing;
|
package/lib/utils/hashing.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Mimics Java's String's Hash implementation
|
|
3
|
-
*
|
|
4
|
-
* @param {string | number | symbol | Date} obj
|
|
5
|
-
* @return {number} hash value of obj
|
|
6
|
-
*
|
|
7
|
-
* @function hashCode
|
|
8
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
9
|
-
* @category Hashing
|
|
10
|
-
*/
|
|
11
|
-
export declare function hashCode(obj: string | number | symbol | Date): string;
|
|
12
|
-
/**
|
|
13
|
-
* @summary Defines teh type for a Hashing function
|
|
14
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
15
|
-
* @category Hashing
|
|
16
|
-
*/
|
|
17
|
-
export type HashingFunction = (value: any, ...args: any[]) => string;
|
|
18
|
-
/**
|
|
19
|
-
* @summary Hashes an object serializing it and then hashing the string
|
|
20
|
-
* @description The Serialization algorithm used by default (JSON.stringify)
|
|
21
|
-
* is not deterministic and should not be used for hashing
|
|
22
|
-
*
|
|
23
|
-
* @param {Record<string, any>} obj
|
|
24
|
-
* @return {string} the resulting hash
|
|
25
|
-
*
|
|
26
|
-
* @function hashSerialization
|
|
27
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
28
|
-
*
|
|
29
|
-
* @category Hashing
|
|
30
|
-
*/
|
|
31
|
-
export declare function hashSerialization(obj: Record<string, any> | any[]): string;
|
|
32
|
-
/**
|
|
33
|
-
* @summary Hashes an object by combining the hash of all its properties
|
|
34
|
-
*
|
|
35
|
-
* @param {Record<string, any>} obj
|
|
36
|
-
* @return {string} the resulting hash
|
|
37
|
-
*
|
|
38
|
-
* @function hashObj
|
|
39
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
40
|
-
* @category Hashing
|
|
41
|
-
*/
|
|
42
|
-
export declare function hashObj(obj: Record<string, any> | any[]): string;
|
|
43
|
-
export declare const DefaultHashingMethod = "default";
|
|
44
|
-
export declare class Hashing {
|
|
45
|
-
private static current;
|
|
46
|
-
private static cache;
|
|
47
|
-
private constructor();
|
|
48
|
-
private static get;
|
|
49
|
-
static register(key: string, func: HashingFunction, setDefault?: boolean): void;
|
|
50
|
-
static hash(obj: any, method?: string, ...args: any[]): any;
|
|
51
|
-
static setDefault(method: string): void;
|
|
52
|
-
}
|
package/lib/utils/index.cjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./constants.cjs"), exports);
|
|
18
|
-
__exportStar(require("./dates.cjs"), exports);
|
|
19
|
-
__exportStar(require("./decorators.cjs"), exports);
|
|
20
|
-
__exportStar(require("./hashing.cjs"), exports);
|
|
21
|
-
__exportStar(require("./registry.cjs"), exports);
|
|
22
|
-
__exportStar(require("./serialization.cjs"), exports);
|
|
23
|
-
__exportStar(require("./strings.cjs"), exports);
|
package/lib/utils/index.d.ts
DELETED
package/lib/utils/registry.cjs
DELETED
package/lib/utils/registry.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "../model/types";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Basic interface for Registries
|
|
4
|
-
*
|
|
5
|
-
* @interface IRegistry
|
|
6
|
-
*
|
|
7
|
-
* @category Utilities
|
|
8
|
-
*/
|
|
9
|
-
export interface IRegistry<T> {
|
|
10
|
-
/**
|
|
11
|
-
* @summary Registers an Object
|
|
12
|
-
*
|
|
13
|
-
* @param {T} obj
|
|
14
|
-
* @param {any[]} args
|
|
15
|
-
*
|
|
16
|
-
* @method
|
|
17
|
-
*/
|
|
18
|
-
register(obj: T | any, ...args: any[]): void;
|
|
19
|
-
/**
|
|
20
|
-
* @summary Retrieves an Object if it can find it
|
|
21
|
-
*
|
|
22
|
-
* @param {any} key
|
|
23
|
-
* @param {any[]} args
|
|
24
|
-
* @return {T | undefined}
|
|
25
|
-
*
|
|
26
|
-
* @method
|
|
27
|
-
*/
|
|
28
|
-
get(key: any, ...args: any[]): T | undefined;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @summary Basic Builder Registry Interface
|
|
32
|
-
*
|
|
33
|
-
* @typedef T
|
|
34
|
-
* @interface BuilderRegistry<T>
|
|
35
|
-
*
|
|
36
|
-
* @category Construction
|
|
37
|
-
*/
|
|
38
|
-
export interface BuilderRegistry<T> extends IRegistry<Constructor<T>> {
|
|
39
|
-
/**
|
|
40
|
-
* @summary Retrieves an Builder Object by name if it can
|
|
41
|
-
*
|
|
42
|
-
* @param {string} name
|
|
43
|
-
* @param {any[]} args
|
|
44
|
-
*
|
|
45
|
-
* @method
|
|
46
|
-
*/
|
|
47
|
-
get(name: string, ...args: any[]): Constructor<T> | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* @summary Registers a constructor by name
|
|
50
|
-
*
|
|
51
|
-
* @param {Constructor<T>} [constructor]
|
|
52
|
-
* @param {name} name
|
|
53
|
-
* @param {any[]} args
|
|
54
|
-
*
|
|
55
|
-
* @method
|
|
56
|
-
*/
|
|
57
|
-
register(constructor: Constructor<T>, name?: string, ...args: any[]): void;
|
|
58
|
-
/**
|
|
59
|
-
* @summary Builds an Object by name
|
|
60
|
-
*
|
|
61
|
-
* @param {{}} obj
|
|
62
|
-
* @param {any[]} args
|
|
63
|
-
* @return T
|
|
64
|
-
*
|
|
65
|
-
* @method
|
|
66
|
-
*/
|
|
67
|
-
build(obj: Record<string, any> | T, ...args: any[]): T;
|
|
68
|
-
}
|