@waiting/bankcard-reader-base
Version:
67 lines (58 loc) • 1.79 kB
JavaScript
/**
* @waiting/bankcard-reader-base
* 读取IC/RF银行卡基础包
*
* @version 1.3.0
* @author waiting
* @license MIT
* @link https://github.com/waitingsong/node-bankcard-reader-base#readme
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var sharedCore = require('@waiting/shared-core');
const initialConfig = {
appDir: '',
};
/** 初始化参数 */
const initialOpts = {
cardType: 'auto',
dllTxt: '',
dllSearchPath: '',
findCardRetryTimes: 0,
debug: false,
port: 0,
searchAll: false,
};
function parseDeviceOpts(options) {
const deviceOpts = Object.assign({}, initialOpts);
if (!options.dllTxt) {
throw new Error('params dllTxt undefined or blank')
}
else {
deviceOpts.dllTxt = sharedCore.normalize(options.dllTxt);
}
if (typeof options.dllSearchPath === 'string' && options.dllSearchPath) {
deviceOpts.dllSearchPath = options.dllSearchPath;
}
if (typeof options.debug === 'boolean') {
deviceOpts.debug = options.debug;
}
if (typeof options.searchAll === 'boolean') {
deviceOpts.searchAll = options.searchAll;
}
if (typeof options.findCardRetryTimes === 'number') {
deviceOpts.findCardRetryTimes = options.findCardRetryTimes;
}
if (isNaN(deviceOpts.findCardRetryTimes) || deviceOpts.findCardRetryTimes < 0) {
deviceOpts.findCardRetryTimes = initialOpts.findCardRetryTimes;
}
if (typeof options.port === 'number' && options.port > 0) {
deviceOpts.port = options.port;
}
return deviceOpts
}
/* istanbul ignore next */
initialConfig.appDir = __dirname + '/..';
exports.initialConfig = initialConfig;
exports.initialOpts = initialOpts;
exports.parseDeviceOpts = parseDeviceOpts;