Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import iconv from 'iconv-lite';
import encodings from 'iconv-lite/encodings';
import enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
// For info on this hack:
// https://stackoverflow.com/questions/46227783/encoding-not-recognized-in-jest-js
iconv.encodings = encodings;
enzyme.configure({ adapter: new Adapter() });
import iconv from 'iconv-lite';
import { check } from 'meteor/check';
iconv.encode('', 'utf8'); // Load all encodings -- iconv-lite has no real interface for this yet.
if (!iconv.encodings) {
// If this should be thrown, you have to update the code to fetch the available iconv
// encoding names in a new way.
check(iconv.encodings, [String]);
throw new Error('No iconv encodings available. Please update implementation.');
}
export default class ConvertToUTF8 {
constructor({ fromCharSet = 'utf8' }) {
check(fromCharSet, String);
this.stream = iconv.decodeStream(fromCharSet);
}
dispose() {
delete this.stream;
}
import iconv from 'iconv-lite';
import { check } from 'meteor/check';
iconv.encode('', 'utf8'); // Load all encodings -- iconv-lite has no real interface for this yet.
if (!iconv.encodings) {
// If this should be thrown, you have to update the code to fetch the available iconv
// encoding names in a new way.
check(iconv.encodings, [String]);
throw new Error('No iconv encodings available. Please update implementation.');
}
export default class ConvertToUTF8 {
constructor({ fromCharSet = 'utf8' }) {
check(fromCharSet, String);
this.stream = iconv.decodeStream(fromCharSet);
}
dispose() {
delete this.stream;
}
static getParameterSchema() {
return {
fromCharset: {
static getParameterSchema() {
return {
fromCharset: {
type: String,
allowedValues: iconv.encodings,
},
};
}
}
'windows1254': [0x5b, false],
'windows1255': [0x20, false],
'windows1256': [0x5c, false],
'windows1257': [0x19, false],
'windows1258': [0x5e, false],
};
let codepage;
if (!iconv.encodingExists(value)) {
throw new Error('Unknown codepage');
}
if (value in iconv.encodings) {
if (typeof iconv.encodings[value] === 'string') {
codepage = iconv.encodings[value];
} else {
codepage = value;
}
} else {
throw new Error('Unknown codepage');
}
if (typeof codepages[codepage] !== 'undefined') {
this._codepage = codepage;
this._state.hanzi = codepages[codepage][1];
this._queue([
0x1b, 0x74, codepages[codepage][0],
]);
} else {
throw new Error('Codepage not supported by printer');
'windows1252': [0x47, false],
'windows1253': [0x5a, false],
'windows1254': [0x5b, false],
'windows1255': [0x20, false],
'windows1256': [0x5c, false],
'windows1257': [0x19, false],
'windows1258': [0x5e, false],
};
let codepage;
if (!iconv.encodingExists(value)) {
throw new Error('Unknown codepage');
}
if (value in iconv.encodings) {
if (typeof iconv.encodings[value] === 'string') {
codepage = iconv.encodings[value];
} else {
codepage = value;
}
} else {
throw new Error('Unknown codepage');
}
if (typeof codepages[codepage] !== 'undefined') {
this._codepage = codepage;
this._state.hanzi = codepages[codepage][1];
this._queue([
0x1b, 0x74, codepages[codepage][0],
]);