mdtg 0.0.2 → 0.0.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/README.md CHANGED
@@ -15,13 +15,13 @@ npm install mdtg
15
15
  ### Usage
16
16
 
17
17
  ```js
18
- import { MDTG } from 'mdtg';
18
+ import { MDTG } from "mdtg";
19
19
 
20
20
  const mdtg = new MDTG();
21
21
 
22
- console.log(mdtg.toMDT({form: "short"}));
23
- console.log(mdtg.toMDT({form: "shortened"}));
24
- console.log(mdtg.toMDT({form: "long"}));
22
+ console.log(mdtg.toMDT({ form: "short" }));
23
+ console.log(mdtg.toMDT({ form: "shortened" }));
24
+ console.log(mdtg.toMDT({ form: "long" }));
25
25
 
26
26
  console.log(MDTG.parse("12135530Zaug24"));
27
27
  console.log(MDTG.parse("121355Zaug24"));
@@ -0,0 +1,21 @@
1
+ import pluginJs from "@eslint/js";
2
+
3
+ export default [
4
+ pluginJs.configs.recommended,
5
+ {
6
+ rules: {
7
+ "no-unused-vars": [
8
+ "error",
9
+ {
10
+ varsIgnorePattern: "^_",
11
+ },
12
+ ],
13
+ },
14
+ },
15
+ {
16
+ files: ["**/*.test.js"],
17
+ rules: {
18
+ "no-undef": "off",
19
+ },
20
+ },
21
+ ];
package/index.js CHANGED
@@ -1,100 +1,131 @@
1
1
  export class MDTG {
2
- #currentDate = null;
3
- static months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
2
+ #currentDate = null;
3
+ static months = [
4
+ "jan",
5
+ "feb",
6
+ "mar",
7
+ "apr",
8
+ "may",
9
+ "jun",
10
+ "jul",
11
+ "aug",
12
+ "sep",
13
+ "oct",
14
+ "nov",
15
+ "dec",
16
+ ];
4
17
 
5
- constructor(date) {
6
- this.#currentDate = date ?? new Date();
7
- }
18
+ constructor(date) {
19
+ this.#currentDate = date ?? new Date();
20
+ }
8
21
 
9
- static isShortFormat(str) {
10
- return /^[0-9]{6}Z$/.test(str);
11
- }
22
+ static isShortFormat(str) {
23
+ return /^[0-9]{6}Z$/.test(str);
24
+ }
12
25
 
13
- static isShortenedFormat(str) {
14
- return /^[0-9]{6}Z(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i.test(str);
15
- }
26
+ static isShortenedFormat(str) {
27
+ return /^[0-9]{6}Z(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i.test(
28
+ str,
29
+ );
30
+ }
16
31
 
17
- static isLongFormat(str) {
18
- return /^[0-9]{8}Z(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i.test(str);
19
- }
32
+ static isLongFormat(str) {
33
+ return /^[0-9]{8}Z(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i.test(
34
+ str,
35
+ );
36
+ }
20
37
 
21
- #toShortMDT() {
22
- const shortMDT = String(this.#currentDate.getDate()).padStart(2, "0") +
23
- String(this.#currentDate.getHours()).padStart(2, "0") +
24
- String(this.#currentDate.getMinutes()).padStart(2, "0") + "Z";
25
- if (!MDTG.isShortFormat(shortMDT)) {
26
- throw new Error('There was an error while building short MDT');
27
- }
28
- return shortMDT;
38
+ #toShortMDT() {
39
+ const shortMDT =
40
+ String(this.#currentDate.getDate()).padStart(2, "0") +
41
+ String(this.#currentDate.getHours()).padStart(2, "0") +
42
+ String(this.#currentDate.getMinutes()).padStart(2, "0") +
43
+ "Z";
44
+ if (!MDTG.isShortFormat(shortMDT)) {
45
+ throw new Error("There was an error while building short MDT");
29
46
  }
47
+ return shortMDT;
48
+ }
30
49
 
31
- #toLongMDT() {
32
- const longMDT = String(this.#currentDate.getDate()).padStart(2, "0") +
33
- String(this.#currentDate.getHours()).padStart(2, "0") +
34
- String(this.#currentDate.getMinutes()).padStart(2, "0") +
35
- String(this.#currentDate.getSeconds()).padStart(2, "0") + "Z" +
36
- MDTG.months[this.#currentDate.getMonth()] +
37
- String(this.#currentDate.getFullYear() % 2000).padStart(2, "0")
38
- if (!MDTG.isLongFormat(longMDT)) {
39
- throw new Error('There was an error while building long MDT');
40
- }
41
- return longMDT;
50
+ #toLongMDT() {
51
+ const longMDT =
52
+ String(this.#currentDate.getDate()).padStart(2, "0") +
53
+ String(this.#currentDate.getHours()).padStart(2, "0") +
54
+ String(this.#currentDate.getMinutes()).padStart(2, "0") +
55
+ String(this.#currentDate.getSeconds()).padStart(2, "0") +
56
+ "Z" +
57
+ MDTG.months[this.#currentDate.getMonth()] +
58
+ String(this.#currentDate.getFullYear() % 2000).padStart(2, "0");
59
+ if (!MDTG.isLongFormat(longMDT)) {
60
+ throw new Error("There was an error while building long MDT");
42
61
  }
62
+ return longMDT;
63
+ }
43
64
 
44
- #toShortenedMDT() {
45
- const shortenedMDT = this.#toShortMDT() + MDTG.months[this.#currentDate.getMonth()]
46
- + String(this.#currentDate.getFullYear() % 2000).padStart(2, "0");
47
- if (!MDTG.isShortenedFormat(shortenedMDT)) {
48
- throw new Error('There was an error while building shortened MDT');
49
- }
50
- return shortenedMDT;
65
+ #toShortenedMDT() {
66
+ const shortenedMDT =
67
+ this.#toShortMDT() +
68
+ MDTG.months[this.#currentDate.getMonth()] +
69
+ String(this.#currentDate.getFullYear() % 2000).padStart(2, "0");
70
+ if (!MDTG.isShortenedFormat(shortenedMDT)) {
71
+ throw new Error("There was an error while building shortened MDT");
51
72
  }
73
+ return shortenedMDT;
74
+ }
52
75
 
53
- toMDT(options) {
54
- if (options?.form === "short") {
55
- return this.#toShortMDT();
56
- } else if (options?.form === "shortened") {
57
- return this.#toShortenedMDT();
58
- } else {
59
- return this.#toLongMDT();
60
- }
76
+ toMDT(options) {
77
+ if (options?.form === "short") {
78
+ return this.#toShortMDT();
79
+ } else if (options?.form === "shortened") {
80
+ return this.#toShortenedMDT();
81
+ } else {
82
+ return this.#toLongMDT();
61
83
  }
84
+ }
62
85
 
63
- static parse(str) {
64
- if (MDTG.isShortFormat(str)) {
65
- const day = Number.parseInt(str.slice(0, 2));
66
- const hours = Number.parseInt(str.slice(2, 4));
67
- const minutes = Number.parseInt(str.slice(4, 6));
68
- const _timezone = str.slice(-1);
86
+ static parse(str) {
87
+ if (MDTG.isShortFormat(str)) {
88
+ const day = Number.parseInt(str.slice(0, 2));
89
+ const hours = Number.parseInt(str.slice(2, 4));
90
+ const minutes = Number.parseInt(str.slice(4, 6));
91
+ const _timezone = str.slice(-1);
69
92
 
70
- const today = new Date();
71
- const date = new Date(today.getFullYear(), today.getMonth(), day, hours, minutes, 0, 0);
72
- return date;
73
- } else if (MDTG.isShortenedFormat(str)) {
74
- const day = Number.parseInt(str.slice(0, 2));
75
- const hours = Number.parseInt(str.slice(2, 4));
76
- const minutes = Number.parseInt(str.slice(4, 6));
77
- const _timezone = str.slice(6, 7);
78
- const month = MDTG.months.indexOf(str.slice(7, 10).toLowerCase());
79
- const year = 2000 + Number.parseInt(str.slice(10, 12));
80
- const date = new Date(year, month, day, hours, minutes, 0, 0);
81
- return date;
82
- } else if (MDTG.isLongFormat(str)) {
83
- const day = Number.parseInt(str.slice(0, 2));
84
- const hours = Number.parseInt(str.slice(2, 4));
85
- const minutes = Number.parseInt(str.slice(4, 6));
86
- const seconds = Number.parseInt(str.slice(6, 8));
87
- const _timezone = str.slice(8, 9);
88
- const month = MDTG.months.indexOf(str.slice(9, 12).toLowerCase());
89
- const year = 2000 + Number.parseInt(str.slice(12, 14));
90
- const date = new Date(year, month, day, hours, minutes, seconds, 0);
91
- return date;
92
- } else {
93
- throw Error('There was an error while parsing the string ' + str);
94
- }
93
+ const today = new Date();
94
+ const date = new Date(
95
+ today.getFullYear(),
96
+ today.getMonth(),
97
+ day,
98
+ hours,
99
+ minutes,
100
+ 0,
101
+ 0,
102
+ );
103
+ return date;
104
+ } else if (MDTG.isShortenedFormat(str)) {
105
+ const day = Number.parseInt(str.slice(0, 2));
106
+ const hours = Number.parseInt(str.slice(2, 4));
107
+ const minutes = Number.parseInt(str.slice(4, 6));
108
+ const _timezone = str.slice(6, 7);
109
+ const month = MDTG.months.indexOf(str.slice(7, 10).toLowerCase());
110
+ const year = 2000 + Number.parseInt(str.slice(10, 12));
111
+ const date = new Date(year, month, day, hours, minutes, 0, 0);
112
+ return date;
113
+ } else if (MDTG.isLongFormat(str)) {
114
+ const day = Number.parseInt(str.slice(0, 2));
115
+ const hours = Number.parseInt(str.slice(2, 4));
116
+ const minutes = Number.parseInt(str.slice(4, 6));
117
+ const seconds = Number.parseInt(str.slice(6, 8));
118
+ const _timezone = str.slice(8, 9);
119
+ const month = MDTG.months.indexOf(str.slice(9, 12).toLowerCase());
120
+ const year = 2000 + Number.parseInt(str.slice(12, 14));
121
+ const date = new Date(year, month, day, hours, minutes, seconds, 0);
122
+ return date;
123
+ } else {
124
+ throw Error("There was an error while parsing the string " + str);
95
125
  }
126
+ }
96
127
 
97
- toDate() {
98
- return this.#currentDate;
99
- }
100
- }
128
+ toDate() {
129
+ return this.#currentDate;
130
+ }
131
+ }
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "mdtg",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
7
+ "format": "prettier --check .",
8
+ "lint": "eslint .",
7
9
  "test": "node index.test.js"
8
10
  },
9
11
  "keywords": [
@@ -13,5 +15,9 @@
13
15
  ],
14
16
  "author": "0xflotus",
15
17
  "license": "MIT",
16
- "description": "This package offers you methods to convert Date Objects to military date time and vice versa"
18
+ "description": "This package offers you methods to convert Date Objects to military date time and vice versa",
19
+ "devDependencies": {
20
+ "eslint": "8.57.1",
21
+ "prettier": "3.5.2"
22
+ }
17
23
  }