"@rollup/plugin-json": "^5.0.2",
"@types/mocha": "^10.0.1",
"@types/mochawesome": "^6.2.1",
- "@types/node": "^18.11.12",
+ "@types/node": "^18.11.13",
"@types/proper-lockfile": "^4.1.2",
"@types/tar": "^6.1.3",
"@types/ws": "^8.5.3",
"expect": "^29.3.1",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
- "mocha": "^10.1.0",
+ "mocha": "^10.2.0",
"mochawesome": "^7.1.3",
"prettier": "^2.8.1",
"release-it": "^15.5.1",
"robohydra": "^0.6.9",
- "rollup": "^3.7.0",
+ "rollup": "^3.7.3",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-delete": "^2.0.0",
}
},
"node_modules/@types/node": {
- "version": "18.11.12",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.12.tgz",
- "integrity": "sha512-FgD3NtTAKvyMmD44T07zz2fEf+OKwutgBCEVM8GcvMGVGaDktiLNTDvPwC/LUe3PinMW+X6CuLOF2Ui1mAlSXg=="
+ "version": "18.11.13",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz",
+ "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w=="
},
"node_modules/@types/object-path": {
"version": "0.11.1",
}
},
"node_modules/mocha": {
- "version": "10.1.0",
- "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.1.0.tgz",
- "integrity": "sha512-vUF7IYxEoN7XhQpFLxQAEMtE4W91acW4B6En9l97MwE9stL1A9gusXfoHZCLVHDUJ/7V5+lbCM6yMqzo5vNymg==",
+ "version": "10.2.0",
+ "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz",
+ "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==",
"dev": true,
"dependencies": {
"ansi-colors": "4.1.1",
}
},
"node_modules/rollup": {
- "version": "3.7.0",
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.7.0.tgz",
- "integrity": "sha512-FIJe0msW9P7L9BTfvaJyvn1U1BVCNTL3w8O+PKIrCyiMLg+rIUGb4MbcgVZ10Lnm1uWXOTOWRNARjfXC1+M12Q==",
+ "version": "3.7.3",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.7.3.tgz",
+ "integrity": "sha512-7e68MQbAWCX6mI4/0lG1WHd+NdNAlVamg0Zkd+8LZ/oXojligdGnCNyHlzXqXCZObyjs5FRc3AH0b17iJESGIQ==",
"dev": true,
"bin": {
"rollup": "dist/bin/rollup"
}
},
"@types/node": {
- "version": "18.11.12",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.12.tgz",
- "integrity": "sha512-FgD3NtTAKvyMmD44T07zz2fEf+OKwutgBCEVM8GcvMGVGaDktiLNTDvPwC/LUe3PinMW+X6CuLOF2Ui1mAlSXg=="
+ "version": "18.11.13",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz",
+ "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w=="
},
"@types/object-path": {
"version": "0.11.1",
}
},
"mocha": {
- "version": "10.1.0",
- "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.1.0.tgz",
- "integrity": "sha512-vUF7IYxEoN7XhQpFLxQAEMtE4W91acW4B6En9l97MwE9stL1A9gusXfoHZCLVHDUJ/7V5+lbCM6yMqzo5vNymg==",
+ "version": "10.2.0",
+ "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz",
+ "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==",
"dev": true,
"requires": {
"ansi-colors": "4.1.1",
}
},
"rollup": {
- "version": "3.7.0",
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.7.0.tgz",
- "integrity": "sha512-FIJe0msW9P7L9BTfvaJyvn1U1BVCNTL3w8O+PKIrCyiMLg+rIUGb4MbcgVZ10Lnm1uWXOTOWRNARjfXC1+M12Q==",
+ "version": "3.7.3",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.7.3.tgz",
+ "integrity": "sha512-7e68MQbAWCX6mI4/0lG1WHd+NdNAlVamg0Zkd+8LZ/oXojligdGnCNyHlzXqXCZObyjs5FRc3AH0b17iJESGIQ==",
"dev": true,
"requires": {
"fsevents": "~2.3.2"
"@rollup/plugin-json": "^5.0.2",
"@types/mocha": "^10.0.1",
"@types/mochawesome": "^6.2.1",
- "@types/node": "^18.11.12",
+ "@types/node": "^18.11.13",
"@types/proper-lockfile": "^4.1.2",
"@types/tar": "^6.1.3",
"@types/ws": "^8.5.3",
"expect": "^29.3.1",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
- "mocha": "^10.1.0",
+ "mocha": "^10.2.0",
"mochawesome": "^7.1.3",
"prettier": "^2.8.1",
"release-it": "^15.5.1",
"robohydra": "^0.6.9",
- "rollup": "^3.7.0",
+ "rollup": "^3.7.3",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-delete": "^2.0.0",
}
}
- private static isObject(item): boolean {
+ private static isObject(item: unknown): boolean {
return item && typeof item === 'object' && Array.isArray(item) === false;
}
return Utils.formatDurationMilliSeconds(duration * 1000);
}
- public static convertToDate(value: unknown): Date {
- // Check
- if (!value) {
- return value as Date;
+ public static convertToDate(value: unknown): Date | null | undefined {
+ if (Utils.isNullOrUndefined(value)) {
+ return value as null | undefined;
+ }
+ if (value instanceof Date) {
+ return value;
}
- // Check Type
- if (!(value instanceof Date)) {
- return new Date(value as string);
+ if (Utils.isString(value) || typeof value === 'number') {
+ return new Date(value as string | number);
}
- return value;
+ return null;
}
public static convertToInt(value: unknown): number {
it('Verify convertToDate()', () => {
expect(Utils.convertToDate(undefined)).toBe(undefined);
expect(Utils.convertToDate(null)).toBe(null);
- expect(Utils.convertToDate(0)).toBe(0);
+ const invalidDate = Utils.convertToDate('');
+ expect(invalidDate instanceof Date && !isNaN(invalidDate.getTime())).toBe(false);
+ expect(Utils.convertToDate(0)).toStrictEqual(new Date('1970-01-01T00:00:00.000Z'));
+ expect(Utils.convertToDate([])).toBe(null);
+ expect(Utils.convertToDate({})).toBe(null);
+ expect(Utils.convertToDate(new Map())).toBe(null);
+ expect(Utils.convertToDate(new Set())).toBe(null);
+ expect(Utils.convertToDate(new WeakMap())).toBe(null);
+ expect(Utils.convertToDate(new WeakSet())).toBe(null);
const dateStr = '2020-01-01T00:00:00.000Z';
let date = Utils.convertToDate(dateStr);
expect(date).toBeInstanceOf(Date);
- expect(date.getUTCFullYear()).toBe(2020);
- expect(date.getUTCMonth()).toBe(0);
- expect(date.getUTCDate()).toBe(1);
- expect(date.getUTCHours()).toBe(0);
- expect(date.getUTCMinutes()).toBe(0);
- expect(date.getUTCSeconds()).toBe(0);
- expect(date.getUTCMilliseconds()).toBe(0);
+ expect(date).toStrictEqual(new Date(dateStr));
date = Utils.convertToDate(new Date(dateStr));
expect(date).toBeInstanceOf(Date);
- expect(date.getUTCFullYear()).toBe(2020);
- expect(date.getUTCMonth()).toBe(0);
- expect(date.getUTCDate()).toBe(1);
- expect(date.getUTCHours()).toBe(0);
- expect(date.getUTCMinutes()).toBe(0);
- expect(date.getUTCSeconds()).toBe(0);
- expect(date.getUTCMilliseconds()).toBe(0);
+ expect(date).toStrictEqual(new Date(dateStr));
});
it('Verify convertToInt()', () => {
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
- "@types/node": "^18.11.12",
+ "@types/node": "^18.11.13",
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
"@vue/cli": "~5.0.8",
"dev": true
},
"node_modules/@types/node": {
- "version": "18.11.12",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.12.tgz",
- "integrity": "sha512-FgD3NtTAKvyMmD44T07zz2fEf+OKwutgBCEVM8GcvMGVGaDktiLNTDvPwC/LUe3PinMW+X6CuLOF2Ui1mAlSXg==",
+ "version": "18.11.13",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz",
+ "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==",
"dev": true
},
"node_modules/@types/normalize-package-data": {
}
},
"node_modules/postcss": {
- "version": "8.4.19",
- "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.19.tgz",
- "integrity": "sha512-h+pbPsyhlYj6N2ozBmHhHrs9DzGmbaarbLvWipMRO7RLS+v4onj26MPFXA5OBYFxyqYhUJK456SwDcY9H2/zsA==",
+ "version": "8.4.20",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz",
+ "integrity": "sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g==",
"funding": [
{
"type": "opencollective",
"dev": true
},
"@types/node": {
- "version": "18.11.12",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.12.tgz",
- "integrity": "sha512-FgD3NtTAKvyMmD44T07zz2fEf+OKwutgBCEVM8GcvMGVGaDktiLNTDvPwC/LUe3PinMW+X6CuLOF2Ui1mAlSXg==",
+ "version": "18.11.13",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz",
+ "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==",
"dev": true
},
"@types/normalize-package-data": {
"dev": true
},
"postcss": {
- "version": "8.4.19",
- "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.19.tgz",
- "integrity": "sha512-h+pbPsyhlYj6N2ozBmHhHrs9DzGmbaarbLvWipMRO7RLS+v4onj26MPFXA5OBYFxyqYhUJK456SwDcY9H2/zsA==",
+ "version": "8.4.20",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz",
+ "integrity": "sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g==",
"requires": {
"nanoid": "^3.3.4",
"picocolors": "^1.0.0",
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
- "@types/node": "^18.11.12",
+ "@types/node": "^18.11.13",
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
"@vue/cli": "~5.0.8",