@frsource/base64 1.0.49 → 1.0.51
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 +0 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +30 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -35,7 +35,6 @@ import { encode, decode } from '@frsource/base64';
|
|
|
35
35
|
// legacy javscript
|
|
36
36
|
const { encode, decode } = require('@frsource/base64');
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
const encoded = encode('我喜欢解码lubię dekodować');
|
|
40
39
|
console.log(encoded); // output: 5oiR5Zac5qyi6Kej56CBbHViacSZIGRla29kb3dhxIc=
|
|
41
40
|
const decoded = decode(encoded);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Base64 encode / decode
|
|
4
|
-
* http://www.webtoolkit.info/
|
|
5
|
-
*
|
|
6
|
-
**/
|
|
7
|
-
/**
|
|
8
|
-
* Encodes given string.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} input - Text to encode
|
|
11
|
-
*/
|
|
12
|
-
export declare const encode: (input: string) => string;
|
|
13
|
-
/**
|
|
14
|
-
* Decodes given string.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} input - Text to decode
|
|
17
|
-
*/
|
|
18
|
-
export declare const decode: (input: string) => string;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Base64 encode / decode
|
|
4
|
+
* http://www.webtoolkit.info/
|
|
5
|
+
*
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* Encodes given string.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} input - Text to encode
|
|
11
|
+
*/
|
|
12
|
+
export declare const encode: (input: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Decodes given string.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} input - Text to decode
|
|
17
|
+
*/
|
|
18
|
+
export declare const decode: (input: string) => string;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Base64 encode / decode
|
|
4
|
-
* http://www.webtoolkit.info/
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Base64 encode / decode
|
|
4
|
+
* http://www.webtoolkit.info/
|
|
5
|
+
*
|
|
6
6
|
**/
|
|
7
|
-
const _keyStr =
|
|
8
|
-
/**
|
|
9
|
-
* Encodes given string.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} input - Text to encode
|
|
7
|
+
const _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
8
|
+
/**
|
|
9
|
+
* Encodes given string.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} input - Text to encode
|
|
12
12
|
*/
|
|
13
13
|
const encode = input => {
|
|
14
|
-
let output =
|
|
14
|
+
let output = '';
|
|
15
15
|
let i = 0;
|
|
16
16
|
input = _utf8_encode(input);
|
|
17
17
|
while (i < input.length) {
|
|
@@ -31,15 +31,15 @@ const encode = input => {
|
|
|
31
31
|
}
|
|
32
32
|
return output;
|
|
33
33
|
};
|
|
34
|
-
/**
|
|
35
|
-
* Decodes given string.
|
|
36
|
-
*
|
|
37
|
-
* @param {string} input - Text to decode
|
|
34
|
+
/**
|
|
35
|
+
* Decodes given string.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} input - Text to decode
|
|
38
38
|
*/
|
|
39
39
|
const decode = input => {
|
|
40
|
-
let output =
|
|
40
|
+
let output = '';
|
|
41
41
|
let i = 0;
|
|
42
|
-
input = input.replace(/[^A-Za-z0-9
|
|
42
|
+
input = input.replace(/[^A-Za-z0-9+/=]/g, '');
|
|
43
43
|
while (i < input.length) {
|
|
44
44
|
const enc1 = _keyStr.indexOf(input.charAt(i++));
|
|
45
45
|
const enc2 = _keyStr.indexOf(input.charAt(i++));
|
|
@@ -58,15 +58,15 @@ const decode = input => {
|
|
|
58
58
|
}
|
|
59
59
|
return output = _utf8_decode(output);
|
|
60
60
|
};
|
|
61
|
-
/**
|
|
62
|
-
* (private method) does a UTF-8 encoding
|
|
63
|
-
*
|
|
64
|
-
* @private
|
|
65
|
-
* @param {string} string - Text to encode
|
|
61
|
+
/**
|
|
62
|
+
* (private method) does a UTF-8 encoding
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
* @param {string} string - Text to encode
|
|
66
66
|
*/
|
|
67
67
|
function _utf8_encode(string) {
|
|
68
|
-
string = string.replace(/\r\n/g,
|
|
69
|
-
let utftext =
|
|
68
|
+
string = string.replace(/\r\n/g, '\n');
|
|
69
|
+
let utftext = '';
|
|
70
70
|
for (let n = 0; n < string.length; n++) {
|
|
71
71
|
const c = string.charCodeAt(n);
|
|
72
72
|
if (c < 128) {
|
|
@@ -79,14 +79,14 @@ function _utf8_encode(string) {
|
|
|
79
79
|
}
|
|
80
80
|
return utftext;
|
|
81
81
|
}
|
|
82
|
-
/**
|
|
83
|
-
* (private method - do not use) does a UTF-8 decoding
|
|
84
|
-
*
|
|
85
|
-
* @private
|
|
86
|
-
* @param {string} utftext - UTF-8 text to dencode
|
|
82
|
+
/**
|
|
83
|
+
* (private method - do not use) does a UTF-8 decoding
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
* @param {string} utftext - UTF-8 text to dencode
|
|
87
87
|
*/
|
|
88
88
|
function _utf8_decode(utftext) {
|
|
89
|
-
let string =
|
|
89
|
+
let string = '';
|
|
90
90
|
let i = 0;
|
|
91
91
|
while (i < utftext.length) {
|
|
92
92
|
const c = utftext.charCodeAt(i);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../index.ts"],"sourcesContent":["/**\n *\n * Base64 encode / decode\n * http://www.webtoolkit.info/\n *\n **/\n\nconst _keyStr =\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../index.ts"],"sourcesContent":["/**\n *\n * Base64 encode / decode\n * http://www.webtoolkit.info/\n *\n **/\n\nconst _keyStr =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n\n/**\n * Encodes given string.\n *\n * @param {string} input - Text to encode\n */\nexport const encode = (input: string) => {\n let output = '';\n let i = 0;\n\n input = _utf8_encode(input);\n\n while (i < input.length) {\n const chr1 = input.charCodeAt(i++);\n const chr2 = input.charCodeAt(i++);\n const chr3 = input.charCodeAt(i++);\n\n const enc1 = chr1 >> 2;\n const enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n let enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n let enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output =\n output +\n _keyStr.charAt(enc1) +\n _keyStr.charAt(enc2) +\n _keyStr.charAt(enc3) +\n _keyStr.charAt(enc4);\n }\n\n return output;\n};\n\n/**\n * Decodes given string.\n *\n * @param {string} input - Text to decode\n */\nexport const decode = (input: string) => {\n let output = '';\n let i = 0;\n\n input = input.replace(/[^A-Za-z0-9+/=]/g, '');\n\n while (i < input.length) {\n const enc1 = _keyStr.indexOf(input.charAt(i++));\n const enc2 = _keyStr.indexOf(input.charAt(i++));\n const enc3 = _keyStr.indexOf(input.charAt(i++));\n const enc4 = _keyStr.indexOf(input.charAt(i++));\n\n const chr1 = (enc1 << 2) | (enc2 >> 4);\n const chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\n const chr3 = ((enc3 & 3) << 6) | enc4;\n\n output = output + String.fromCharCode(chr1);\n\n if (enc3 != 64) {\n output = output + String.fromCharCode(chr2);\n }\n\n if (enc4 != 64) {\n output = output + String.fromCharCode(chr3);\n }\n }\n\n return (output = _utf8_decode(output));\n};\n\n/**\n * (private method) does a UTF-8 encoding\n *\n * @private\n * @param {string} string - Text to encode\n */\nfunction _utf8_encode(string: string) {\n string = string.replace(/\\r\\n/g, '\\n');\n let utftext = '';\n\n for (let n = 0; n < string.length; n++) {\n const c = string.charCodeAt(n);\n\n if (c < 128) {\n utftext += String.fromCharCode(c);\n } else if (c > 127 && c < 2048) {\n utftext +=\n String.fromCharCode((c >> 6) | 192) +\n String.fromCharCode((c & 63) | 128);\n } else {\n utftext +=\n String.fromCharCode((c >> 12) | 224) +\n String.fromCharCode(((c >> 6) & 63) | 128) +\n String.fromCharCode((c & 63) | 128);\n }\n }\n\n return utftext;\n}\n\n/**\n * (private method - do not use) does a UTF-8 decoding\n *\n * @private\n * @param {string} utftext - UTF-8 text to dencode\n */\nfunction _utf8_decode(utftext: string) {\n let string = '';\n let i = 0;\n\n while (i < utftext.length) {\n const c = utftext.charCodeAt(i);\n\n if (c < 128) {\n string += String.fromCharCode(c);\n i++;\n } else if (c > 191 && c < 224) {\n const c2 = utftext.charCodeAt(i + 1);\n string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));\n i += 2;\n } else {\n const c2 = utftext.charCodeAt(i + 1);\n const c3 = utftext.charCodeAt(i + 2);\n string += String.fromCharCode(\n ((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63),\n );\n i += 3;\n }\n }\n return string;\n}\n"],"names":["_keyStr","encode","input","output","i","_utf8_encode","length","chr1","charCodeAt","chr2","chr3","enc1","enc2","enc3","enc4","isNaN","charAt","decode","replace","indexOf","String","fromCharCode","_utf8_decode","string","utftext","n","c","c2","c3"],"mappings":"AAAA;;;;;AAKI;AAEJ,MAAMA,OAAO,GACX,mEAAmE,CAAA;AAErE;;;;AAIG;AACUC,MAAAA,MAAM,GAAIC,KAAa,IAAI;EACtC,IAAIC,MAAM,GAAG,EAAE,CAAA;EACf,IAAIC,CAAC,GAAG,CAAC,CAAA;AAETF,EAAAA,KAAK,GAAGG,YAAY,CAACH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
7
|
-
const _keyStr =
|
|
8
|
-
/**
|
|
9
|
-
* Encodes given string.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} input - Text to encode
|
|
7
|
+
const _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
8
|
+
/**
|
|
9
|
+
* Encodes given string.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} input - Text to encode
|
|
12
12
|
*/
|
|
13
13
|
const encode = input => {
|
|
14
|
-
let output =
|
|
14
|
+
let output = '';
|
|
15
15
|
let i = 0;
|
|
16
16
|
input = _utf8_encode(input);
|
|
17
17
|
while (i < input.length) {
|
|
@@ -31,15 +31,15 @@ const encode = input => {
|
|
|
31
31
|
}
|
|
32
32
|
return output;
|
|
33
33
|
};
|
|
34
|
-
/**
|
|
35
|
-
* Decodes given string.
|
|
36
|
-
*
|
|
37
|
-
* @param {string} input - Text to decode
|
|
34
|
+
/**
|
|
35
|
+
* Decodes given string.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} input - Text to decode
|
|
38
38
|
*/
|
|
39
39
|
const decode = input => {
|
|
40
|
-
let output =
|
|
40
|
+
let output = '';
|
|
41
41
|
let i = 0;
|
|
42
|
-
input = input.replace(/[^A-Za-z0-9
|
|
42
|
+
input = input.replace(/[^A-Za-z0-9+/=]/g, '');
|
|
43
43
|
while (i < input.length) {
|
|
44
44
|
const enc1 = _keyStr.indexOf(input.charAt(i++));
|
|
45
45
|
const enc2 = _keyStr.indexOf(input.charAt(i++));
|
|
@@ -58,15 +58,15 @@ const decode = input => {
|
|
|
58
58
|
}
|
|
59
59
|
return output = _utf8_decode(output);
|
|
60
60
|
};
|
|
61
|
-
/**
|
|
62
|
-
* (private method) does a UTF-8 encoding
|
|
63
|
-
*
|
|
64
|
-
* @private
|
|
65
|
-
* @param {string} string - Text to encode
|
|
61
|
+
/**
|
|
62
|
+
* (private method) does a UTF-8 encoding
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
* @param {string} string - Text to encode
|
|
66
66
|
*/
|
|
67
67
|
function _utf8_encode(string) {
|
|
68
|
-
string = string.replace(/\r\n/g,
|
|
69
|
-
let utftext =
|
|
68
|
+
string = string.replace(/\r\n/g, '\n');
|
|
69
|
+
let utftext = '';
|
|
70
70
|
for (let n = 0; n < string.length; n++) {
|
|
71
71
|
const c = string.charCodeAt(n);
|
|
72
72
|
if (c < 128) {
|
|
@@ -79,14 +79,14 @@ function _utf8_encode(string) {
|
|
|
79
79
|
}
|
|
80
80
|
return utftext;
|
|
81
81
|
}
|
|
82
|
-
/**
|
|
83
|
-
* (private method - do not use) does a UTF-8 decoding
|
|
84
|
-
*
|
|
85
|
-
* @private
|
|
86
|
-
* @param {string} utftext - UTF-8 text to dencode
|
|
82
|
+
/**
|
|
83
|
+
* (private method - do not use) does a UTF-8 decoding
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
* @param {string} utftext - UTF-8 text to dencode
|
|
87
87
|
*/
|
|
88
88
|
function _utf8_decode(utftext) {
|
|
89
|
-
let string =
|
|
89
|
+
let string = '';
|
|
90
90
|
let i = 0;
|
|
91
91
|
while (i < utftext.length) {
|
|
92
92
|
const c = utftext.charCodeAt(i);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":["/**\n *\n * Base64 encode / decode\n * http://www.webtoolkit.info/\n *\n **/\n\nconst _keyStr =\n
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":["/**\n *\n * Base64 encode / decode\n * http://www.webtoolkit.info/\n *\n **/\n\nconst _keyStr =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n\n/**\n * Encodes given string.\n *\n * @param {string} input - Text to encode\n */\nexport const encode = (input: string) => {\n let output = '';\n let i = 0;\n\n input = _utf8_encode(input);\n\n while (i < input.length) {\n const chr1 = input.charCodeAt(i++);\n const chr2 = input.charCodeAt(i++);\n const chr3 = input.charCodeAt(i++);\n\n const enc1 = chr1 >> 2;\n const enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n let enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n let enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output =\n output +\n _keyStr.charAt(enc1) +\n _keyStr.charAt(enc2) +\n _keyStr.charAt(enc3) +\n _keyStr.charAt(enc4);\n }\n\n return output;\n};\n\n/**\n * Decodes given string.\n *\n * @param {string} input - Text to decode\n */\nexport const decode = (input: string) => {\n let output = '';\n let i = 0;\n\n input = input.replace(/[^A-Za-z0-9+/=]/g, '');\n\n while (i < input.length) {\n const enc1 = _keyStr.indexOf(input.charAt(i++));\n const enc2 = _keyStr.indexOf(input.charAt(i++));\n const enc3 = _keyStr.indexOf(input.charAt(i++));\n const enc4 = _keyStr.indexOf(input.charAt(i++));\n\n const chr1 = (enc1 << 2) | (enc2 >> 4);\n const chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\n const chr3 = ((enc3 & 3) << 6) | enc4;\n\n output = output + String.fromCharCode(chr1);\n\n if (enc3 != 64) {\n output = output + String.fromCharCode(chr2);\n }\n\n if (enc4 != 64) {\n output = output + String.fromCharCode(chr3);\n }\n }\n\n return (output = _utf8_decode(output));\n};\n\n/**\n * (private method) does a UTF-8 encoding\n *\n * @private\n * @param {string} string - Text to encode\n */\nfunction _utf8_encode(string: string) {\n string = string.replace(/\\r\\n/g, '\\n');\n let utftext = '';\n\n for (let n = 0; n < string.length; n++) {\n const c = string.charCodeAt(n);\n\n if (c < 128) {\n utftext += String.fromCharCode(c);\n } else if (c > 127 && c < 2048) {\n utftext +=\n String.fromCharCode((c >> 6) | 192) +\n String.fromCharCode((c & 63) | 128);\n } else {\n utftext +=\n String.fromCharCode((c >> 12) | 224) +\n String.fromCharCode(((c >> 6) & 63) | 128) +\n String.fromCharCode((c & 63) | 128);\n }\n }\n\n return utftext;\n}\n\n/**\n * (private method - do not use) does a UTF-8 decoding\n *\n * @private\n * @param {string} utftext - UTF-8 text to dencode\n */\nfunction _utf8_decode(utftext: string) {\n let string = '';\n let i = 0;\n\n while (i < utftext.length) {\n const c = utftext.charCodeAt(i);\n\n if (c < 128) {\n string += String.fromCharCode(c);\n i++;\n } else if (c > 191 && c < 224) {\n const c2 = utftext.charCodeAt(i + 1);\n string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));\n i += 2;\n } else {\n const c2 = utftext.charCodeAt(i + 1);\n const c3 = utftext.charCodeAt(i + 2);\n string += String.fromCharCode(\n ((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63),\n );\n i += 3;\n }\n }\n return string;\n}\n"],"names":["_keyStr","encode","input","output","i","_utf8_encode","length","chr1","charCodeAt","chr2","chr3","enc1","enc2","enc3","enc4","isNaN","charAt","decode","replace","indexOf","String","fromCharCode","_utf8_decode","string","utftext","n","c","c2","c3"],"mappings":"AAAA;;;;;AAKI;AAEJ,MAAMA,OAAO,GACX,mEAAmE,CAAA;AAErE;;;;AAIG;AACUC,MAAAA,MAAM,GAAIC,KAAa,IAAI;EACtC,IAAIC,MAAM,GAAG,EAAE,CAAA;EACf,IAAIC,CAAC,GAAG,CAAC,CAAA;AAETF,EAAAA,KAAK,GAAGG,YAAY,CAACH,KAAK,CAAC,CAAA;AAE3B,EAAA,OAAOE,CAAC,GAAGF,KAAK,CAACI,MAAM,EAAE;IACvB,MAAMC,IAAI,GAAGL,KAAK,CAACM,UAAU,CAACJ,CAAC,EAAE,CAAC,CAAA;IAClC,MAAMK,IAAI,GAAGP,KAAK,CAACM,UAAU,CAACJ,CAAC,EAAE,CAAC,CAAA;IAClC,MAAMM,IAAI,GAAGR,KAAK,CAACM,UAAU,CAACJ,CAAC,EAAE,CAAC,CAAA;AAElC,IAAA,MAAMO,IAAI,GAAGJ,IAAI,IA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AACpCmB,MAAAA,MAAM,IAAIH,MAAM,CAACC,YAAY,CAAE,CAACK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAKC,EAAE,GAAG,EAAG,CAAC,CAAA;AAC1DvB,MAAAA,CAAC,IAAI,CAAC,CAAA;AACR,KAAC,MAAM;MACL,MAAMuB,EAAE,GAAGH,OAAO,CAAChB,UAAU,CAACJ,CAAC,GAAG,CAAC,CAAC,CAAA;MACpC,MAAMwB,EAAE,GAAGJ,OAAO,CAAChB,UAAU,CAACJ,CAAC,GAAG,CAAC,CAAC,CAAA;MACpCmB,MAAM,IAAIH,MAAM,CAACC,YAAY,CAC1B,CAACK,CAAC,GAAG,EAAE,KAAK,EAAE,GAAK,CAACC,EAAE,GAAG,EAAE,KAAK,CAAE,GAAIC,EAAE,GAAG,EAAG,CAChD,CAAA;AACDxB,MAAAA,CAAC,IAAI,CAAC,CAAA;AACR,KAAA;AACF,GAAA;AACA,EAAA,OAAOmB,MAAM,CAAA;AACf;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frsource/base64",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "base64 encoder/decoder with UTF-8 support 📔",
|
|
5
5
|
"repository": "https://github.com/FRSOURCE/base64.git",
|
|
6
6
|
"homepage": "http://www.webtoolkit.info/javascript_base64.html",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "del-cli dist && microbundle index.ts --target node -f cjs,modern",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"lint": "eslint . && prettier . --check",
|
|
10
|
+
"fix": "pnpm eslint --fix && prettier . --write",
|
|
11
11
|
"prepack": "pnpm build",
|
|
12
12
|
"release": "semantic-release",
|
|
13
13
|
"release:ci": "pnpm release --yes",
|
|
@@ -35,13 +35,16 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"packageManager": "pnpm@8.15.8",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@semantic-release
|
|
38
|
+
"@frsource/eslint-config": "1.10.0",
|
|
39
|
+
"@frsource/prettier-config": "1.7.0",
|
|
40
|
+
"@frsource/semantic-release-config": "1.4.0",
|
|
41
|
+
"eslint": "9.3.0",
|
|
41
42
|
"del-cli": "5.1.0",
|
|
43
|
+
"globals": "15.2.0",
|
|
42
44
|
"microbundle": "0.15.1",
|
|
43
45
|
"prettier": "3.2.5",
|
|
44
|
-
"semantic-release": "23.
|
|
46
|
+
"semantic-release": "23.1.1",
|
|
47
|
+
"typescript": "5.4.5"
|
|
45
48
|
},
|
|
46
49
|
"publishConfig": {
|
|
47
50
|
"access": "public"
|
|
@@ -51,5 +54,6 @@
|
|
|
51
54
|
"package.json",
|
|
52
55
|
"README.md",
|
|
53
56
|
"LICENSE"
|
|
54
|
-
]
|
|
57
|
+
],
|
|
58
|
+
"funding": "https://buymeacoffee.com/frsource"
|
|
55
59
|
}
|