@diemtarh/detalex-utils
Version:
Detalex utils library.
78 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require('fs');
var pathLib = require('path');
var moment = require('moment');
var config = require('config');
exports.env = process.env.NODE_ENV || 'default';
function rootDirName() {
var root = config.get('root');
return "" + root + exports.env + "/";
}
exports.rootDirName = rootDirName;
function toFloat(val) {
val = val.replace('.', '');
return parseFloat(val.replace(',', '.'));
}
exports.toFloat = toFloat;
function toDeString(val) {
val = val < 0 ? val * -1 : val;
var res = val.toString();
return res.replace('.', ',');
}
exports.toDeString = toDeString;
function save(file, value) {
if (value === void 0) { value = {}; }
var path = pathLib.dirname(file);
exports.createDir(path);
fs.writeFileSync(file, JSON.stringify(value, null, 4), function (e) {
if (e) {
console.error(file, e);
}
});
}
exports.save = save;
exports.createDir = function (dir) {
var splitPath = dir.split('/');
splitPath.reduce(function (strpath, subPath) {
var currentPath;
if (subPath != '.') {
currentPath = strpath + '/' + subPath;
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
}
else {
currentPath = subPath;
}
return currentPath;
}, '');
};
function now(format) {
if (format === void 0) { format = 'X'; }
return moment().format(format);
}
exports.now = now;
function linuxTimeStampToDate(time, format) {
if (format === void 0) { format = moment.HTML5_FMT.DATETIME_LOCAL; }
return moment(time * 1000).format(format);
}
exports.linuxTimeStampToDate = linuxTimeStampToDate;
function getAccountNumberFromFileName(file) {
file = file.toLowerCase().replace('.csv', '');
var map = config.get('map');
return map[pathLib.basename(file).split('-')[1]];
}
exports.getAccountNumberFromFileName = getAccountNumberFromFileName;
function isBankAccountNumber(bankAccountNumber) {
var map = config.get('map');
for (var _i = 0, _a = Object.keys(map); _i < _a.length; _i++) {
var key = _a[_i];
if (bankAccountNumber === map[key]) {
return true;
}
}
return false;
}
exports.isBankAccountNumber = isBankAccountNumber;
//# sourceMappingURL=Utils.js.map