@ridi/parser-core
Advanced tools
Comparing version 0.3.0-alpha.5 to 0.3.0-alpha-10
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.openZip = exports.validateOptions = exports.isUrl = exports.isString = exports.isObject = exports.isFunc = exports.isExists = exports.isBool = exports.isArray = exports.getType = exports.stringContains = exports.readEntries = exports.getPathes = exports.safePathJoin = exports.safePath = exports.safeDirname = exports.parseBool = exports.mergeObjects = exports.Logger = exports.mustOverride = exports.createError = exports.Errors = exports.CryptoProvider = exports.Cryptor = undefined; | ||
exports.openZip = exports.validateOptions = exports.isUrl = exports.isString = exports.isObject = exports.isFunc = exports.isExists = exports.isBool = exports.isArray = exports.getType = exports.stringContains = exports.readEntries = exports.getPathes = exports.safePathJoin = exports.safePath = exports.safeDirname = exports.Parser = exports.parseBool = exports.mergeObjects = exports.LogLevel = exports.Logger = exports.mustOverride = exports.createError = exports.Errors = exports.CryptoProvider = exports.Cryptor = undefined; | ||
@@ -33,2 +33,6 @@ var _Cryptor = require('./Cryptor'); | ||
var _Parser = require('./Parser'); | ||
var _Parser2 = _interopRequireDefault(_Parser); | ||
var _pathUtil = require('./pathUtil'); | ||
@@ -62,4 +66,6 @@ | ||
exports.Logger = _Logger2.default; | ||
exports.LogLevel = _Logger.LogLevel; | ||
exports.mergeObjects = _mergeObjects2.default; | ||
exports.parseBool = _parseBool2.default; | ||
exports.Parser = _Parser2.default; | ||
exports.safeDirname = _pathUtil.safeDirname; | ||
@@ -66,0 +72,0 @@ exports.safePath = _pathUtil.safePath; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports.LogLevel = undefined; | ||
@@ -28,2 +29,6 @@ var _regenerator = require('babel-runtime/regenerator'); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _freeze = require('babel-runtime/core-js/object/freeze'); | ||
@@ -33,2 +38,4 @@ | ||
var _typecheck = require('./typecheck'); | ||
var _stringContains = require('./stringContains'); | ||
@@ -40,2 +47,3 @@ | ||
/* eslint-disable no-console */ | ||
var LogLevel = (0, _freeze2.default)({ | ||
@@ -47,22 +55,26 @@ SILENT: 'silent', | ||
VERBOSE: 'verbose' | ||
}); /* eslint-disable no-console */ | ||
}); | ||
var Logger = function () { | ||
(0, _createClass3.default)(Logger, [{ | ||
key: 'logLevel', | ||
get: function get() { | ||
return this._logLevel; | ||
}, | ||
set: function set(level) { | ||
this._logLevel = (0, _stringContains2.default)((0, _values2.default)(LogLevel), level) ? level : this.logLevel; | ||
} | ||
}]); | ||
var logLevel = LogLevel.ERROR; | ||
function Logger(namespace) { | ||
var logLevel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
(0, _classCallCheck3.default)(this, Logger); | ||
var Logger = function () { | ||
function Logger() { | ||
(0, _classCallCheck3.default)(this, Logger); | ||
this.namespace = namespace || 'Logger'; | ||
this._logLevel = (0, _stringContains2.default)((0, _values2.default)(LogLevel), logLevel) ? logLevel : LogLevel.ERROR; | ||
this._firstTime = null; | ||
} | ||
Logger.setLogLevel = function setLogLevel(level) { | ||
logLevel = (0, _stringContains2.default)((0, _values2.default)(LogLevel), level) ? level : logLevel; | ||
}; | ||
Logger.getLogLevel = function getLogLevel() { | ||
return logLevel; | ||
}; | ||
Logger.info = function info(message) { | ||
if ((0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], logLevel)) { | ||
Logger.prototype.info = function info(message) { | ||
if ((0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], this.logLevel)) { | ||
var _console; | ||
@@ -74,14 +86,15 @@ | ||
(_console = console).log.apply(_console, [message].concat(optionalParams)); | ||
(_console = console).log.apply(_console, ['[' + this.namespace + '] ' + message].concat(optionalParams)); | ||
} | ||
}; | ||
Logger.measure = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(func, message) { | ||
Logger.prototype.measure = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(func, thisArg, argsArray, message) { | ||
var _console2, | ||
startTime, | ||
result, | ||
_result, | ||
_len2, | ||
optionalParams, | ||
_key2, | ||
result, | ||
_args = arguments; | ||
@@ -93,4 +106,4 @@ | ||
case 0: | ||
if (!(0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], logLevel)) { | ||
_context.next = 8; | ||
if (!(0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], this.logLevel)) { | ||
_context.next = 9; | ||
break; | ||
@@ -100,19 +113,28 @@ } | ||
startTime = new Date().getTime(); | ||
_context.next = 4; | ||
return func(); | ||
case 4: | ||
result = _context.sent; | ||
if (!(0, _typecheck.isExists)(this._firstTime)) { | ||
this._firstTime = startTime; | ||
} | ||
_context.next = 5; | ||
return func.apply(thisArg, argsArray); | ||
for (_len2 = _args.length, optionalParams = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
optionalParams[_key2 - 2] = _args[_key2]; | ||
case 5: | ||
_result = _context.sent; | ||
for (_len2 = _args.length, optionalParams = Array(_len2 > 4 ? _len2 - 4 : 0), _key2 = 4; _key2 < _len2; _key2++) { | ||
optionalParams[_key2 - 4] = _args[_key2]; | ||
} | ||
(_console2 = console).log.apply(_console2, [message + ' (' + (new Date().getTime() - startTime) + 'ms)'].concat((0, _toConsumableArray3.default)(optionalParams))); | ||
(_console2 = console).log.apply(_console2, ['[' + this.namespace + '] ' + message + ' (' + (new Date().getTime() - startTime) + 'ms)'].concat((0, _toConsumableArray3.default)(optionalParams))); | ||
return _context.abrupt('return', _result); | ||
case 9: | ||
_context.next = 11; | ||
return func.apply(thisArg, argsArray); | ||
case 11: | ||
result = _context.sent; | ||
return _context.abrupt('return', result); | ||
case 8: | ||
return _context.abrupt('return', func()); | ||
case 9: | ||
case 13: | ||
case 'end': | ||
@@ -125,3 +147,3 @@ return _context.stop(); | ||
function measure(_x, _x2) { | ||
function measure(_x2, _x3, _x4, _x5) { | ||
return _ref.apply(this, arguments); | ||
@@ -133,21 +155,25 @@ } | ||
Logger.measureSync = function measureSync(func, message) { | ||
if ((0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], logLevel)) { | ||
Logger.prototype.measureSync = function measureSync(func, thisArg, argsArray, message) { | ||
if ((0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], this.logLevel)) { | ||
var _console3; | ||
var startTime = new Date().getTime(); | ||
var result = func(); | ||
if (!(0, _typecheck.isExists)(this._firstTime)) { | ||
this._firstTime = startTime; | ||
} | ||
var result = func.apply(thisArg, argsArray); | ||
for (var _len3 = arguments.length, optionalParams = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { | ||
optionalParams[_key3 - 2] = arguments[_key3]; | ||
for (var _len3 = arguments.length, optionalParams = Array(_len3 > 4 ? _len3 - 4 : 0), _key3 = 4; _key3 < _len3; _key3++) { | ||
optionalParams[_key3 - 4] = arguments[_key3]; | ||
} | ||
(_console3 = console).log.apply(_console3, [message + ' (' + (new Date().getTime() - startTime) + 'ms)'].concat(optionalParams)); | ||
(_console3 = console).log.apply(_console3, ['[' + this.namespace + '] ' + message + ' (' + (new Date().getTime() - startTime) + 'ms)'].concat(optionalParams)); | ||
return result; | ||
} | ||
return func(); | ||
return func.apply(thisArg, argsArray); | ||
}; | ||
Logger.warn = function warn(message) { | ||
if ((0, _stringContains2.default)([LogLevel.WARNING, LogLevel.VERBOSE], logLevel)) { | ||
Logger.prototype.result = function result(message) { | ||
var time = this._firstTime || new Date().getTime(); | ||
if ((0, _stringContains2.default)([LogLevel.INFO, LogLevel.VERBOSE], this.logLevel)) { | ||
var _console4; | ||
@@ -159,8 +185,9 @@ | ||
(_console4 = console).warn.apply(_console4, [message].concat(optionalParams)); | ||
(_console4 = console).log.apply(_console4, ['[' + this.namespace + '] ' + message + ' (' + (new Date().getTime() - time) + 'ms)'].concat(optionalParams)); | ||
} | ||
this._firstTime = null; | ||
}; | ||
Logger.error = function error(message) { | ||
if ((0, _stringContains2.default)([LogLevel.ERROR, LogLevel.VERBOSE], logLevel)) { | ||
Logger.prototype.warn = function warn(message) { | ||
if ((0, _stringContains2.default)([LogLevel.WARNING, LogLevel.VERBOSE], this.logLevel)) { | ||
var _console5; | ||
@@ -172,12 +199,22 @@ | ||
(_console5 = console).error.apply(_console5, [message].concat(optionalParams)); | ||
(_console5 = console).warn.apply(_console5, ['[' + this.namespace + '] ' + message].concat(optionalParams)); | ||
} | ||
}; | ||
Logger.prototype.error = function error(message) { | ||
if ((0, _stringContains2.default)([LogLevel.ERROR, LogLevel.VERBOSE], this.logLevel)) { | ||
var _console6; | ||
for (var _len6 = arguments.length, optionalParams = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { | ||
optionalParams[_key6 - 1] = arguments[_key6]; | ||
} | ||
(_console6 = console).error.apply(_console6, ['[' + this.namespace + '] ' + message].concat(optionalParams)); | ||
} | ||
}; | ||
return Logger; | ||
}(); | ||
Logger.LogLevel = LogLevel; | ||
exports.default = Logger; | ||
module.exports = exports.default; | ||
exports.LogLevel = LogLevel; |
@@ -141,3 +141,3 @@ 'use strict'; | ||
exports.default = function () { | ||
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(input, cryptoProvider) { | ||
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(input, cryptoProvider, logger) { | ||
var zip; | ||
@@ -158,3 +158,3 @@ return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
_context2.next = 4; | ||
return (0, _zipUtil2.default)(input, cryptoProvider); | ||
return (0, _zipUtil2.default)(input, cryptoProvider, logger); | ||
@@ -176,3 +176,3 @@ case 4: | ||
function readEntries(_x2, _x3) { | ||
function readEntries(_x2, _x3, _x4) { | ||
return _ref2.apply(this, arguments); | ||
@@ -179,0 +179,0 @@ } |
@@ -36,6 +36,5 @@ 'use strict'; | ||
entry.stream() // is DuplexStream. | ||
.on('error', function (e) { | ||
_Logger2.default.error(e); | ||
reject(e); | ||
}).setEncoding('binary').on('data', function (chunk) { | ||
.setEncoding('binary').on('error', function (error) { | ||
return reject(error); | ||
}).on('data', function (chunk) { | ||
chunk = Buffer.from(chunk, 'binary'); | ||
@@ -89,7 +88,6 @@ if ((0, _typecheck.isExists)(_this.cryptoProvider)) { | ||
// eslint-disable-line arrow-body-style | ||
return new _promise2.default(function (resolve, reject) { | ||
return new _promise2.default(function (resolve) { | ||
var writeStream = _fsExtra2.default.createWriteStream(output, { encoding: 'binary' }); | ||
var onError = function onError(e) { | ||
_Logger2.default.error(e); | ||
reject(e); | ||
var onError = function onError(error) { | ||
resolve(error); | ||
writeStream.end(); | ||
@@ -117,3 +115,3 @@ }; | ||
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
var output, dir; | ||
var output, dir, error; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
@@ -132,6 +130,19 @@ while (1) { | ||
} | ||
_context2.next = 4; | ||
if (entry.path.endsWith('/')) { | ||
_context2.next = 7; | ||
break; | ||
} | ||
_context2.next = 5; | ||
return writeFile(entry, output); | ||
case 4: | ||
case 5: | ||
error = _context2.sent; | ||
if (error) { | ||
_this2.logger.error(error); | ||
} | ||
case 7: | ||
case 'end': | ||
@@ -174,6 +185,2 @@ return _context2.stop(); | ||
var _Logger = require('./Logger'); | ||
var _Logger2 = _interopRequireDefault(_Logger); | ||
var _typecheck = require('./typecheck'); | ||
@@ -192,3 +199,3 @@ | ||
exports.default = function () { | ||
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(file, cryptoProvider) { | ||
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(file, cryptoProvider, logger) { | ||
var open, zip; | ||
@@ -214,3 +221,4 @@ return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
getFile: getFile, | ||
extractAll: extractAll | ||
extractAll: extractAll, | ||
logger: logger | ||
})); | ||
@@ -226,3 +234,3 @@ | ||
function openZip(_x5, _x6) { | ||
function openZip(_x5, _x6, _x7) { | ||
return _ref4.apply(this, arguments); | ||
@@ -229,0 +237,0 @@ } |
{ | ||
"name": "@ridi/parser-core", | ||
"version": "0.3.0-alpha.5", | ||
"version": "0.3.0-alpha-10", | ||
"description": "Utilities for parsers", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61639
35
17
1543
4