analogger 1.7.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.run/Debuggable demo.run.xml +12 -0
- package/.run/Demo in browser with importmap.run.xml +12 -0
- package/.toesm.cjs +4 -20
- package/CHANGELOG.md +7 -1
- package/README.md +9 -9
- package/dist/analogger-browser.min.mjs +2 -0
- package/generated/browser/demo.mjs +102 -0
- package/generated/browser/example/cjs/contexts-def.mjs +22 -0
- package/generated/browser/node_modules/rgb-hex/index.mjs +43 -0
- package/generated/browser/node_modules/to-ansi/index.mjs +285 -0
- package/generated/browser/src/cjs/ana-logger.mjs +805 -0
- package/generated/browser/src/cjs/constants.mjs +37 -0
- package/package.json +37 -21
- package/dist/index-cjs.min.cjs +0 -2
- package/dist/index-esm.min.mjs +0 -2
- package/dist/index.css +0 -83
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
|
2
|
+
<configuration default="false" name="Debuggable demo" type="js.build_tools.npm">
|
|
3
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
+
<command value="run" />
|
|
5
|
+
<scripts>
|
|
6
|
+
<script value="quick:run" />
|
|
7
|
+
</scripts>
|
|
8
|
+
<node-interpreter value="project" />
|
|
9
|
+
<envs />
|
|
10
|
+
<method v="2" />
|
|
11
|
+
</configuration>
|
|
12
|
+
</component>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
|
2
|
+
<configuration default="false" name="Demo in browser with importmap" type="js.build_tools.npm">
|
|
3
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
+
<command value="run" />
|
|
5
|
+
<scripts>
|
|
6
|
+
<script value="build:browser:importmap" />
|
|
7
|
+
</scripts>
|
|
8
|
+
<node-interpreter value="project" />
|
|
9
|
+
<envs />
|
|
10
|
+
<method v="2" />
|
|
11
|
+
</configuration>
|
|
12
|
+
</component>
|
package/.toesm.cjs
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
+
const os = require("os");
|
|
1
2
|
module.exports = {
|
|
2
3
|
replaceStart: [
|
|
3
4
|
{
|
|
4
|
-
search :
|
|
5
|
-
replace: `const chalk = null;`
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
search : "const colorConvert = require('color-convert-cjs');",
|
|
5
|
+
search : "const colorConvert = require(\"color-convert-cjs\");",
|
|
9
6
|
replace: `const colorConvert = null;`
|
|
10
7
|
},
|
|
11
8
|
{
|
|
12
|
-
search:
|
|
13
|
-
replace:
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
search: "// alert(result)",
|
|
17
|
-
replace: "alert(result)"
|
|
9
|
+
search : /const\s+chalk\s*=\s*require\(.chalk-cjs.\)[;]?/g,
|
|
10
|
+
replace: `${os.EOL}const chalk = null;${os.EOL}`
|
|
18
11
|
},
|
|
19
12
|
],
|
|
20
13
|
replaceEnd : [
|
|
@@ -25,15 +18,6 @@ module.exports = {
|
|
|
25
18
|
],
|
|
26
19
|
replaceModules:
|
|
27
20
|
{
|
|
28
|
-
chalk: {
|
|
29
|
-
cjs: {
|
|
30
|
-
name: "chalk-cjs",
|
|
31
|
-
version: "@^4.1.2",
|
|
32
|
-
},
|
|
33
|
-
esm: {
|
|
34
|
-
version: "@latest"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
21
|
"rgb-hex": {
|
|
38
22
|
cjs: {
|
|
39
23
|
name: "rgb-hex-cjs",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
## [1.8.2](https://github.com/thimpat/analogger/compare/v1.8.1...v1.8.2) (2022-02-28)
|
|
2
2
|
|
|
3
|
+
## [1.8.1](https://github.com/thimpat/analogger/compare/v1.8.0...v1.8.1) (2022-02-28)
|
|
4
|
+
|
|
5
|
+
# [1.8.0](https://github.com/thimpat/analogger/compare/v1.7.0...v1.8.0) (2022-02-23)
|
|
6
|
+
|
|
7
|
+
# [1.7.0](https://github.com/thimpat/analogger/compare/v1.6.2...v1.7.0) (2022-02-11)
|
|
8
|
+
|
|
3
9
|
## [1.6.2](https://github.com/thimpat/analogger/compare/v1.6.1...v1.6.2) (2022-02-11)
|
|
4
10
|
|
|
5
11
|
## [1.6.1](https://github.com/thimpat/analogger/compare/v1.6.0...v1.6.1) (2022-02-11)
|
package/README.md
CHANGED
|
@@ -84,14 +84,14 @@ Display the browser native message box if run from it; otherwise, it displays th
|
|
|
84
84
|
### setOptions()
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
| **Options** | **default** | **Expect** | **Description**
|
|
88
|
-
|
|
89
|
-
| silent | false | boolean | _No log will be displayed (only errors)_
|
|
90
|
-
| hideError | false | boolean | _Hide errors from console_
|
|
87
|
+
| **Options** | **default** | **Expect** | **Description** |
|
|
88
|
+
|------------------|-------------|--------------|------------------------------------------------------------------------------------|
|
|
89
|
+
| silent | false | boolean | _No log will be displayed (only errors)_ |
|
|
90
|
+
| hideError | false | boolean | _Hide errors from console_ |
|
|
91
91
|
| hideHookMessage | false | boolean | _Hide the automatic message shown when some native console methods are overridden_ |
|
|
92
|
-
|
|
|
93
|
-
| logToDom |
|
|
94
|
-
| logToFile |
|
|
92
|
+
| hidePassingTests | false | boolean | _Hide Live test results_ |
|
|
93
|
+
| logToDom | false | string (DOM Selector) | _display log in a DOM container_ |
|
|
94
|
+
| logToFile | false | string (File path) | _write log to a file if running from Node_ |
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
```javascript
|
|
@@ -104,14 +104,14 @@ anaLogger.setOptions({hideHookMessage: true, logToDom: "#analogger"})
|
|
|
104
104
|
### overrideConsole()
|
|
105
105
|
|
|
106
106
|
```javascript
|
|
107
|
-
anaLogger.setOptions({silent:
|
|
107
|
+
anaLogger.setOptions({silent: false, hideError: false})
|
|
108
108
|
console.log(`Log Before override`);
|
|
109
109
|
anaLogger.overrideConsole()
|
|
110
110
|
console.log(`Log After override`);
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
Override console.log, console.info and console.warn. If you already have many console.log running in your system,
|
|
114
|
-
it allows
|
|
114
|
+
it allows formatting them or hiding then (silent = true) all in one go.
|
|
115
115
|
In this example, the terminal (or inspector) will not show the message "Log After override". All following messages
|
|
116
116
|
either.
|
|
117
117
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const s={};{s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"]={};const o=["#d2466e","#FFA07A","#FF7F50","#FF6347","#FFE4B5","#ADFF2F","#808000","#40E0D0","#1E90FF","#EE82EE","#708090","#DEB887","#FE642E","#210B61","#088A4B","#5E610B","#FA8258","#088A68","#B40431"],t={BROWSER:"BROWSER",NODE:"NODE"};var r=o,e=t;s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"].COLOR_TABLE=r,s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"].SYSTEM=e}s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"]={},s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"].default=function(e,o,t,s){var r=(e+(s||"")).toString().includes("%");if("string"==typeof e?[e,o,t,s]=e.match(/(0?\.?\d{1,3})%?\b/g).map(e=>Number(e)):void 0!==s&&(s=Number.parseFloat(s)),"number"!=typeof e||"number"!=typeof o||"number"!=typeof t||255<e||255<o||255<t)throw new TypeError("Expected three numbers below 256");if("number"==typeof s){if(!r&&0<=s&&s<=1)s=Math.round(255*s);else{if(!(r&&0<=s&&s<=100))throw new TypeError(`Expected alpha value (${s}) as a fraction or percentage`);s=Math.round(255*s/100)}s=(256|s).toString(16).slice(1)}else s="";return(t|o<<8|e<<16|1<<24).toString(16).slice(1)+s};{s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102={};const i={Foreground:38,Background:48},u="[0m",d={Bold:"[1m",Underline:"[4m",Reversed:"[7m"},p=(e,o,t)=>e===o&&o===t?e<8?16:248<e?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(o/255*5)+Math.round(t/255*5),b=e=>{e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,o,t,s){return o+o+t+t+s+s});e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return e?{red:parseInt(e[1],16),blue:parseInt(e[2],16),green:parseInt(e[3],16)}:{}},c=function(e,o,t){return t<0&&(t+=1),1<t&&--t,t<1/6?e+6*(o-e)*t:t<.5?o:t<2/3?e+(o-e)*(2/3-t)*6:e};function n({red:e,blue:o,green:t},s=!0){if(void 0===e||void 0===o||void 0===t)return"";e=p(e,o,t);return`[${s?i.Foreground:i.Background};5;`+e+"m "}function a(e,o){var{red:e,green:t,blue:s}=b(e);return n({red:e,green:t,blue:s},o)}function l({hue:e,saturation:o,lightness:t},s){var{red:e,green:o,blue:t}=(({hue:e,saturation:o,lightness:t})=>{let s,r,i;return 0===o?s=r=i=t:(o=2*t-(t=t<.5?t*(1+o):t+o-t*o),s=c(o,t,e+1/3),r=c(o,t,e),i=c(o,t,e-1/3)),{red:Math.round(255*s),blue:Math.round(255*i),green:Math.round(255*r)}})({hue:e,saturation:o,lightness:t});return n({red:e,green:o,blue:t},s)}function g(e,{fg:o,bg:t,isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){let n="";return o&&(n+=o),t&&(n+=t),s&&(n+=d.Underline),r&&(n+=d.Bold),i&&(n+=d.Reversed),n+e+u}s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102.default={fromRgb:n,fromHexa:a,fromHsl:l,getTextFromRgb:function(e,{fg:o={},bg:t={},isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){return g(e,{fg:o=o&&n({...o}),bg:t=t&&n({...t},!1),isUnderline:s,isBold:r,isReversed:i})},getTextFromHsl:function(e,{fg:o="",bg:t="",isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){return g(e,{fg:o=o&&l({...o}),bg:t=t&&l({...t},!1),isUnderline:s,isBold:r,isReversed:i})},getTextFromHex:function(e,{fg:o="",bg:t="",isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){return g(e,{fg:o=o&&a(o),bg:t=t&&a(t,!1),isUnderline:s,isBold:r,isReversed:i})},hexToRgb:b,rgbToAnsi256:p,hue2rgb:c,RESET:u,FONT_STYLE:d,STYLE:{Bold:"[1m",Underline:"[4m",Reversed:"[7m"}}}{s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"]={};let i=s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102.default,t=s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"].default,{COLOR_TABLE:o,SYSTEM:e}=s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"];class h{system="";logIndex=0;logCounter=0;contexts=[];targets={};activeTarget=null;indexColor=0;format="";keepLog=!1;logHistory=[];$containers=null;options={hideHookMessage:!1};static ALIGN={LEFT:"LEFT",RIGHT:"RIGHT"};static ENVIRONMENT_TYPE={BROWSER:"BROWSER",NODE:"NODE",OTHER:"OTHER"};originalFormatFunction;constructor(){if(h.Instance)return h.Instance;(h.Instance=this).system="object"==typeof process?e.NODE:e.BROWSER,this.format=this.onBuildLog.bind(this),this.originalFormatFunction=this.format,this.errorTargetHandler=this.onError.bind(this),this.errorUserTargetHandler=this.onErrorForUserTarget.bind(this),this.setOptions(this.options),this.realConsoleLog=console.log,this.realConsoleInfo=console.info,this.realConsoleWarn=console.warn,this.realConsoleError=console.error,this.ALIGN=h.ALIGN,this.ENVIRONMENT_TYPE=h.ENVIRONMENT_TYPE}keepLogHistory(){this.keepLog=!0}releaseLogHistory(){this.keepLog=!1}resetLogHistory(){this.logHistory=[]}getLogHistory(e=!0,o=`
|
|
2
|
+
`){const t=JSON.parse(JSON.stringify(this.logHistory.slice(0)));return e?t.join(o):t}isNode(){return this.system===e.NODE}isBrowser(){return!this.isNode()}resetLogger(){this.options={contextLenMax:10,idLenMax:5,lidLenMax:5,symbolLenMax:2,messageLenMax:void 0,hideLog:void 0,hideError:void 0,hideHookMessage:void 0,hidePassingTests:void 0,logToDom:void 0,logToFile:void 0,oneConsolePerContext:void 0,silent:void 0}}resetOptions(){this.options.contextLenMax=10,this.options.idLenMax=5,this.options.lidLenMax=5,this.options.messageLenMax=void 0,this.options.symbolLenMax=60,this.options.hideHookMessage=!1,this.options.hidePassingTests=!1,this.options.hideLog=!1,this.options.hideError=!1,this.options.oneConsolePerContext=!0,this.options.logToDom=void 0,this.options.logToDomlogToFile=void 0,this.options.silent=!1}setOptions({contextLenMax:e=10,idLenMax:o=5,lidLenMax:d=5,symbolLenMax:c=2,messageLenMax:h=void 0,hideLog:t=void 0,hideError:s=void 0,hideHookMessage:r=void 0,hidePassingTests:i=void 0,logToDom:n=void 0,logToFile:a=void 0,oneConsolePerContext:l=void 0,silent:g=void 0}=null){this.options.contextLenMax=e,this.options.idLenMax=o,this.options.lidLenMax=d,this.options.messageLenMax=h,this.options.symbolLenMax=c,void 0!==i&&(this.options.hidePassingTests=!!i),void 0!==r&&(this.options.hideHookMessage=!!r),void 0!==t&&(this.options.hideLog=!!t),void 0!==s&&(this.options.hideError=!!s),void 0!==l&&(this.options.oneConsolePerContext=!!l),void 0!==n&&(this.options.logToDom=n||"#analogger"),void 0!==a&&(this.isBrowser()||(this.options.logToFile=a||"./analogger.log"),this.realConsoleLog("LogToFile is not supported in this environment. ")),void 0!==g&&(this.options.silent=!!g,this.options.hideLog=this.options.silent)}getOptions(){return this.options}truncateMessage(e="",{fit:o=0,align:t=h.ALIGN.LEFT}={}){return e=""+e,o&&e.length>=o+2&&(e=e.substring(0,o-3)+"..."),e=t===h.ALIGN.LEFT?e.padEnd(o," "):e.padStart(o," ")}onBuildLog({contextName:e,message:o="",lid:t="",symbol:s=""}={}){const r=new Date;var i=("0"+r.getHours()).slice(-2)+":"+("0"+r.getMinutes()).slice(-2)+":"+("0"+r.getSeconds()).slice(-2),i=this.truncateMessage(i,{fit:7});return e=this.truncateMessage(e,{fit:this.options.contextLenMax,align:h.ALIGN.RIGHT}),t=this.truncateMessage(t,{fit:this.options.lidLenMax}),void 0!==this.options.messageLenMax&&(o=this.truncateMessage(o,{fit:this.options.messageLenMax})),`[${i}] ${e}: (${t}) ${s=this.truncateMessage(s,{fit:this.options.symbolLenMax})} `+o}onErrorForUserTarget(e,...o){this.errorUserTargetHandler(e,...o)}onError(e,...o){e.target===this.targets.USER&&this.onErrorForUserTarget(e,...o)}onDisplayLog(...e){this.log(...e)}onDisplayError(...e){this.error(...e)}setLogFormat(e){if("function"!=typeof e)return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}resetLogFormatter(){this.format=this.originalFormatFunction}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContextValid(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e&&(e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"))}generateDefaultContext(){const e={name:"DEFAULT",contextName:"DEFAULT",target:"ALL",symbol:"⚡"};return e.id=this.logIndex++,e.color=o[1],e}generateNewContext(){const e=this.generateDefaultContext();return e.color=o[this.indexColor++%(o.length-3)+2],e.symbol="",e}generateErrorContext(){const e=this.generateDefaultContext();return e.color=o[0],e.symbol="v",e.error=!0,e}#allegeProperties(e){let o=e;e=this.generateNewContext();return-1<(o=Object.assign({},e,o)).color.toLowerCase().indexOf("rgb")?o.color="#"+t(o.color):-1===o.color.indexOf("#")&&0,o}setContexts(t){const e=Object.keys(t);t.DEFAULT=this.contexts.DEFAULT=this.generateDefaultContext(),t.ERROR=this.contexts.ERROR=this.generateErrorContext(),e.forEach(e=>{const o=t[e]||{};o.contextName=e,o.name=e,this.contexts[e]=this.#allegeProperties(o),t[e]=this.contexts[e]})}setTargets(e={}){this.targets=Object.assign({},e,{ALL:"ALL",USER:"USER"})}setActiveTarget(e){this.activeTarget=e}isTargetAllowed(e){return!e||!this.activeTarget||(e===this.targets.ALL||this.activeTarget===e)}setColumns(e,o,t){let s=0;for(var r in o)if("name"!==r){var i=o[r];const n=document.createElement("span");n.classList.add("analogger-col","analogger-col-"+r,"analogger-col-"+s),++s,n.textContent=i,e.append(n)}const n=document.createElement("span");n.classList.add("analogger-col","analogger-col-text","analogger-col-"+s),n.textContent=t,e.append(n)}writeLogToDom(t,s){this.$containers=this.$containers||document.querySelectorAll(this.options.logToDom);for(let o=0;o<this.$containers.length;++o){const r=this.$containers[o];let e=r.querySelector(".analogger-view");e||((e=document.createElement("div")).classList.add("analogger-view"),r.append(e));const i=document.createElement("div");i.classList.add("to-esm-line"),i.style.color=t.color,i.setAttribute("data-log-counter",this.logCounter),i.setAttribute("data-log-index",this.logIndex),this.setColumns(i,t,s),e.append(i)}}writeLogToFile(e){this.logFile.write(e+this.EOL)}processOutput(t={}){try{if(!this.isTargetAllowed(t.target))return;let e=Array.prototype.slice.call(arguments);e.shift();var s=e.join(" | ");let o="";var r=this.format({...t,message:s});if(++this.logCounter,this.isBrowser()?(t.environnment=h.ENVIRONMENT_TYPE.BROWSER,this.options.logToDom&&this.writeLogToDom(t,r),o="%c"+r):(t.environnment=h.ENVIRONMENT_TYPE.NODE,o=i.getTextFromHex(r,{fg:t.color}),this.options.logToFile&&this.writeLogToFile(r)),this.keepLog&&this.logHistory.push(o),this.options.hideLog)return;this.isBrowser()?this.realConsoleLog(o,"color: "+t.color):this.realConsoleLog(o),this.errorTargetHandler(t,e)}catch(e){console.error("AnaLogger:",e.message)}}isExtendedOptionsPassed(e){return"object"==typeof e&&(e.hasOwnProperty("context")||e.hasOwnProperty("target")||e.hasOwnProperty("color")||e.hasOwnProperty("lid"))}convertToContext(e,o){o=o||this.generateDefaultContext();let t=e=e||o;if(e.context&&"object"==typeof e.context){const s=Object.assign({},e);delete s.context,t=Object.assign({},e.context,s)}return delete(t=Object.assign({},o,t)).context,t}log(e,...o){if(!this.isExtendedOptionsPassed(e))return t=this.generateDefaultContext(),void this.processOutput.apply(this,[t,e,...o]);var t=this.convertToContext(e);this.processOutput.apply(this,[t,...o])}error(e,...o){if(!this.options.hideError){if(!this.isExtendedOptionsPassed(e))return t=this.generateErrorContext(),void this.processOutput.apply(this,[t,e,...o]);var t=this.generateErrorContext(),t=this.convertToContext(e,t),s=Array.prototype.slice.call(arguments,1);this.log(t,...s)}}overrideError(){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}overrideConsole({log:e=!0,info:o=!0,warn:t=!0,error:s=!1}={}){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.log"),e&&(console.log=this.onDisplayLog.bind(this)),o&&(console.info=this.onDisplayLog.bind(this)),t&&(console.warn=this.onDisplayLog.bind(this)),s&&this.overrideError()}removeOverrideError(){console.warn=this.realConsoleError}removeOverride({log:e=!0,info:o=!0,warn:t=!0,error:s=!1}={}){e&&(console.log=this.realConsoleLog),o&&(console.info=this.realConsoleInfo),t&&(console.warn=this.realConsoleWarn),s&&this.removeOverrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}alert(...e){if(this.isNode())return this.log(...e);e=e.join(" | ");alert(e)}assert(e,o=!0,...t){try{return"function"==typeof e?e(...t)!==o?(this.error("Asset failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0):e!==o?(this.error("Assert failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)}catch(e){this.error("Unexpected error in assert")}return!1}}s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"].default=new h,r=new h,s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"].anaLogger=r}s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e={},s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e.LOG_CONTEXTS={STANDARD:{},TEST:{color:"#B18904",symbol:"⏰"},TEST2:{color:"rgb(127, 127, 127)",symbol:"⏰"},TEST3:{color:"blue",symbol:"⏰"},C1:null,C2:null,C3:null,DEFAULT:{}},s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e.LOG_TARGETS={ALL:"ALL",DEV1:"TOM",DEV2:"TIM",DEV3:"ME",USER:"USER"};{s.ca63110bb9882fce16420271e1c0aa1a22360931c93ababb90ba99d2da8a867c={};var{LOG_CONTEXTS:e,LOG_TARGETS:r}=s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e;let o=s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"]["anaLogger"];o.keepLogHistory(),o.setContexts(e),o.setTargets(r),o.setActiveTarget(r.DEV3),o.setOptions({logToDom:".analogger"}),o.setOptions({silent:!0}),console.log("=========================="),o.log(e.C1,"You should not see this C1"),o.log(e.C2,"You should not see this C2"),o.log(e.C3,"You should not see this C3"),o.setOptions({silent:!1,hideError:!1,logToFile:"./logme.log"}),o.log(e.C1,"You should see this C100"),o.log(e.C2,"You should see this C200"),o.log(e.C3,"You should see this C300"),console.log("============= From History ==========================="),console.log(o.getLogHistory()),console.log("============= From History (Closed) =================="),o.assert(!0),o.assert(!1),o.assert(()=>!0,!0),o.assert((e,o)=>e===o,!0,2,2),console.log("-------------------------- console.log is about to be overridden"),o.overrideConsole(),console.log("Log After override <= Console.log is overridden"),console.error("-------------------------- console.error is about to be overridden"),o.overrideError(),console.error("Hook on Error placed after override <= Console.error is also overridden"),console.log("=========================="),o.log(e.STANDARD,"Basic Log example 2","+Something 0","+Something 1"),o.log({context:e.TEST,lid:1e5},"Test Log example"),o.log({context:e.TEST,target:r.DEV3,lid:100001},"Test Log example with active target"),o.log({context:e.TEST,target:r.DEV1,lid:100002},"Test Log example with DEV1 target"),o.log({context:e.TEST,target:r.DEV2,lid:100003},"Test Log example with DEV2 target"),o.log("Test Log example with DEFAULT target"),o.log(e.TEST,"Test Log example","+Something 3"),o.log(e.C1,"Test Log example C1"),o.log(e.C2,"Test Log example C2"),o.log(e.C3,"Test Log example C3"),console.log(e.C1,"Test Log example C4"),console.log(e.C1,"Test Log example C5"),console.log(e.C1,"Test Log example C6"),console.error({context:e.ERROR,lid:2e5},"Testing Error 1"),console.error(e.ERROR,"Testing Error 2"),console.error("Testing Error 3"),console.error(void 0,"Testing Error 4"),console.error({context:e.ERROR,target:r.USER,lid:200010},"Testing Error 4"),o.info("Hello from alert",{aaa:1012}),o.setActiveTarget(r.USER),o.setErrorHandlerForUserTarget(function(e){o.log("User explicitly see this message"),o.info("User explicitly see this message",e)}),console.error({context:e.ERROR,target:r.USER,lid:200020},"Testing Error that triggers a special handler"),o.setLogFormat(function({contextName:e,message:o}){return e+": "+o}),console.log(e.C1,"Test Log example C4 with new format"),console.log(e.C1,"Test Log example C5 with new format"),console.log(e.C1,"Test Log example C6 with new format"),o.log("Basic Log example 1")}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
3
|
+
* This file is generated following the conversion of
|
|
4
|
+
* [./example/cjs/demo.cjs]{@link ./example/cjs/demo.cjs}
|
|
5
|
+
*
|
|
6
|
+
**/
|
|
7
|
+
import {LOG_CONTEXTS, LOG_TARGETS} from "./example/cjs/contexts-def.mjs";
|
|
8
|
+
import {anaLogger} from "./src/cjs/ana-logger.mjs";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
anaLogger.keepLogHistory();
|
|
12
|
+
|
|
13
|
+
anaLogger.setContexts(LOG_CONTEXTS);
|
|
14
|
+
anaLogger.setTargets(LOG_TARGETS);
|
|
15
|
+
anaLogger.setActiveTarget(LOG_TARGETS.DEV3);
|
|
16
|
+
anaLogger.setOptions({logToDom: ".analogger"});
|
|
17
|
+
anaLogger.setOptions({silent: true});
|
|
18
|
+
|
|
19
|
+
console.log("==========================");
|
|
20
|
+
anaLogger.log(LOG_CONTEXTS.C1, "You should not see this C1");
|
|
21
|
+
anaLogger.log(LOG_CONTEXTS.C2, "You should not see this C2");
|
|
22
|
+
anaLogger.log(LOG_CONTEXTS.C3, "You should not see this C3");
|
|
23
|
+
|
|
24
|
+
anaLogger.setOptions({silent: false, hideError: false, logToFile: "./logme.log"});
|
|
25
|
+
anaLogger.log(LOG_CONTEXTS.C1, "You should see this C100");
|
|
26
|
+
anaLogger.log(LOG_CONTEXTS.C2, "You should see this C200");
|
|
27
|
+
anaLogger.log(LOG_CONTEXTS.C3, "You should see this C300");
|
|
28
|
+
|
|
29
|
+
console.log("============= From History ===========================");
|
|
30
|
+
console.log(anaLogger.getLogHistory());
|
|
31
|
+
console.log("============= From History (Closed) ==================");
|
|
32
|
+
|
|
33
|
+
anaLogger.assert(1 === 1);
|
|
34
|
+
anaLogger.assert(1 === 2);
|
|
35
|
+
anaLogger.assert(() => true, true);
|
|
36
|
+
|
|
37
|
+
anaLogger.assert((a, b) => a === b, true, 2, 2);
|
|
38
|
+
|
|
39
|
+
console.log("-------------------------- console.log is about to be overridden");
|
|
40
|
+
anaLogger.overrideConsole();
|
|
41
|
+
console.log("Log After override <= Console.log is overridden");
|
|
42
|
+
console.error("-------------------------- console.error is about to be overridden");
|
|
43
|
+
anaLogger.overrideError();
|
|
44
|
+
console.error("Hook on Error placed after override <= Console.error is also overridden");
|
|
45
|
+
console.log("==========================");
|
|
46
|
+
|
|
47
|
+
anaLogger.log(LOG_CONTEXTS.STANDARD, "Basic Log example 2", "+Something 0", "+Something 1");
|
|
48
|
+
|
|
49
|
+
anaLogger.log({context: LOG_CONTEXTS.TEST, lid: 100000}, "Test Log example");
|
|
50
|
+
anaLogger.log({
|
|
51
|
+
context: LOG_CONTEXTS.TEST,
|
|
52
|
+
target : LOG_TARGETS.DEV3,
|
|
53
|
+
lid : 100001
|
|
54
|
+
}, "Test Log example with active target");
|
|
55
|
+
anaLogger.log({context: LOG_CONTEXTS.TEST, target: LOG_TARGETS.DEV1, lid: 100002}, "Test Log example with DEV1 target");
|
|
56
|
+
anaLogger.log({context: LOG_CONTEXTS.TEST, target: LOG_TARGETS.DEV2, lid: 100003}, "Test Log example with DEV2 target");
|
|
57
|
+
anaLogger.log("Test Log example with DEFAULT target");
|
|
58
|
+
|
|
59
|
+
anaLogger.log(LOG_CONTEXTS.TEST, "Test Log example", "+Something 3");
|
|
60
|
+
anaLogger.log(LOG_CONTEXTS.C1, "Test Log example C1");
|
|
61
|
+
anaLogger.log(LOG_CONTEXTS.C2, "Test Log example C2");
|
|
62
|
+
anaLogger.log(LOG_CONTEXTS.C3, "Test Log example C3");
|
|
63
|
+
|
|
64
|
+
console.log(LOG_CONTEXTS.C1, "Test Log example C4");
|
|
65
|
+
console.log(LOG_CONTEXTS.C1, "Test Log example C5");
|
|
66
|
+
console.log(LOG_CONTEXTS.C1, "Test Log example C6");
|
|
67
|
+
|
|
68
|
+
console.error({context: LOG_CONTEXTS.ERROR, lid: 200000}, "Testing Error 1");
|
|
69
|
+
console.error(LOG_CONTEXTS.ERROR, "Testing Error 2");
|
|
70
|
+
console.error("Testing Error 3");
|
|
71
|
+
console.error(undefined, "Testing Error 4");
|
|
72
|
+
|
|
73
|
+
console.error({context: LOG_CONTEXTS.ERROR, target: LOG_TARGETS.USER, lid: 200010}, "Testing Error 4");
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
anaLogger.info("Hello from alert", {aaa: 1012});
|
|
77
|
+
|
|
78
|
+
anaLogger.setActiveTarget(LOG_TARGETS.USER);
|
|
79
|
+
anaLogger.setErrorHandlerForUserTarget(function (context/*, ...args*/)
|
|
80
|
+
{
|
|
81
|
+
anaLogger.log("User explicitly see this message");
|
|
82
|
+
anaLogger.info("User explicitly see this message", context);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
console.error({
|
|
86
|
+
context: LOG_CONTEXTS.ERROR,
|
|
87
|
+
target : LOG_TARGETS.USER,
|
|
88
|
+
lid : 200020
|
|
89
|
+
}, "Testing Error that triggers a special handler");
|
|
90
|
+
|
|
91
|
+
anaLogger.setLogFormat(
|
|
92
|
+
function({contextName, message})
|
|
93
|
+
{
|
|
94
|
+
return `${contextName}: ${message}`;
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
console.log(LOG_CONTEXTS.C1, "Test Log example C4 with new format");
|
|
99
|
+
console.log(LOG_CONTEXTS.C1, "Test Log example C5 with new format");
|
|
100
|
+
console.log(LOG_CONTEXTS.C1, "Test Log example C6 with new format");
|
|
101
|
+
|
|
102
|
+
anaLogger.log("Basic Log example 1");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
3
|
+
* This file is generated following the conversion of
|
|
4
|
+
* [./example/cjs/contexts-def.cjs]{@link ./example/cjs/contexts-def.cjs}
|
|
5
|
+
*
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @type {{C3: null, TEST: {symbol: string, color: string}, STANDARD: {}, C1: null, DEFAULT: {}, C2: null}}
|
|
10
|
+
*/
|
|
11
|
+
export const LOG_CONTEXTS = {
|
|
12
|
+
STANDARD: {},
|
|
13
|
+
TEST: {color: "#B18904", symbol: "⏰"},
|
|
14
|
+
TEST2: {color: "rgb(127, 127, 127)", symbol: "⏰"},
|
|
15
|
+
TEST3: {color: "blue", symbol: "⏰"},
|
|
16
|
+
C1: null,
|
|
17
|
+
C2: null,
|
|
18
|
+
C3: null,
|
|
19
|
+
DEFAULT: {}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", DEV3: "ME", USER: "USER"};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
3
|
+
* This file is generated following the conversion of
|
|
4
|
+
* [./node_modules/rgb-hex/index.js]{@link ./node_modules/rgb-hex/index.js}
|
|
5
|
+
*
|
|
6
|
+
**/
|
|
7
|
+
export default function rgbHex(red, green, blue, alpha) {
|
|
8
|
+
const isPercent = (red + (alpha || '')).toString().includes('%');
|
|
9
|
+
|
|
10
|
+
if (typeof red === 'string') {
|
|
11
|
+
[red, green, blue, alpha] = red.match(/(0?\.?\d{1,3})%?\b/g).map(component => Number(component));
|
|
12
|
+
} else if (alpha !== undefined) {
|
|
13
|
+
alpha = Number.parseFloat(alpha);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof red !== 'number' ||
|
|
17
|
+
typeof green !== 'number' ||
|
|
18
|
+
typeof blue !== 'number' ||
|
|
19
|
+
red > 255 ||
|
|
20
|
+
green > 255 ||
|
|
21
|
+
blue > 255
|
|
22
|
+
) {
|
|
23
|
+
throw new TypeError('Expected three numbers below 256');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof alpha === 'number') {
|
|
27
|
+
if (!isPercent && alpha >= 0 && alpha <= 1) {
|
|
28
|
+
alpha = Math.round(255 * alpha);
|
|
29
|
+
} else if (isPercent && alpha >= 0 && alpha <= 100) {
|
|
30
|
+
alpha = Math.round(255 * alpha / 100);
|
|
31
|
+
} else {
|
|
32
|
+
throw new TypeError(`Expected alpha value (${alpha}) as a fraction or percentage`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
alpha = (alpha | 1 << 8).toString(16).slice(1); // eslint-disable-line no-mixed-operators
|
|
36
|
+
} else {
|
|
37
|
+
alpha = '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// TODO: Remove this ignore comment.
|
|
41
|
+
// eslint-disable-next-line no-mixed-operators
|
|
42
|
+
return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1) + alpha;
|
|
43
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
3
|
+
* This file is generated following the conversion of
|
|
4
|
+
* [./node_modules/to-ansi/index.mjs]{@link ./node_modules/to-ansi/index.mjs}
|
|
5
|
+
*
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
9
|
+
* This file is generated following the conversion of
|
|
10
|
+
* [./index.cjs]{@link ./index.cjs}
|
|
11
|
+
*
|
|
12
|
+
**/
|
|
13
|
+
const COLOR_TYPE = {
|
|
14
|
+
Foreground: 38,
|
|
15
|
+
Background: 48,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const RESET = "\x1b[0m";
|
|
19
|
+
|
|
20
|
+
export const FONT_STYLE = {
|
|
21
|
+
Bold : "\x1b[1m",
|
|
22
|
+
Underline: "\x1b[4m",
|
|
23
|
+
Reversed : "\x1b[7m",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const STYLE = {
|
|
27
|
+
Bold : "\x1b[1m",
|
|
28
|
+
Underline: "\x1b[4m",
|
|
29
|
+
Reversed : "\x1b[7m",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @see [Code and original author]
|
|
34
|
+
* {@link https://stackoverflow.com/questions/15682537/ansi-color-specific-rgb-sequence-bash}
|
|
35
|
+
* @param red
|
|
36
|
+
* @param green
|
|
37
|
+
* @param blue
|
|
38
|
+
* @returns {number}
|
|
39
|
+
*/
|
|
40
|
+
export const rgbToAnsi256 = (red, green, blue) =>
|
|
41
|
+
{
|
|
42
|
+
if (red === green && green === blue)
|
|
43
|
+
{
|
|
44
|
+
if (red < 8)
|
|
45
|
+
{
|
|
46
|
+
return 16;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (red > 248)
|
|
50
|
+
{
|
|
51
|
+
return 231;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return 16
|
|
58
|
+
+ (36 * Math.round(red / 255 * 5))
|
|
59
|
+
+ (6 * Math.round(green / 255 * 5))
|
|
60
|
+
+ Math.round(blue / 255 * 5);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @see [Code and original author]
|
|
65
|
+
* {@link https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb/5624139#5624139}
|
|
66
|
+
* @param hex
|
|
67
|
+
* @returns {{red: number, green: number, blue: number}|null}
|
|
68
|
+
*/
|
|
69
|
+
export const hexToRgb = (hex) =>
|
|
70
|
+
{
|
|
71
|
+
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
72
|
+
hex = hex.replace(shorthandRegex, function (m, r, g, b)
|
|
73
|
+
{
|
|
74
|
+
return r + r + g + g + b + b;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
78
|
+
return result ? {
|
|
79
|
+
red : parseInt(result[1], 16),
|
|
80
|
+
blue : parseInt(result[2], 16),
|
|
81
|
+
green: parseInt(result[3], 16)
|
|
82
|
+
} : {};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const hue2rgb = function hue2rgb(p, q, t)
|
|
86
|
+
{
|
|
87
|
+
if (t < 0)
|
|
88
|
+
{
|
|
89
|
+
t += 1;
|
|
90
|
+
}
|
|
91
|
+
if (t > 1)
|
|
92
|
+
{
|
|
93
|
+
t -= 1;
|
|
94
|
+
}
|
|
95
|
+
if (t < 1 / 6)
|
|
96
|
+
{
|
|
97
|
+
return p + (q - p) * 6 * t;
|
|
98
|
+
}
|
|
99
|
+
if (t < 1 / 2)
|
|
100
|
+
{
|
|
101
|
+
return q;
|
|
102
|
+
}
|
|
103
|
+
if (t < 2 / 3)
|
|
104
|
+
{
|
|
105
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
106
|
+
}
|
|
107
|
+
return p;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts an HSL color value to RGB. Conversion formula
|
|
112
|
+
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
|
113
|
+
* Assumes h, s, and l are contained in the set [0, 1] and
|
|
114
|
+
* returns r, g, and b in the set [0, 255].
|
|
115
|
+
* @see [Original code and author] {@link https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion}
|
|
116
|
+
*
|
|
117
|
+
* @param {number} hue The hue
|
|
118
|
+
* @param {number} saturation The saturation
|
|
119
|
+
* @param {number} lightness The lightness
|
|
120
|
+
* @return {Array} The RGB representation
|
|
121
|
+
*/
|
|
122
|
+
const hslToRgb = ({hue, saturation, lightness}) =>
|
|
123
|
+
{
|
|
124
|
+
let r, g, b;
|
|
125
|
+
|
|
126
|
+
if (saturation === 0)
|
|
127
|
+
{
|
|
128
|
+
r = g = b = lightness; // achromatic
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
{
|
|
132
|
+
const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
|
|
133
|
+
const p = 2 * lightness - q;
|
|
134
|
+
r = hue2rgb(p, q, hue + 1 / 3);
|
|
135
|
+
g = hue2rgb(p, q, hue);
|
|
136
|
+
b = hue2rgb(p, q, hue - 1 / 3);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
red : Math.round(r * 255),
|
|
141
|
+
blue : Math.round(b * 255),
|
|
142
|
+
green: Math.round(g * 255)
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export function fromRgb ({red, blue, green}, isForeground = true)
|
|
147
|
+
{
|
|
148
|
+
if (red === undefined || blue === undefined || green === undefined)
|
|
149
|
+
{
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const code = rgbToAnsi256(red, blue, green);
|
|
154
|
+
|
|
155
|
+
let ground = isForeground ? COLOR_TYPE.Foreground : COLOR_TYPE.Background;
|
|
156
|
+
return `\x1b[${ground};5;` + code + "m ";
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function fromHexa (hexa, isForeground)
|
|
160
|
+
{
|
|
161
|
+
const {red, green, blue} = hexToRgb(hexa);
|
|
162
|
+
return fromRgb({red, green, blue}, isForeground);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function fromHsl ({hue, saturation, lightness}, isForeground)
|
|
166
|
+
{
|
|
167
|
+
const {red, green, blue} = hslToRgb({hue, saturation, lightness});
|
|
168
|
+
return fromRgb({red, green, blue}, isForeground);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function getTextFromAnsi(text, {
|
|
172
|
+
fg,
|
|
173
|
+
bg,
|
|
174
|
+
isUnderline = false,
|
|
175
|
+
isBold = false,
|
|
176
|
+
isReversed = false
|
|
177
|
+
})
|
|
178
|
+
{
|
|
179
|
+
let prefix = ""
|
|
180
|
+
if (fg)
|
|
181
|
+
{
|
|
182
|
+
prefix = prefix + fg;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (bg)
|
|
186
|
+
{
|
|
187
|
+
prefix = prefix + bg;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (isUnderline)
|
|
191
|
+
{
|
|
192
|
+
prefix = prefix + FONT_STYLE.Underline;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (isBold)
|
|
196
|
+
{
|
|
197
|
+
prefix = prefix + FONT_STYLE.Bold;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (isReversed)
|
|
201
|
+
{
|
|
202
|
+
prefix = prefix + FONT_STYLE.Reversed;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return prefix + text + RESET;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
export function getTextFromRgb (text, {
|
|
210
|
+
fg = {},
|
|
211
|
+
bg = {},
|
|
212
|
+
isUnderline = false,
|
|
213
|
+
isBold = false,
|
|
214
|
+
isReversed = false
|
|
215
|
+
})
|
|
216
|
+
{
|
|
217
|
+
if (fg)
|
|
218
|
+
{
|
|
219
|
+
fg = fromRgb({...fg});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (bg)
|
|
223
|
+
{
|
|
224
|
+
bg = fromRgb({...bg}, false);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return getTextFromAnsi(text,{fg, bg, isUnderline, isBold, isReversed});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function getTextFromHsl (text, {
|
|
231
|
+
fg = "",
|
|
232
|
+
bg = "",
|
|
233
|
+
isUnderline = false,
|
|
234
|
+
isBold = false,
|
|
235
|
+
isReversed = false
|
|
236
|
+
})
|
|
237
|
+
{
|
|
238
|
+
if (fg)
|
|
239
|
+
{
|
|
240
|
+
fg = fromHsl({...fg});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (bg)
|
|
244
|
+
{
|
|
245
|
+
bg = fromHsl({...bg}, false);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return getTextFromAnsi(text,{fg, bg, isUnderline, isBold, isReversed});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function getTextFromHex (text, {
|
|
252
|
+
fg = "",
|
|
253
|
+
bg = "",
|
|
254
|
+
isUnderline = false,
|
|
255
|
+
isBold = false,
|
|
256
|
+
isReversed = false
|
|
257
|
+
})
|
|
258
|
+
{
|
|
259
|
+
if (fg)
|
|
260
|
+
{
|
|
261
|
+
fg = fromHexa(fg);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (bg)
|
|
265
|
+
{
|
|
266
|
+
bg = fromHexa(bg, false);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return getTextFromAnsi(text,{fg, bg, isUnderline, isBold, isReversed});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export default {
|
|
273
|
+
fromRgb, fromHexa, fromHsl, getTextFromRgb, getTextFromHsl, getTextFromHex,
|
|
274
|
+
hexToRgb, rgbToAnsi256, hue2rgb, RESET, FONT_STYLE, STYLE
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* For the conversion with to-esm, the named export and the function to export must use the same identifier.
|
|
280
|
+
* Otherwise, the conversion will fail.
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|