Programmatically check which encoding is available.
This commit is contained in:
@@ -15,9 +15,11 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import * as iconv from "iconv-lite";
|
||||||
|
|
||||||
import Exception from "./exception.js";
|
import Exception from "./exception.js";
|
||||||
|
|
||||||
export const charsetPresets = [
|
const availableEncodings = [
|
||||||
"utf-8",
|
"utf-8",
|
||||||
"ibm866",
|
"ibm866",
|
||||||
"iso-8859-2",
|
"iso-8859-2",
|
||||||
@@ -27,7 +29,6 @@ export const charsetPresets = [
|
|||||||
"iso-8859-6",
|
"iso-8859-6",
|
||||||
"iso-8859-7",
|
"iso-8859-7",
|
||||||
"iso-8859-8",
|
"iso-8859-8",
|
||||||
"iso-8859-8i",
|
|
||||||
"iso-8859-10",
|
"iso-8859-10",
|
||||||
"iso-8859-13",
|
"iso-8859-13",
|
||||||
"iso-8859-14",
|
"iso-8859-14",
|
||||||
@@ -52,11 +53,30 @@ export const charsetPresets = [
|
|||||||
"euc-jp",
|
"euc-jp",
|
||||||
"shift-jis",
|
"shift-jis",
|
||||||
"euc-kr",
|
"euc-kr",
|
||||||
"iso-2022-kr",
|
|
||||||
"utf-16be",
|
"utf-16be",
|
||||||
"utf-16le"
|
"utf-16le"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const charsetPresets = (() => {
|
||||||
|
let r = [];
|
||||||
|
|
||||||
|
for (let i in availableEncodings) {
|
||||||
|
try {
|
||||||
|
if (!iconv.encodingExists(availableEncodings[i])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
new TextDecoder(availableEncodings[i]);
|
||||||
|
|
||||||
|
r.push(availableEncodings[i]);
|
||||||
|
} catch (e) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
})();
|
||||||
|
|
||||||
const numCharators = {
|
const numCharators = {
|
||||||
"0": true,
|
"0": true,
|
||||||
"1": true,
|
"1": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user