typepki-strconv 0.1.0
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/LICENSE +21 -0
- package/README.md +22 -0
- package/dist/import/conv.d.mts +193 -0
- package/dist/import/conv.d.mts.map +1 -0
- package/dist/import/conv_arybuf.d.mts +30 -0
- package/dist/import/conv_arybuf.d.mts.map +1 -0
- package/dist/import/conv_ba.d.mts +27 -0
- package/dist/import/conv_ba.d.mts.map +1 -0
- package/dist/import/conv_ip.d.mts +69 -0
- package/dist/import/conv_ip.d.mts.map +1 -0
- package/dist/import/conv_iso88591.d.mts +19 -0
- package/dist/import/conv_iso88591.d.mts.map +1 -0
- package/dist/import/conv_pem.d.mts +109 -0
- package/dist/import/conv_pem.d.mts.map +1 -0
- package/dist/import/conv_ucs2.d.mts +14 -0
- package/dist/import/conv_ucs2.d.mts.map +1 -0
- package/dist/import/conv_uricmp.d.mts +29 -0
- package/dist/import/conv_uricmp.d.mts.map +1 -0
- package/dist/import/conv_zulu.d.mts +120 -0
- package/dist/import/conv_zulu.d.mts.map +1 -0
- package/dist/import/index.d.mts +22 -0
- package/dist/import/index.d.mts.map +1 -0
- package/dist/import/index.mjs +4 -0
- package/dist/require/index.cjs +4 -0
- package/dist/require/index.d.cts +2 -0
- package/dist/require/index.d.cts.map +1 -0
- package/package.json +72 -0
- package/src/conv.mts +367 -0
- package/src/conv.test.mts +99 -0
- package/src/conv_arybuf.mts +53 -0
- package/src/conv_arybuf.test.mts +16 -0
- package/src/conv_ba.mts +52 -0
- package/src/conv_ip.mts +226 -0
- package/src/conv_iso88591.mts +63 -0
- package/src/conv_pem.mts +160 -0
- package/src/conv_ucs2.mts +47 -0
- package/src/conv_uricmp.mts +48 -0
- package/src/conv_uricmp.test.mts +16 -0
- package/src/conv_zulu.mts +208 -0
- package/src/conv_zulu.test.mts +49 -0
- package/src/index.cts +1 -0
- package/src/index.mts +100 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { hextoutf8 } from "./conv.mts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* convert UCS-2 hexadecimal stirng to UTF-8 string
|
|
5
|
+
* @param s - hexadecimal string of UCS-2 string (ex. "0066")
|
|
6
|
+
* @return UTF-8 string
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* This function converts hexadecimal value of UCS-2 string to
|
|
10
|
+
* UTF-8 string.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ucs2hextoutf8("006600fc0072") -> "für"
|
|
14
|
+
*/
|
|
15
|
+
/*
|
|
16
|
+
See: http://nomenclator.la.coocan.jp/unicode/ucs_utf.htm
|
|
17
|
+
UCS-2 to UTF-8
|
|
18
|
+
UCS-2 code point | UCS-2 bytes | UTF-8 bytes
|
|
19
|
+
U+0000 .. U+007F | 00000000-0xxxxxxx | 0xxxxxxx (1 byte)
|
|
20
|
+
U+0080 .. U+07FF | 00000xxx-xxyyyyyy | 110xxxxx 10yyyyyy (2 byte)
|
|
21
|
+
U+0800 .. U+FFFF | xxxxyyyy-yyzzzzzz | 1110xxxx 10yyyyyy 10zzzzzz (3 byte)
|
|
22
|
+
*/
|
|
23
|
+
export function ucs2hextoutf8(s: string): string {
|
|
24
|
+
function _conv(s: string): string {
|
|
25
|
+
const i1: number = parseInt(s.substr(0, 2), 16);
|
|
26
|
+
const i2: number = parseInt(s.substr(2), 16);
|
|
27
|
+
if (i1 === 0 && i2 < 0x80) {
|
|
28
|
+
// 1 byte
|
|
29
|
+
return String.fromCharCode(i2);
|
|
30
|
+
}
|
|
31
|
+
if (i1 < 8) {
|
|
32
|
+
// 2 bytes
|
|
33
|
+
const u1 = 0xc0 | ((i1 & 0x07) << 3) | ((i2 & 0xc0) >> 6);
|
|
34
|
+
const u2 = 0x80 | (i2 & 0x3f);
|
|
35
|
+
return hextoutf8(u1.toString(16) + u2.toString(16));
|
|
36
|
+
}
|
|
37
|
+
// 3 bytes
|
|
38
|
+
const u1 = 0xe0 | ((i1 & 0xf0) >> 4);
|
|
39
|
+
const u2 = 0x80 | ((i1 & 0x0f) << 2) | ((i2 & 0xc0) >> 6);
|
|
40
|
+
const u3 = 0x80 | (i2 & 0x3f);
|
|
41
|
+
return hextoutf8(u1.toString(16) + u2.toString(16) + u3.toString(16));
|
|
42
|
+
}
|
|
43
|
+
const a: string[] | null = s.match(/.{4}/g);
|
|
44
|
+
if (a == null) return "";
|
|
45
|
+
const a2: string[] | null = a.map(_conv);
|
|
46
|
+
return a2.join("");
|
|
47
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { stohex } from "./conv_ba.mts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* convert a URLComponent string such like "%67%68" to a hexadecimal string.
|
|
5
|
+
* @param s - URIComponent string such like "%67%68"
|
|
6
|
+
* @return hexadecimal string
|
|
7
|
+
* @example
|
|
8
|
+
* uricmptohex("%67%68") -> "6768"
|
|
9
|
+
*/
|
|
10
|
+
export function uricmptohex(s: string): string {
|
|
11
|
+
return s.replace(/%/g, "");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* convert a hexadecimal string to a URLComponent string such like "%67%68".
|
|
16
|
+
* @param s - hexadecimal string
|
|
17
|
+
* @return URIComponent string such like "%67%68"
|
|
18
|
+
* @example
|
|
19
|
+
* hextouricmp("6768") -> "%67%68"
|
|
20
|
+
*/
|
|
21
|
+
export function hextouricmp(s: string): string {
|
|
22
|
+
return s.replace(/(..)/g, "%$1");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* convert UTF8 hexadecimal string to a URLComponent string such like "%67%68".
|
|
27
|
+
* @param u8 - UTF8 hexadecimal string
|
|
28
|
+
* @return URIComponent string such like "%67%68"
|
|
29
|
+
*
|
|
30
|
+
* @description
|
|
31
|
+
* Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not
|
|
32
|
+
* converted to "%xx" format by builtin 'encodeURIComponent()' function.
|
|
33
|
+
* However this 'encodeURIComponentAll()' function will convert
|
|
34
|
+
* all of characters into "%xx" format.
|
|
35
|
+
*/
|
|
36
|
+
export function encodeURIComponentAll(u8: string): string {
|
|
37
|
+
const s = encodeURIComponent(u8);
|
|
38
|
+
let s2 = "";
|
|
39
|
+
for (let i = 0; i < s.length; i++) {
|
|
40
|
+
if (s[i] === "%") {
|
|
41
|
+
s2 = s2 + s.substr(i, 3);
|
|
42
|
+
i = i + 2;
|
|
43
|
+
} else {
|
|
44
|
+
s2 = `${s2}%${stohex(s[i])}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return s2;
|
|
48
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { encodeURIComponentAll, hextouricmp, uricmptohex } from "./index.mts";
|
|
4
|
+
|
|
5
|
+
test("uricmptohex", () => {
|
|
6
|
+
expect(uricmptohex("%67%68")).toBe("6768");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("hextouricmp", () => {
|
|
10
|
+
expect(hextouricmp("6768")).toBe("%67%68");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("encodeURIComponentAll", () => {
|
|
14
|
+
expect(encodeURIComponentAll("test")).toBe("%74%65%73%74");
|
|
15
|
+
expect(encodeURIComponentAll("aあa")).toBe("%61%E3%81%82%61");
|
|
16
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GeneralizedTime or UTCTime string to milliseconds from Unix origin
|
|
3
|
+
* @param sZulu - GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
|
|
4
|
+
* @return milliseconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
|
|
5
|
+
*
|
|
6
|
+
* @description
|
|
7
|
+
* This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
|
|
8
|
+
* UTCTime string (i.e. YYMMDDHHmmSSZ) to milliseconds from Unix origin time
|
|
9
|
+
* (i.e. Jan 1 1970 0:00:00 UTC).
|
|
10
|
+
* Argument string may have fraction of seconds and
|
|
11
|
+
* its length is one or more digits such as "20170410235959.1234567Z".
|
|
12
|
+
* As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
|
|
13
|
+
* If year "YY" is equal or greater than 50 then it is 19YY.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* zulutomsec( "071231235959Z") -> 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
17
|
+
* zulutomsec( "071231235959.1Z") -> 1199145599100 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
18
|
+
* zulutomsec( "071231235959.12345Z") -> 1199145599123 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
19
|
+
* zulutomsec("20071231235959Z") -> 1199145599000 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
20
|
+
* zulutomsec( "931231235959Z") -> -410227201000 #Mon, 31 Dec 1956 23:59:59 GMT
|
|
21
|
+
*/
|
|
22
|
+
export function zulutomsec(sZulu: string): number {
|
|
23
|
+
let s: string = sZulu;
|
|
24
|
+
let year: number;
|
|
25
|
+
let month: number;
|
|
26
|
+
let day: number;
|
|
27
|
+
let hour: number;
|
|
28
|
+
let min: number;
|
|
29
|
+
let sec: number;
|
|
30
|
+
let msec: number;
|
|
31
|
+
let sFrac: string;
|
|
32
|
+
let sMsec: string;
|
|
33
|
+
|
|
34
|
+
s = timetogen(s);
|
|
35
|
+
const matchResult = s.match(
|
|
36
|
+
/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(|\.\d+)Z$/,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (matchResult) {
|
|
40
|
+
year = parseInt(matchResult[1]);
|
|
41
|
+
month = parseInt(matchResult[2]) - 1;
|
|
42
|
+
day = parseInt(matchResult[3]);
|
|
43
|
+
hour = parseInt(matchResult[4]);
|
|
44
|
+
min = parseInt(matchResult[5]);
|
|
45
|
+
sec = parseInt(matchResult[6]);
|
|
46
|
+
msec = 0;
|
|
47
|
+
|
|
48
|
+
sFrac = matchResult[7];
|
|
49
|
+
if (sFrac !== "") {
|
|
50
|
+
sMsec = `${sFrac.substr(1)}00`.substr(0, 3); // .12 -> 012
|
|
51
|
+
msec = parseInt(sMsec);
|
|
52
|
+
}
|
|
53
|
+
return Date.UTC(year, month, day, hour, min, sec, msec);
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`unsupported zulu format: ${s}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Unix origin milliseconds GeneralizedTime string
|
|
60
|
+
* @param n - milliseconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
|
|
61
|
+
* @return GeneralizedTime string (ex. 20170412235959.384Z)
|
|
62
|
+
*
|
|
63
|
+
* @description
|
|
64
|
+
* This function converts from milliseconds of Unix origin time (ex. 1199145599000
|
|
65
|
+
* for 31 Dec 2007 23:59:59 GMT) to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ).
|
|
66
|
+
* The result string may have a fraction of second.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* msectozulu(1199145599000) -> "20071231235959Z" #Mon, 31 Dec 2007 23:59:59 GMT
|
|
70
|
+
* msectozulu(1199145599100) -> "20071231235959.1Z" #Mon, 31 Dec 2007 23:59:59.1 GMT
|
|
71
|
+
* msectozulu(1199145599123) -> "20071231235959.123Z" #Mon, 31 Dec 2007 23:59:59.123 GMT
|
|
72
|
+
*/
|
|
73
|
+
export function msectozulu(n: number): string {
|
|
74
|
+
const d = new Date(n);
|
|
75
|
+
const year = `0000${d.getUTCFullYear()}`.slice(-4);
|
|
76
|
+
const mon = `00${d.getUTCMonth() + 1}`.slice(-2);
|
|
77
|
+
const day = `00${d.getUTCDate()}`.slice(-2);
|
|
78
|
+
const hour = `00${d.getUTCHours()}`.slice(-2);
|
|
79
|
+
const min = `00${d.getUTCMinutes()}`.slice(-2);
|
|
80
|
+
const sec = `00${d.getUTCSeconds()}`.slice(-2);
|
|
81
|
+
let msec = `000${d.getUTCMilliseconds()}`.slice(-3);
|
|
82
|
+
msec = msec.replace(/0+$/, "");
|
|
83
|
+
msec = msec !== "" ? `.${msec}` : msec;
|
|
84
|
+
return `${year + mon + day + hour + min + sec + msec}Z`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* GeneralizedTime or UTCTime string to seconds from Unix origin
|
|
89
|
+
* @param s - GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
|
|
90
|
+
* @return seconds from Unix origin time (i.e. Jan 1, 1970 0:00:00 UTC)
|
|
91
|
+
*
|
|
92
|
+
* @description
|
|
93
|
+
* This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
|
|
94
|
+
* UTCTime string (i.e. YYMMDDHHmmSSZ) to seconds from Unix origin time
|
|
95
|
+
* (i.e. Jan 1 1970 0:00:00 UTC). Argument string may have fraction of seconds
|
|
96
|
+
* however result value will be omitted.
|
|
97
|
+
* As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
|
|
98
|
+
* If year "YY" is equal or greater than 50 then it is 19YY.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* zulutosec( "071231235959Z") -> 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
102
|
+
* zulutosec( "071231235959.1Z") -> 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
103
|
+
* zulutosec("20071231235959Z") -> 1199145599 #Mon, 31 Dec 2007 23:59:59 GMT
|
|
104
|
+
*/
|
|
105
|
+
export function zulutosec(s: string): number {
|
|
106
|
+
return Math.round(zulutomsec(s) / 1000.0);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* GeneralizedTime or UTCTime string to Date object
|
|
111
|
+
* @param s - GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
|
|
112
|
+
* @return Date object for specified time
|
|
113
|
+
*
|
|
114
|
+
* @description
|
|
115
|
+
* This function converts from GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
|
|
116
|
+
* UTCTime string (i.e. YYMMDDHHmmSSZ) to Date object.
|
|
117
|
+
* Argument string may have fraction of seconds and
|
|
118
|
+
* its length is one or more digits such as "20170410235959.1234567Z".
|
|
119
|
+
* As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
|
|
120
|
+
* If year "YY" is equal or greater than 50 then it is 19YY.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* zulutodate( "071231235959Z").toUTCString() -> "Mon, 31 Dec 2007 23:59:59 GMT"
|
|
124
|
+
* zulutodate( "071231235959.1Z").toUTCString() -> "Mon, 31 Dec 2007 23:59:59 GMT"
|
|
125
|
+
* zulutodate("20071231235959Z").toUTCString() -> "Mon, 31 Dec 2007 23:59:59 GMT"
|
|
126
|
+
* zulutodate( "071231235959.34Z").getMilliseconds() -> 340
|
|
127
|
+
*/
|
|
128
|
+
export function zulutodate(s: string): Date {
|
|
129
|
+
return new Date(zulutomsec(s));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Date object to zulu time string
|
|
134
|
+
* @param d - Date object for specified time
|
|
135
|
+
* @param flagUTCTime - if this is true year will be YY otherwise YYYY
|
|
136
|
+
* @param flagMilli - if this is true result concludes milliseconds
|
|
137
|
+
* @return GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
|
|
138
|
+
*
|
|
139
|
+
* @description
|
|
140
|
+
* This function converts from Date object to GeneralizedTime string (i.e. YYYYMMDDHHmmSSZ) or
|
|
141
|
+
* UTCTime string (i.e. YYMMDDHHmmSSZ).
|
|
142
|
+
* As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
|
|
143
|
+
* If year "YY" is equal or greater than 50 then it is 19YY.
|
|
144
|
+
* If flagMilli is true its result concludes milliseconds such like
|
|
145
|
+
* "20170520235959.42Z".
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* d = new Date(Date.UTC(2017,4,20,23,59,59,670));
|
|
149
|
+
* datetozulu(d) -> "20170520235959Z"
|
|
150
|
+
* datetozulu(d, true) -> "170520235959Z"
|
|
151
|
+
* datetozulu(d, false, true) -> "20170520235959.67Z"
|
|
152
|
+
*/
|
|
153
|
+
export function datetozulu(
|
|
154
|
+
d: Date,
|
|
155
|
+
flagUTCTime = false,
|
|
156
|
+
flagMilli = false,
|
|
157
|
+
): string {
|
|
158
|
+
let s: string;
|
|
159
|
+
const year = d.getUTCFullYear();
|
|
160
|
+
if (flagUTCTime) {
|
|
161
|
+
if (year < 1950 || 2049 < year)
|
|
162
|
+
throw new Error(`not proper year for UTCTime: ${year}`);
|
|
163
|
+
s = `${year}`.slice(-2);
|
|
164
|
+
} else {
|
|
165
|
+
s = `000${year}`.slice(-4);
|
|
166
|
+
}
|
|
167
|
+
s += `0${d.getUTCMonth() + 1}`.slice(-2);
|
|
168
|
+
s += `0${d.getUTCDate()}`.slice(-2);
|
|
169
|
+
s += `0${d.getUTCHours()}`.slice(-2);
|
|
170
|
+
s += `0${d.getUTCMinutes()}`.slice(-2);
|
|
171
|
+
s += `0${d.getUTCSeconds()}`.slice(-2);
|
|
172
|
+
if (flagMilli) {
|
|
173
|
+
const milli = d.getUTCMilliseconds();
|
|
174
|
+
if (milli !== 0) {
|
|
175
|
+
let sMilli = `00${milli}`.slice(-3);
|
|
176
|
+
sMilli = sMilli.replace(/0+$/g, "");
|
|
177
|
+
s += `.${sMilli}`;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
s += "Z";
|
|
181
|
+
return s;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* GeneralizedTime or UTCTime string to GeneralizedTime
|
|
186
|
+
* @param s - GeneralizedTime or UTCTime string (ex. 20170412235959.384Z)
|
|
187
|
+
* @return GeneralizedTime
|
|
188
|
+
*
|
|
189
|
+
* @description
|
|
190
|
+
* This function converts UTCTime string (i.e. YYMMDDHHmmSSZ ) to
|
|
191
|
+
* GeneralizedTime (YYYYMMDDHHmmSSZ) when the argument 's' is UTCTime.
|
|
192
|
+
* Argument string may have fraction of seconds and
|
|
193
|
+
* its length is one or more digits such as "170410235959.1234567Z".
|
|
194
|
+
* As for UTCTime, if year "YY" is equal or less than 49 then it is 20YY.
|
|
195
|
+
* If year "YY" is equal or greater than 50 then it is 19YY.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* timetogen( "071231235959Z") -> "20071231235959Z"
|
|
199
|
+
* timetogen( "971231235959Z") -> "19971231235959Z"
|
|
200
|
+
* timetogen("20071231235959Z") -> "20071231235959Z"
|
|
201
|
+
* timetogen( "971231235959.123Z") -> "19971231235959.123Z"
|
|
202
|
+
*/
|
|
203
|
+
export function timetogen(s: string): string {
|
|
204
|
+
if (s.match(/^[0-9]{12}Z$/) || s.match(/^[0-9]{12}[.][0-9]*Z$/)) {
|
|
205
|
+
return s.match(/^[0-4]/) ? `20${s}` : `19${s}`;
|
|
206
|
+
}
|
|
207
|
+
return s;
|
|
208
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
datetozulu,
|
|
5
|
+
msectozulu,
|
|
6
|
+
zulutodate,
|
|
7
|
+
zulutomsec,
|
|
8
|
+
zulutosec,
|
|
9
|
+
} from "./index.mts";
|
|
10
|
+
|
|
11
|
+
test("zulutomsec", () => {
|
|
12
|
+
expect(zulutomsec("071231235959Z")).toBe(1199145599000); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
13
|
+
expect(zulutomsec("071231235959.1Z")).toBe(1199145599100); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
14
|
+
expect(zulutomsec("071231235959.12345Z")).toBe(1199145599123); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
15
|
+
expect(zulutomsec("20071231235959Z")).toBe(1199145599000); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
16
|
+
//expect(zulutomsec( "931231235959Z" )).toBe(-410227201000); // Mon, 31 Dec 1956 23:59:59 GMT
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("msectozulu", () => {
|
|
20
|
+
expect(msectozulu(1199145599000)).toBe("20071231235959Z"); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
21
|
+
expect(msectozulu(1199145599100)).toBe("20071231235959.1Z"); // Mon, 31 Dec 2007 23:59:59.1 GMT
|
|
22
|
+
expect(msectozulu(1199145599123)).toBe("20071231235959.123Z"); // Mon, 31 Dec 2007 23:59:59.123 GMT
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("zulutosec", () => {
|
|
26
|
+
expect(zulutosec("071231235959Z")).toBe(1199145599); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
27
|
+
expect(zulutosec("071231235959.1Z")).toBe(1199145599); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
28
|
+
expect(zulutosec("20071231235959Z")).toBe(1199145599); // Mon, 31 Dec 2007 23:59:59 GMT
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("zulutodate", () => {
|
|
32
|
+
expect(zulutodate("071231235959Z").toUTCString()).toBe(
|
|
33
|
+
"Mon, 31 Dec 2007 23:59:59 GMT",
|
|
34
|
+
);
|
|
35
|
+
expect(zulutodate("071231235959.1Z").toUTCString()).toBe(
|
|
36
|
+
"Mon, 31 Dec 2007 23:59:59 GMT",
|
|
37
|
+
);
|
|
38
|
+
expect(zulutodate("20071231235959Z").toUTCString()).toBe(
|
|
39
|
+
"Mon, 31 Dec 2007 23:59:59 GMT",
|
|
40
|
+
);
|
|
41
|
+
expect(zulutodate("071231235959.34Z").getMilliseconds()).toBe(340);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("datetozulu", () => {
|
|
45
|
+
const d = new Date(Date.UTC(2017, 4, 20, 23, 59, 59, 670));
|
|
46
|
+
expect(datetozulu(d)).toBe("20170520235959Z");
|
|
47
|
+
expect(datetozulu(d, true)).toBe("170520235959Z");
|
|
48
|
+
expect(datetozulu(d, false, true)).toBe("20170520235959.67Z");
|
|
49
|
+
});
|
package/src/index.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./index.mts");
|
package/src/index.mts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const VERSION: string = "typepki-strconv 0.1.0 kjur.github.io/typepki-strconv";
|
|
2
|
+
export { VERSION };
|
|
3
|
+
|
|
4
|
+
import { BAtohex, BAtos, stoBA, stohex } from "./conv_ba.mts";
|
|
5
|
+
export { stohex, BAtohex, stoBA, BAtos };
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Dictionary,
|
|
9
|
+
aryval,
|
|
10
|
+
b64tob64u,
|
|
11
|
+
b64tohex,
|
|
12
|
+
b64toutf8,
|
|
13
|
+
b64utob64,
|
|
14
|
+
b64utohex,
|
|
15
|
+
b64utoutf8,
|
|
16
|
+
binstrtobitstr,
|
|
17
|
+
bitstrtobinstr,
|
|
18
|
+
hextob64,
|
|
19
|
+
hextob64u,
|
|
20
|
+
hextorstr,
|
|
21
|
+
hextoutf8,
|
|
22
|
+
inttobitstr,
|
|
23
|
+
namearraytobinstr,
|
|
24
|
+
rstrtob64,
|
|
25
|
+
rstrtohex,
|
|
26
|
+
strpad,
|
|
27
|
+
utf8tob64,
|
|
28
|
+
utf8tob64u,
|
|
29
|
+
utf8tohex,
|
|
30
|
+
} from "./conv.mts";
|
|
31
|
+
export {
|
|
32
|
+
b64tohex,
|
|
33
|
+
hextob64,
|
|
34
|
+
b64toutf8,
|
|
35
|
+
utf8tob64,
|
|
36
|
+
b64utoutf8,
|
|
37
|
+
utf8tob64u,
|
|
38
|
+
hextoutf8,
|
|
39
|
+
utf8tohex,
|
|
40
|
+
b64utohex,
|
|
41
|
+
hextob64u,
|
|
42
|
+
b64tob64u,
|
|
43
|
+
b64utob64,
|
|
44
|
+
hextorstr,
|
|
45
|
+
rstrtohex,
|
|
46
|
+
binstrtobitstr,
|
|
47
|
+
bitstrtobinstr,
|
|
48
|
+
inttobitstr,
|
|
49
|
+
strpad,
|
|
50
|
+
namearraytobinstr,
|
|
51
|
+
aryval,
|
|
52
|
+
rstrtob64,
|
|
53
|
+
};
|
|
54
|
+
export type { Dictionary };
|
|
55
|
+
|
|
56
|
+
import { iso88591hextoutf8, utf8toiso88591hex } from "./conv_iso88591.mts";
|
|
57
|
+
export { iso88591hextoutf8, utf8toiso88591hex };
|
|
58
|
+
|
|
59
|
+
import {
|
|
60
|
+
b64nltohex,
|
|
61
|
+
b64topem,
|
|
62
|
+
foldnl,
|
|
63
|
+
hextopem,
|
|
64
|
+
pemtob64,
|
|
65
|
+
pemtohex,
|
|
66
|
+
} from "./conv_pem.mts";
|
|
67
|
+
export { pemtohex, hextopem, pemtob64, b64topem, b64nltohex, foldnl };
|
|
68
|
+
|
|
69
|
+
import { ArrayBuffertohex, hextoArrayBuffer } from "./conv_arybuf.mts";
|
|
70
|
+
export { hextoArrayBuffer, ArrayBuffertohex };
|
|
71
|
+
|
|
72
|
+
import {
|
|
73
|
+
datetozulu,
|
|
74
|
+
msectozulu,
|
|
75
|
+
timetogen,
|
|
76
|
+
zulutodate,
|
|
77
|
+
zulutomsec,
|
|
78
|
+
zulutosec,
|
|
79
|
+
} from "./conv_zulu.mts";
|
|
80
|
+
export { zulutomsec, msectozulu, zulutosec, zulutodate, datetozulu, timetogen };
|
|
81
|
+
|
|
82
|
+
import {
|
|
83
|
+
encodeURIComponentAll,
|
|
84
|
+
hextouricmp,
|
|
85
|
+
uricmptohex,
|
|
86
|
+
} from "./conv_uricmp.mts";
|
|
87
|
+
export { encodeURIComponentAll, hextouricmp, uricmptohex };
|
|
88
|
+
|
|
89
|
+
import {
|
|
90
|
+
hextoip,
|
|
91
|
+
hextoipv6,
|
|
92
|
+
ipnetmask,
|
|
93
|
+
ipprefixlen,
|
|
94
|
+
iptohex,
|
|
95
|
+
ipv6tohex,
|
|
96
|
+
} from "./conv_ip.mts";
|
|
97
|
+
export { ipv6tohex, hextoipv6, hextoip, iptohex, ipprefixlen, ipnetmask };
|
|
98
|
+
|
|
99
|
+
import { ucs2hextoutf8 } from "./conv_ucs2.mts";
|
|
100
|
+
export { ucs2hextoutf8 };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"types": ["bun-types"],
|
|
4
|
+
|
|
5
|
+
"lib": ["esnext"],
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"target": "esnext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
|
|
15
|
+
"strict": true,
|
|
16
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
|
+
"skipLibCheck": true
|
|
18
|
+
}
|
|
19
|
+
}
|