mdtg 4.1.1 → 4.1.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdtg",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "type": "module",
@@ -18,11 +18,12 @@
18
18
  "bench": "vitest bench --run",
19
19
  "coverage": "vitest run --coverage",
20
20
  "format": "biome check .",
21
+ "knip": "knip",
21
22
  "prelint": "npm run format && npm run prettier",
22
23
  "lint": "biome lint .",
23
- "knip": "knip",
24
24
  "prettier": "prettier **/*.yml",
25
- "test": "vitest run"
25
+ "test": "vitest run",
26
+ "test:mutation": "stryker run"
26
27
  },
27
28
  "keywords": [
28
29
  "military",
@@ -34,6 +35,7 @@
34
35
  "description": "This package offers you methods to convert Date Objects to military date time and vice versa",
35
36
  "devDependencies": {
36
37
  "@biomejs/biome": "2.5.15",
38
+ "@stryker-mutator/core": "10.0.0",
37
39
  "@vitest/coverage-v8": "5.0.3",
38
40
  "knip": "6.39.0",
39
41
  "prettier": "3.9.9",
package/src/constants.js CHANGED
@@ -42,7 +42,7 @@ export const OFFSETS = Object.freeze({
42
42
  M: -13,
43
43
  });
44
44
 
45
- export const SHORT_FORMAT_REGEX = /^[0-9]{6}[A-Z]$/;
45
+ export const SHORT_FORMAT_REGEX = /^[0-9]{6}[A-Z]$/i;
46
46
  export const STANDARD_FORMAT_REGEX =
47
47
  /^[0-9]{6}[A-Z](jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i;
48
48
  export const EXTENDED_FORMAT_REGEX =
package/src/format.js CHANGED
@@ -9,8 +9,7 @@ import {
9
9
 
10
10
  const normalizeNumber = (number) => String(number).padStart(2, "0");
11
11
 
12
- const createDateWithOffset = (date, offset) =>
13
- new Date(date.getTime() - offset * 60 * 60 * 1000);
12
+ const createDateWithOffset = (date, offset) => new Date(date.getTime() - offset * 60 * 60 * 1000);
14
13
 
15
14
  const buildShort = (date, timezone) => {
16
15
  const result = [date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes()]
@@ -26,18 +25,9 @@ const buildShort = (date, timezone) => {
26
25
  };
27
26
 
28
27
  const buildExtended = (date, timezone) => {
29
- const result = [
30
- date.getUTCDate(),
31
- date.getUTCHours(),
32
- date.getUTCMinutes(),
33
- date.getUTCSeconds(),
34
- ]
28
+ const result = [date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()]
35
29
  .map(normalizeNumber)
36
- .concat(
37
- timezone,
38
- MONTHS[date.getUTCMonth()],
39
- normalizeNumber(date.getUTCFullYear() % 100),
40
- )
30
+ .concat(timezone, MONTHS[date.getUTCMonth()], normalizeNumber(date.getUTCFullYear() % 100))
41
31
  .join("");
42
32
 
43
33
  if (!isExtendedFormat(result)) {
package/src/index.d.ts CHANGED
@@ -5,14 +5,8 @@ declare function formatMDTG(
5
5
  options?: { form?: MDTGFormat; timezone?: string },
6
6
  ): string;
7
7
 
8
- declare function isValidMDTG(
9
- mdtg: string,
10
- options?: { referenceDate?: Date },
11
- ): boolean;
12
- declare function parseMDTG(
13
- mdtg: string,
14
- options?: { referenceDate?: Date },
15
- ): Date;
8
+ declare function isValidMDTG(mdtg: string, options?: { referenceDate?: Date }): boolean;
9
+ declare function parseMDTG(mdtg: string, options?: { referenceDate?: Date }): Date;
16
10
 
17
11
  declare function isExtendedFormat(mdtg: string): boolean;
18
12
  declare function isMDTG(mdtg: string): boolean;
package/src/parse.js CHANGED
@@ -37,9 +37,7 @@ const parseWithMonth = (value, { hasSeconds, timezoneIndex, monthStart }) => {
37
37
  const minutes = parseInteger(value.slice(4, 6));
38
38
  const seconds = hasSeconds ? parseInteger(value.slice(6, 8)) : undefined;
39
39
  const timezone = value.slice(timezoneIndex, timezoneIndex + 1).toUpperCase();
40
- const month = MONTHS.indexOf(
41
- value.slice(monthStart, monthStart + 3).toLowerCase(),
42
- );
40
+ const month = MONTHS.indexOf(value.slice(monthStart, monthStart + 3).toLowerCase());
43
41
  const year = 2000 + parseInteger(value.slice(monthStart + 3, monthStart + 5));
44
42
 
45
43
  validateDateTime({
package/src/validation.js CHANGED
@@ -5,8 +5,7 @@ import {
5
5
  STANDARD_FORMAT_REGEX,
6
6
  } from "./constants.js";
7
7
 
8
- export const isShortFormat = (value) =>
9
- typeof value === "string" && SHORT_FORMAT_REGEX.test(value);
8
+ export const isShortFormat = (value) => typeof value === "string" && SHORT_FORMAT_REGEX.test(value);
10
9
 
11
10
  export const isStandardFormat = (value) =>
12
11
  typeof value === "string" && STANDARD_FORMAT_REGEX.test(value);
@@ -24,18 +23,11 @@ export const validateDate = (date) => {
24
23
  };
25
24
 
26
25
  export const validateTimezone = (timezone) => {
27
- const key = timezone?.toUpperCase();
26
+ const key = typeof timezone === "string" ? timezone.toUpperCase() : "Z";
28
27
  return key in OFFSETS ? key : "Z";
29
28
  };
30
29
 
31
- export const validateDateTime = ({
32
- year,
33
- month,
34
- day,
35
- hours,
36
- minutes,
37
- seconds,
38
- }) => {
30
+ export const validateDateTime = ({ year, month, day, hours, minutes, seconds }) => {
39
31
  const candidate = new Date(0);
40
32
  candidate.setUTCFullYear(year, month, day);
41
33
  candidate.setUTCHours(hours, minutes, seconds ?? 0, 0);