@waiting/bankcard-reader-base
Version:
61 lines (54 loc) • 1.64 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
*/
import { normalize } from '@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 = 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 + '/..';
export { initialConfig, initialOpts, parseDeviceOpts };