@itcoordinadora/cm-coordi-utils
Version:
Librería en TS/JS para convertir etiqueta1d, etiqueta2d y guías
67 lines (61 loc) • 2.42 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var ERROR = {
etiqueta1d: 'Inserte una etiqueta1d de mínimo 15 y máximo 16 caracteres',
etiqueta2d: 'Inserte una etiqueta2d de mínimo 32 y máximo 33 caracteres',
guia: 'Inserte una guía de 11 caracteres',
unit: 'Inserte una unit'
};
var validateErrores = function validateErrores(_ref) {
var dataTypeIn = _ref.dataTypeIn,
dataTypeOut = _ref.dataTypeOut,
unit = _ref.unit;
var tiposValidosdataTypeIn = ['etiqueta1d', 'etiqueta2d', 'guia'];
var tiposValidosdataTypeOut = ['etiqueta1d', 'guia'];
if (dataTypeIn === 'guia' && dataTypeOut === 'etiqueta1d' && !unit) return ERROR.unit;
if (!tiposValidosdataTypeIn.includes(dataTypeIn)) return "Tipo de dato no v\xE1lido en dataTypeIn, solo es permitido " + tiposValidosdataTypeIn;
if (!tiposValidosdataTypeOut.includes(dataTypeOut)) return "Tipo de dato no v\xE1lido en dataTypeOut, solo es permitido " + tiposValidosdataTypeOut;
return;
};
var tagTransform = function tagTransform(_ref) {
var dataTypeIn = _ref.dataTypeIn,
dataTypeOut = _ref.dataTypeOut,
value = _ref.value,
unit = _ref.unit;
validateErrores({
dataTypeIn: dataTypeIn,
dataTypeOut: dataTypeOut,
value: value,
unit: unit
});
if (dataTypeIn === 'etiqueta1d' && dataTypeOut === 'guia') {
if (value.length === 15 || value.length === 16) return value.substring(1, 12);
return ERROR.etiqueta1d;
}
if (dataTypeIn === 'etiqueta2d' && dataTypeOut === 'guia') {
if (value.length === 32 || value.length === 33) return value.substring(18, 29);
return ERROR.etiqueta2d;
}
if (dataTypeIn === 'etiqueta2d' && dataTypeOut === 'etiqueta1d') {
if (value.length === 32 || value.length === 33) return '7' + value.substring(18);
return ERROR.etiqueta2d;
}
if (dataTypeIn === 'guia' && dataTypeOut === 'etiqueta1d' && unit) {
if (value.length === 11) {
var unitStr = unit.toString();
var resultado;
if (unit < 10) {
resultado = "7" + value + ('00' + unitStr);
} else if (unit >= 10 && unit < 100) {
resultado = "7" + value + ('0' + unitStr);
} else {
resultado = "7" + value + unitStr;
}
return resultado;
}
return ERROR.guia;
}
return value.substring(0, 11);
};
exports.tagTransform = tagTransform;
//# sourceMappingURL=cm-coordi-utils.cjs.development.js.map