-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(1.3.0): static code analysis and linting
- Loading branch information
Showing
29 changed files
with
5,331 additions
and
1,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.scannerwork | ||
.coveralls.yml | ||
.eslint | ||
_private | ||
_config | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
// "eslint.enable": false, | ||
"xo.enable": true, | ||
"xo.format.enable": true, | ||
"xo.options": { | ||
"semicolon": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ module.exports = { | |
] | ||
] | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,57 @@ | ||
import dotenv from 'dotenv-flow'; | ||
|
||
dotenv.config(); | ||
/* | ||
usage in programs: | ||
/* | ||
Usage in programs: | ||
import { config } from './lib/config.mjs'; | ||
to check the effective configuration: | ||
@see ../config.checher.mjs | ||
WARNING: to avoid circular reference this module **MUST** not import moduled that consumes configuration, such as: | ||
- <module-that-use-config-here>.mjs | ||
- <module-that-use-config-here>.mjs | ||
Coding Conventions: before each configuration a comment SHOULD be written; the comment also shows the names of the environment variables that can influence the effective configuration value. When present this comment MUST be updated also in the config.checker.mjs program. | ||
*/ | ||
|
||
const DEFAULT_IS_UNDER_TEST = false; | ||
|
||
const castToBoolen = (anyValue) => { | ||
// console.log(`castToBoolen::anyValue: ${anyValue}`); | ||
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`); | ||
// if (typeof anyValue === "string") { | ||
anyValue = anyValue.trim().toLowerCase(); | ||
// } else { console.log('branch never reached in tests'); } | ||
switch (anyValue) { | ||
case 'true': | ||
return true; | ||
case 'false': | ||
return false; | ||
default: | ||
const value = parseInt(anyValue); | ||
if (isNaN(value)) { | ||
throw new TypeError(`{anyValue} is not acceptable value for boolean configurable options`); | ||
} | ||
console.log(`castToBoolen::value: ${value}`); | ||
return value !== 0 ? true : false; | ||
} | ||
const castToBoolen = anyValue => { | ||
// Console.log(`castToBoolen::anyValue: ${anyValue}`); | ||
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`); | ||
// if (typeof anyValue === "string") { | ||
anyValue = anyValue.trim().toLowerCase(); | ||
// } else { console.log('branch never reached in tests'); } | ||
switch (anyValue) { | ||
case 'true': { | ||
return true; | ||
} | ||
|
||
case 'false': { | ||
return false; | ||
} | ||
|
||
default: { | ||
const value = parseInt(anyValue, 10); | ||
if (isNaN(value)) { | ||
throw new TypeError('{anyValue} is not acceptable value for boolean configurable options'); | ||
} | ||
|
||
console.log(`castToBoolen::value: ${value}`); | ||
return value !== 0; | ||
} | ||
} | ||
}; | ||
|
||
const config = { | ||
/* | ||
the test features are enabed | ||
/* | ||
The test features are enabed | ||
affected by .env IS_FILESTORE_WRITING_ENABLED | ||
*/ | ||
isUnderTest: function () { | ||
return process.env.IS_UNDER_TEST ? | ||
castToBoolen(process.env.IS_UNDER_TEST) : | ||
DEFAULT_IS_UNDER_TEST; | ||
} | ||
isUnderTest() { | ||
return process.env.IS_UNDER_TEST ? | ||
castToBoolen(process.env.IS_UNDER_TEST) : | ||
DEFAULT_IS_UNDER_TEST; | ||
} | ||
}; | ||
|
||
export { DEFAULT_IS_UNDER_TEST, config }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,79 @@ | ||
// import { logFactory } from './log.mjs'; | ||
// Import { logFactory } from './log.mjs'; | ||
|
||
const logFactory = { | ||
makeTraceFunction: (config) => { | ||
return (...args) => { | ||
if (config.isLogVerbose()) { | ||
console.trace(...args); | ||
} | ||
}}, | ||
makeDebugFunction: (config) => { | ||
return (...args) => { | ||
if (config.isLogVerbose()) { | ||
console.debug(...args); | ||
} | ||
}}, | ||
makeInfoFunction: (config) => { | ||
return (...args) => { | ||
if (!config.isLogSilent()) { | ||
console.info(...args); | ||
} | ||
}}, | ||
makeWarnFunction: (config) => { | ||
return (...args) => { | ||
if (!config.isLogSilent()) { | ||
console.warn(...args); | ||
} | ||
}}, | ||
makeErrorFunction: (config) => { | ||
return (...args) => { | ||
console.error(...args); | ||
}} | ||
}; | ||
makeTraceFunction: config => { | ||
return (...args) => { | ||
if (config.isLogVerbose()) { | ||
console.trace(...args); | ||
} | ||
}; | ||
}, | ||
makeDebugFunction: config => { | ||
return (...args) => { | ||
if (config.isLogVerbose()) { | ||
console.debug(...args); | ||
} | ||
}; | ||
}, | ||
makeInfoFunction: config => { | ||
return (...args) => { | ||
if (!config.isLogSilent()) { | ||
console.info(...args); | ||
} | ||
}; | ||
}, | ||
makeWarnFunction: config => { | ||
return (...args) => { | ||
if (!config.isLogSilent()) { | ||
console.warn(...args); | ||
} | ||
}; | ||
}, | ||
makeErrorFunction: () => { | ||
return (...args) => { | ||
console.error(...args); | ||
}; | ||
} | ||
}; | ||
|
||
class Log { | ||
constructor(config) { | ||
if ( config.isLogVerbose() && config.isLogSilent() ) { | ||
throw new Error(`log misconfiguration : isLogVerbose:${config.isLogVerbose()} && isLogSilent:${config.isLogSilent()}`); | ||
} | ||
this._trace = logFactory.makeTraceFunction(config); | ||
this._debug = logFactory.makeDebugFunction(config); | ||
this._info = logFactory.makeInfoFunction(config); | ||
this._warn = logFactory.makeWarnFunction(config); | ||
this._error = logFactory.makeErrorFunction(config); | ||
constructor(config) { | ||
if (config.isLogVerbose() && config.isLogSilent()) { | ||
throw new Error(`log misconfiguration : isLogVerbose:${config.isLogVerbose()} && isLogSilent:${config.isLogSilent()}`); | ||
} | ||
|
||
this._config = config; | ||
} | ||
|
||
trace(...args) { | ||
return this._trace(...args); | ||
} | ||
this._trace = logFactory.makeTraceFunction(config); | ||
this._debug = logFactory.makeDebugFunction(config); | ||
this._info = logFactory.makeInfoFunction(config); | ||
this._warn = logFactory.makeWarnFunction(config); | ||
this._error = logFactory.makeErrorFunction(config); | ||
|
||
debug(...args) { | ||
return this._debug(...args); | ||
} | ||
|
||
info(...args) { | ||
return this._info(...args); | ||
} | ||
this._config = config; | ||
} | ||
|
||
warn(...args) { | ||
return this._warn(...args); | ||
} | ||
|
||
error(...args) { | ||
return this._error(...args); | ||
} | ||
trace(...args) { | ||
return this._trace(...args); | ||
} | ||
|
||
getLogConfig(...args) { | ||
return this._config; | ||
} | ||
debug(...args) { | ||
return this._debug(...args); | ||
} | ||
|
||
info(...args) { | ||
return this._info(...args); | ||
} | ||
|
||
warn(...args) { | ||
return this._warn(...args); | ||
} | ||
|
||
error(...args) { | ||
return this._error(...args); | ||
} | ||
|
||
getLogConfig() { | ||
return this._config; | ||
} | ||
} | ||
|
||
export { Log }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,67 @@ | ||
import dotenv from 'dotenv-flow'; | ||
|
||
dotenv.config(); | ||
/* | ||
usage in programs: | ||
/* | ||
Usage in programs: | ||
import { config } from './lib/config.mjs'; | ||
to check the effective configuration: | ||
@see ../config.checher.mjs | ||
WARNING: to avoid circular reference this module **MUST** not import moduled that consumes configuration, such as: | ||
- <module-that-use-config-here>.mjs | ||
- <module-that-use-config-here>.mjs | ||
Coding Conventions: before each configuration a comment SHOULD be written; the comment also shows the names of the environment variables that can influence the effective configuration value. When present this comment MUST be updated also in the config.checker.mjs program. | ||
*/ | ||
|
||
const DEFAULT_IS_LOG_VERBOSE = false; | ||
const DEFAULT_IS_LOG_SILENT = true; | ||
|
||
const castToBoolen = (anyValue) => { | ||
// console.log(`castToBoolen::anyValue: ${anyValue}`); | ||
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`); | ||
// if (typeof anyValue === "string") { | ||
anyValue = anyValue.trim().toLowerCase(); | ||
// } else { console.log('branch never reached in tests'); } | ||
switch (anyValue) { | ||
case 'true': | ||
return true; | ||
case 'false': | ||
return false; | ||
default: | ||
const value = parseInt(anyValue); | ||
if (isNaN(value)) { | ||
throw new TypeError(`{anyValue} is not acceptable value for boolean configurable options`); | ||
} | ||
console.log(`castToBoolen::value: ${value}`); | ||
return value !== 0 ? true : false; | ||
} | ||
const castToBoolen = anyValue => { | ||
// Console.log(`castToBoolen::anyValue: ${anyValue}`); | ||
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`); | ||
// if (typeof anyValue === "string") { | ||
anyValue = anyValue.trim().toLowerCase(); | ||
// } else { console.log('branch never reached in tests'); } | ||
switch (anyValue) { | ||
case 'true': { | ||
return true; | ||
} | ||
|
||
case 'false': { | ||
return false; | ||
} | ||
|
||
default: { | ||
const value = parseInt(anyValue, 10); | ||
if (isNaN(value)) { | ||
throw new TypeError('{anyValue} is not acceptable value for boolean configurable options'); | ||
} | ||
|
||
console.log(`castToBoolen::value: ${value}`); | ||
return value !== 0; | ||
} | ||
} | ||
}; | ||
|
||
const logconfig = { | ||
/* | ||
the log is verbose enabed | ||
/* | ||
The log is verbose enabed | ||
affected by .env IS_LOG_VERBOSE | ||
*/ | ||
isLogVerbose: function () { | ||
return process.env.IS_LOG_VERBOSE ? | ||
castToBoolen(process.env.IS_LOG_VERBOSE) : | ||
DEFAULT_IS_LOG_VERBOSE; | ||
}, | ||
/* | ||
the log is verbose enabed | ||
isLogVerbose() { | ||
return process.env.IS_LOG_VERBOSE ? | ||
castToBoolen(process.env.IS_LOG_VERBOSE) : | ||
DEFAULT_IS_LOG_VERBOSE; | ||
}, | ||
/* | ||
The log is verbose enabed | ||
affected by .env IS_LOG_VERBOSE | ||
*/ | ||
isLogSilent: function () { | ||
return process.env.IS_LOG_SILENT ? | ||
castToBoolen(process.env.IS_LOG_SILENT) : | ||
DEFAULT_IS_LOG_SILENT; | ||
} | ||
isLogSilent() { | ||
return process.env.IS_LOG_SILENT ? | ||
castToBoolen(process.env.IS_LOG_SILENT) : | ||
DEFAULT_IS_LOG_SILENT; | ||
} | ||
}; | ||
|
||
export { DEFAULT_IS_LOG_SILENT, DEFAULT_IS_LOG_VERBOSE, logconfig }; |
Oops, something went wrong.