Skip to content

Commit 14d0c48

Browse files
clean up pr
1 parent 0f1377a commit 14d0c48

File tree

1 file changed

+22
-24
lines changed
  • packages/devextreme/js/__internal/data/odata

1 file changed

+22
-24
lines changed

packages/devextreme/js/__internal/data/odata/m_utils.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@ const makeArray = (value) => (type(value) === 'string' ? value.split() : value);
2727
const hasDot = (x) => /\./.test(x);
2828

2929
// consider to use String.prototype.padEnd() or String.prototype.padStart()
30-
const pad = (text: unknown, length: number, right?: boolean): string => {
31-
let textString = String(text);
32-
33-
textString = right ? textString.padEnd(length, '0') : textString.padStart(length, '0');
34-
35-
return textString;
30+
const pad = (text, length, right) => {
31+
text = String(text);
32+
while (text.length < length) {
33+
text = right ? `${text}0` : `0${text}`;
34+
}
35+
return text;
3636
};
3737

38-
const formatISO8601 = (date: Date, skipZeroTime?: boolean, skipTimezone?: boolean): string => {
38+
const formatISO8601 = (date, skipZeroTime, skipTimezone) => {
3939
const bag: string[] = [];
4040

4141
const isZeroTime = () => date.getHours() + date.getMinutes() + date.getSeconds() + date.getMilliseconds() < 1;
42-
const padLeft2 = (text: unknown) => pad(text, 2);
42+
// @ts-expect-error
43+
const padLeft2 = (text) => pad(text, 2);
4344

44-
bag.push(date.getFullYear().toString());
45+
bag.push(date.getFullYear());
4546
bag.push('-');
4647
bag.push(padLeft2(date.getMonth() + 1));
4748
bag.push('-');
@@ -57,29 +58,27 @@ const formatISO8601 = (date: Date, skipZeroTime?: boolean, skipTimezone?: boolea
5758

5859
if (date.getMilliseconds()) {
5960
bag.push('.');
61+
// @ts-expect-error
6062
bag.push(pad(date.getMilliseconds(), 3));
6163
}
6264

6365
if (!skipTimezone) {
6466
bag.push('Z');
6567
}
6668
}
67-
6869
return bag.join('');
6970
};
7071

71-
const parseISO8601 = (isoString: string) => {
72+
const parseISO8601 = (isoString) => {
7273
const result = new Date(new Date(0).getTimezoneOffset() * 60 * 1000);
73-
const [dateChunk, timeChunk] = isoString.replace('Z', '').split('T');
74-
const date = /(\d{4})-(\d{2})-(\d{2})/.exec(dateChunk);
75-
const time = /(\d{2}):(\d{2}):(\d{2})\.?(\d{0,7})?/.exec(timeChunk);
76-
77-
if (!date) {
78-
return null;
79-
}
80-
74+
const chunks = isoString.replace('Z', '').split('T');
75+
const date = /(\d{4})-(\d{2})-(\d{2})/.exec(chunks[0]);
76+
const time = /(\d{2}):(\d{2}):(\d{2})\.?(\d{0,7})?/.exec(chunks[1]);
77+
// @ts-expect-error
8178
result.setFullYear(Number(date[1]));
79+
// @ts-expect-error
8280
result.setMonth(Number(date[2]) - 1);
81+
// @ts-expect-error
8382
result.setDate(Number(date[3]));
8483

8584
if (Array.isArray(time) && time.length) {
@@ -126,7 +125,7 @@ const toAbsoluteUrl = (basePath, relativePath) => {
126125

127126
const param = (params) => {
128127
const result = [];
129-
// eslint-disable-next-line no-restricted-syntax, guard-for-in
128+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, no-restricted-syntax, guard-for-in
130129
for (const name in params) {
131130
// @ts-expect-error
132131
result.push(`${name}=${params[name]}`);
@@ -140,7 +139,7 @@ const ajaxOptionsForRequest = (protocolVersion, request, options = {}) => {
140139
if (!(this[key] instanceof Date)) {
141140
return value;
142141
}
143-
142+
// @ts-expect-error
144143
value = formatISO8601(this[key]);
145144
switch (protocolVersion) {
146145
case 2:
@@ -379,7 +378,7 @@ export const EdmLiteral = Class.inherit({
379378
},
380379
});
381380

382-
const transformTypes = (obj, options = {}): void => {
381+
const transformTypes = (obj, options = {}) => {
383382
each(obj, (key, value) => {
384383
if (value !== null && typeof value === 'object') {
385384
if ('results' in value) {
@@ -401,9 +400,8 @@ const transformTypes = (obj, options = {}): void => {
401400
// @ts-expect-error
402401
const date = new Date(Number(RegExp.$1) + RegExp.$2 * 60 * 1000);
403402
obj[key] = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000);
404-
// OData v4 format
405403
} else if (ISO8601_DATE_REGEX.test(value)) {
406-
obj[key] = new Date(parseISO8601(obj[key])!.valueOf());
404+
obj[key] = new Date(parseISO8601(obj[key]).valueOf());
407405
}
408406
}
409407
}

0 commit comments

Comments
 (0)