@visulima/is-ansi-color-supported 1.1.0 → 1.2.0
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @visulima/is-ansi-color-supported [1.2.0](https://github.com/visulima/visulima/compare/@visulima/is-ansi-color-supported@1.1.0...@visulima/is-ansi-color-supported@1.2.0) (2024-02-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add detection of additional terminals, thanks [@dse](https://github.com/dse), [colors.js:issue [#42](https://github.com/visulima/visulima/issues/42)](https://github.com/DABH/colors.js/issues/42) ([d2f034d](https://github.com/visulima/visulima/commit/d2f034de2ea41bce4c09fe7a40d8e9aa8ad4401c))
|
|
7
|
+
|
|
1
8
|
## @visulima/is-ansi-color-supported [1.1.0](https://github.com/visulima/visulima/compare/@visulima/is-ansi-color-supported@1.0.0...@visulima/is-ansi-color-supported@1.1.0) (2024-01-31)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _=p=>{let t=p??globalThis,s=t.Deno!=null,o=t.process??t.Deno??{},a=o.argv??o.args??[],l=e=>{let R=a.indexOf("--"),T=a.findIndex(C=>e.test(C));return T!==-1&&(R===-1||T<R)},r={};try{r=s?o.env.toObject():o.env??{};}catch{}let c="FORCE_COLOR",O=c in r,n=r[c]?String(r[c]):void 0,f=Object.prototype.toString.call(n).slice(8,-1)==="String",i=0;if(n==="true"?i=1:n==="false"?i=0:f&&n.length===0?i=1:f&&n.length>0&&(i=Math.min(Number.parseInt(n,10),3)),"NO_COLOR"in r||O&&i===0||l(/^-{1,2}(no-color|no-colors|color=false|color=never)$/))return 0;if(l(/^-{1,2}(color=256)$/))return 2;if(l(/^-{1,2}(color=16m|color=full|color=truecolor)$/))return 3;if(l(/^-{1,2}(color|colors|color=true|color=always)$/))return 1;let u=i||0;if("TF_BUILD"in r&&"AGENT_NAME"in r)return 1;if(r.TERM==="dumb")return u;if((s?t.Deno.build.os:o.platform)==="win32")try{let e=(s?t.Deno.osRelease():o.os.release()).split(".");return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}catch{}if("CI"in r)return "GITHUB_ACTIONS"in r||"GITHUB_WORKFLOW"in r||"GITEA_ACTIONS"in r?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE","GITLAB_CI"].some(e=>e in r)||r.CI_NAME==="codeship"?1:u;if("TEAMCITY_VERSION"in r)return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if(r.COLORTERM==="truecolor"||r.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in r){let e=Number.parseInt((r.TERM_PROGRAM_VERSION??"").split(".")[0],10);if(r.TERM_PROGRAM==="iTerm.app")return e>=3?3:2;if(r.TERM_PROGRAM==="Apple_Terminal")return 2}return /-256(color)?$/i.test(r.TERM)?2:(s?t.Deno.isatty(1):o.stdout&&"isTTY"in o.stdout)&&/^screen|^tmux|^xterm|^vt[1-5]\d\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(r.TERM)||"COLORTERM"in r?1:u};
|
|
4
4
|
|
|
5
|
-
exports.isColorSupported =
|
|
5
|
+
exports.isColorSupported = _;
|
|
6
6
|
//# sourceMappingURL=out.js.map
|
|
7
7
|
//# sourceMappingURL=is-color-supported.server.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupported","mockThis","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version"],"mappings":"AAUO,IAAMA,EAAoBC,GAAsC,CAEnE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,GAAaf,EAASD,EAAM,KAAK,UAAU,EAAIE,EAAK,GAAM,QAAQ,GAAG,MAAM,GAAG,EAGpF,OAAI,OAAOc,EAAU,CAAC,CAAC,GAAK,IAAM,OAAOA,EAAU,CAAC,CAAC,GAAK,MAE/C,OAAOA,EAAU,CAAC,CAAC,GAAK,MAAS,EAAI,EAGzC,CACX,MAAQ,CAER,CAGJ,GAAI,OAAQP,EACR,MAAI,mBAAoBA,GAAe,oBAAqBA,GAAe,kBAAmBA,EACnF,EAIP,CAAC,SAAU,WAAY,WAAY,YAAa,YAAa,QAAS,WAAW,EAAE,KAAMQ,GAASA,KAAQR,CAAW,GACrHA,EAAY,UAAe,WAEpB,EAGJM,EAGX,GAAI,qBAAsBN,EAGtB,MAAO,gCAAgC,KAAKA,EAAY,gBAA6B,EAAI,EAAI,EAOjG,GAJIA,EAAY,YAAiB,aAI7BA,EAAY,OAAY,cACxB,MAAO,GAGX,GAAI,iBAAkBA,EAAa,CAE/B,IAAMS,EAAU,OAAO,UAAWT,EAAY,sBAAsC,IAAI,MAAM,GAAG,EAAE,CAAC,EAAa,EAAE,EAEnH,GAAIA,EAAY,eAAoB,YAChC,OAAOS,GAAW,EAAI,EAAI,EAG9B,GAAIT,EAAY,eAAoB,iBAChC,MAAO,EAEf,CAGA,MAAI,iBAAiB,KAAaA,EAAY,IAAO,EAC1C,GAIGR,EAASD,EAAM,KAAK,OAAO,CAAC,EAAIE,EAAK,QAAa,UAAWA,EAAK,SAEnE,
|
|
1
|
+
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupported","mockThis","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version"],"mappings":"AAUO,IAAMA,EAAoBC,GAAsC,CAEnE,IAAMC,EAAQD,GAAY,WAEpBE,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EAAM,MAA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,OAAOc,EAAU,CAAC,CAAC,GAAK,IAAM,OAAOA,EAAU,CAAC,CAAC,GAAK,MAE/C,OAAOA,EAAU,CAAC,CAAC,GAAK,MAAS,EAAI,EAGzC,CACX,MAAQ,CAER,CAGJ,GAAI,OAAQP,EACR,MAAI,mBAAoBA,GAAe,oBAAqBA,GAAe,kBAAmBA,EACnF,EAIP,CAAC,SAAU,WAAY,WAAY,YAAa,YAAa,QAAS,WAAW,EAAE,KAAMQ,GAASA,KAAQR,CAAW,GACrHA,EAAY,UAAe,WAEpB,EAGJM,EAGX,GAAI,qBAAsBN,EAGtB,MAAO,gCAAgC,KAAKA,EAAY,gBAA6B,EAAI,EAAI,EAOjG,GAJIA,EAAY,YAAiB,aAI7BA,EAAY,OAAY,cACxB,MAAO,GAGX,GAAI,iBAAkBA,EAAa,CAE/B,IAAMS,EAAU,OAAO,UAAWT,EAAY,sBAAsC,IAAI,MAAM,GAAG,EAAE,CAAC,EAAa,EAAE,EAEnH,GAAIA,EAAY,eAAoB,YAChC,OAAOS,GAAW,EAAI,EAAI,EAG9B,GAAIT,EAAY,eAAoB,iBAChC,MAAO,EAEf,CAGA,MAAI,iBAAiB,KAAaA,EAAY,IAAO,EAC1C,GAIGR,EAASD,EAAM,KAAK,OAAO,CAAC,EAAIE,EAAK,QAAa,UAAWA,EAAK,SAEnE,0EAA0E,KAAaO,EAAY,IAAO,GAInH,cAAeA,EACR,EAGJM,CACX","sourcesContent":["// Some of this code is taken from https://github.com/chalk/supports-color/blob/main/index.js\n// MIT License\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nimport type { ColorSupportLevel } from \"./types\";\n\n/**\n * @param {Object?} mockThis The mock object of globalThis, used by unit test only.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity,@typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any\nexport const isColorSupported = (mockThis?: any): ColorSupportLevel => {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const _this = mockThis ?? globalThis;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const isDeno = _this.Deno != null;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n const proc: Record<string, any> = _this.process ?? _this.Deno ?? {};\n // Node -> `argv`, Deno -> `args`\n const argv: string[] = (proc[\"argv\"] ?? proc[\"args\"] ?? []) as string[];\n\n /**\n * Detect whether flags exist with `-` or `--` prefix in command-line arguments.\n *\n * @param {RegExp} regex The RegEx to match all possible flags.\n * @return {boolean}\n */\n const oneOfFlags = (regex: RegExp): boolean => {\n const terminatorPosition = argv.indexOf(\"--\");\n\n const position = argv.findIndex((flag) => regex.test(flag));\n\n return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n };\n\n let environment: Record<string, string | undefined> = {};\n\n try {\n // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n environment = isDeno ? proc[\"env\"].toObject() : proc[\"env\"] ?? {};\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n\n const FORCE_COLOR = \"FORCE_COLOR\";\n const hasForceColor = FORCE_COLOR in environment;\n // eslint-disable-next-line security/detect-object-injection\n const forceColorValue = environment[FORCE_COLOR] ? String(environment[FORCE_COLOR]) : undefined;\n const forceColorValueIsString = Object.prototype.toString.call(forceColorValue).slice(8, -1) === \"String\";\n\n let forceColor: ColorSupportLevel = 0;\n\n if (forceColorValue === \"true\") {\n forceColor = 1;\n } else if (forceColorValue === \"false\") {\n forceColor = 0;\n } else if (forceColorValueIsString && (forceColorValue as string).length === 0) {\n forceColor = 1;\n } else if (forceColorValueIsString && (forceColorValue as string).length > 0) {\n forceColor = Math.min(Number.parseInt(forceColorValue as string, 10), 3) as ColorSupportLevel;\n }\n\n const isForceDisabled =\n // eslint-disable-next-line regexp/no-unused-capturing-group\n \"NO_COLOR\" in environment || (hasForceColor && forceColor === 0) || oneOfFlags(/^-{1,2}(no-color|no-colors|color=false|color=never)$/);\n\n if (isForceDisabled) {\n return 0;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=256)$/)) {\n return 2;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=16m|color=full|color=truecolor)$/)) {\n return 3;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n const isForceEnabled = oneOfFlags(/^-{1,2}(color|colors|color=true|color=always)$/);\n\n if (isForceEnabled) {\n return 1;\n }\n\n const minColorLevel = forceColor || 0;\n\n // Check for Azure DevOps pipelines.\n // Has to be above the `stream isTTY` check.\n if (\"TF_BUILD\" in environment && \"AGENT_NAME\" in environment) {\n return 1;\n }\n\n const isDumbTerminal: boolean = environment[\"TERM\"] === \"dumb\";\n\n if (isDumbTerminal) {\n return minColorLevel;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if ((isDeno ? _this.Deno.build.os : proc[\"platform\"]) === \"win32\") {\n try {\n // Deno requires the permission for the access to the operating system, use the `--allow-sys` flag: deno run --allow-sys ./app.js\n\n // Windows 10 build 10586 is the first Windows release that supports 256 colors.\n // Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const osRelease = (isDeno ? _this.Deno.osRelease() : proc[\"os\"].release()).split(\".\");\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return Number(osRelease[2]) >= 14_931 ? 3 : 2;\n }\n\n return 1;\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n }\n\n if (\"CI\" in environment) {\n if (\"GITHUB_ACTIONS\" in environment || \"GITHUB_WORKFLOW\" in environment || \"GITEA_ACTIONS\" in environment) {\n return 3;\n }\n\n if (\n [\"TRAVIS\", \"CIRCLECI\", \"APPVEYOR\", \"GITLAB_CI\", \"BUILDKITE\", \"DRONE\", \"GITLAB_CI\"].some((sign) => sign in environment) ||\n environment[\"CI_NAME\"] === \"codeship\"\n ) {\n return 1;\n }\n\n return minColorLevel;\n }\n\n if (\"TEAMCITY_VERSION\" in environment) {\n // https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingMessages\n // eslint-disable-next-line regexp/no-unused-capturing-group\n return /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(environment[\"TEAMCITY_VERSION\"] as string) ? 1 : 0;\n }\n\n if (environment[\"COLORTERM\"] === \"truecolor\") {\n return 3;\n }\n\n if (environment[\"TERM\"] === \"xterm-kitty\") {\n return 3;\n }\n\n if (\"TERM_PROGRAM\" in environment) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const version = Number.parseInt(((environment[\"TERM_PROGRAM_VERSION\"] as string) ?? \"\").split(\".\")[0] as string, 10);\n\n if (environment[\"TERM_PROGRAM\"] === \"iTerm.app\") {\n return version >= 3 ? 3 : 2;\n }\n\n if (environment[\"TERM_PROGRAM\"] === \"Apple_Terminal\") {\n return 2;\n }\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (/-256(color)?$/i.test(<string>environment[\"TERM\"])) {\n return 2;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const isTTY = isDeno ? _this.Deno.isatty(1) : proc[\"stdout\"] && \"isTTY\" in proc[\"stdout\"];\n\n if (isTTY && /^screen|^tmux|^xterm|^vt[1-5]\\d\\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(<string>environment[\"TERM\"])) {\n return 1;\n }\n\n if (\"COLORTERM\" in environment) {\n return 1;\n }\n\n return minColorLevel;\n};\n\n// eslint-disable-next-line import/no-unused-modules\nexport type { ColorSupportLevel } from \"./types\";\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var M=p=>{let t=p??globalThis,s=t.Deno!=null,o=t.process??t.Deno??{},a=o.argv??o.args??[],l=e=>{let R=a.indexOf("--"),T=a.findIndex(C=>e.test(C));return T!==-1&&(R===-1||T<R)},r={};try{r=s?o.env.toObject():o.env??{};}catch{}let c="FORCE_COLOR",O=c in r,n=r[c]?String(r[c]):void 0,f=Object.prototype.toString.call(n).slice(8,-1)==="String",i=0;if(n==="true"?i=1:n==="false"?i=0:f&&n.length===0?i=1:f&&n.length>0&&(i=Math.min(Number.parseInt(n,10),3)),"NO_COLOR"in r||O&&i===0||l(/^-{1,2}(no-color|no-colors|color=false|color=never)$/))return 0;if(l(/^-{1,2}(color=256)$/))return 2;if(l(/^-{1,2}(color=16m|color=full|color=truecolor)$/))return 3;if(l(/^-{1,2}(color|colors|color=true|color=always)$/))return 1;let u=i||0;if("TF_BUILD"in r&&"AGENT_NAME"in r)return 1;if(r.TERM==="dumb")return u;if((s?t.Deno.build.os:o.platform)==="win32")try{let e=(s?t.Deno.osRelease():o.os.release()).split(".");return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}catch{}if("CI"in r)return "GITHUB_ACTIONS"in r||"GITHUB_WORKFLOW"in r||"GITEA_ACTIONS"in r?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE","GITLAB_CI"].some(e=>e in r)||r.CI_NAME==="codeship"?1:u;if("TEAMCITY_VERSION"in r)return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if(r.COLORTERM==="truecolor"||r.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in r){let e=Number.parseInt((r.TERM_PROGRAM_VERSION??"").split(".")[0],10);if(r.TERM_PROGRAM==="iTerm.app")return e>=3?3:2;if(r.TERM_PROGRAM==="Apple_Terminal")return 2}return /-256(color)?$/i.test(r.TERM)?2:(s?t.Deno.isatty(1):o.stdout&&"isTTY"in o.stdout)&&/^screen|^xterm|^
|
|
1
|
+
var M=p=>{let t=p??globalThis,s=t.Deno!=null,o=t.process??t.Deno??{},a=o.argv??o.args??[],l=e=>{let R=a.indexOf("--"),T=a.findIndex(C=>e.test(C));return T!==-1&&(R===-1||T<R)},r={};try{r=s?o.env.toObject():o.env??{};}catch{}let c="FORCE_COLOR",O=c in r,n=r[c]?String(r[c]):void 0,f=Object.prototype.toString.call(n).slice(8,-1)==="String",i=0;if(n==="true"?i=1:n==="false"?i=0:f&&n.length===0?i=1:f&&n.length>0&&(i=Math.min(Number.parseInt(n,10),3)),"NO_COLOR"in r||O&&i===0||l(/^-{1,2}(no-color|no-colors|color=false|color=never)$/))return 0;if(l(/^-{1,2}(color=256)$/))return 2;if(l(/^-{1,2}(color=16m|color=full|color=truecolor)$/))return 3;if(l(/^-{1,2}(color|colors|color=true|color=always)$/))return 1;let u=i||0;if("TF_BUILD"in r&&"AGENT_NAME"in r)return 1;if(r.TERM==="dumb")return u;if((s?t.Deno.build.os:o.platform)==="win32")try{let e=(s?t.Deno.osRelease():o.os.release()).split(".");return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}catch{}if("CI"in r)return "GITHUB_ACTIONS"in r||"GITHUB_WORKFLOW"in r||"GITEA_ACTIONS"in r?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE","GITLAB_CI"].some(e=>e in r)||r.CI_NAME==="codeship"?1:u;if("TEAMCITY_VERSION"in r)return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if(r.COLORTERM==="truecolor"||r.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in r){let e=Number.parseInt((r.TERM_PROGRAM_VERSION??"").split(".")[0],10);if(r.TERM_PROGRAM==="iTerm.app")return e>=3?3:2;if(r.TERM_PROGRAM==="Apple_Terminal")return 2}return /-256(color)?$/i.test(r.TERM)?2:(s?t.Deno.isatty(1):o.stdout&&"isTTY"in o.stdout)&&/^screen|^tmux|^xterm|^vt[1-5]\d\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(r.TERM)||"COLORTERM"in r?1:u};
|
|
2
2
|
|
|
3
3
|
export { M as isColorSupported };
|
|
4
4
|
//# sourceMappingURL=out.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupported","mockThis","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version"],"mappings":"AAUO,IAAMA,EAAoBC,GAAsC,CAEnE,IAAMC,EAAQD,GAAY,WAEpBE,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EAAM,MAAQ,CAAC,EAE5DG,EAAkBD,EAAK,MAAWA,EAAK,MAAW,CAAC,EAQnDE,EAAcC,GAA2B,CAC3C,IAAMC,EAAqBH,EAAK,QAAQ,IAAI,EAEtCI,EAAWJ,EAAK,UAAWK,GAASH,EAAM,KAAKG,CAAI,CAAC,EAE1D,OAAOD,IAAa,KAAOD,IAAuB,IAAMC,EAAWD,EACvE,EAEIG,EAAkD,CAAC,EAEvD,GAAI,CAGAA,EAAcR,EAASC,EAAK,IAAO,SAAS,EAAIA,EAAK,KAAU,CAAC,CACpE,MAAQ,CAER,CAEA,IAAMQ,EAAc,cACdC,EAAgBD,KAAeD,EAE/BG,EAAkBH,EAAYC,CAAW,EAAI,OAAOD,EAAYC,CAAW,CAAC,EAAI,OAChFG,EAA0B,OAAO,UAAU,SAAS,KAAKD,CAAe,EAAE,MAAM,EAAG,EAAE,IAAM,SAE7FE,EAAgC,EAgBpC,GAdIF,IAAoB,OACpBE,EAAa,EACNF,IAAoB,QAC3BE,EAAa,EACND,GAA4BD,EAA2B,SAAW,EACzEE,EAAa,E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9B,GAAIT,EAAY,eAAoB,iBAChC,MAAO,EAEf,CAGA,MAAI,iBAAiB,KAAaA,EAAY,IAAO,EAC1C,GAIGR,EAASD,EAAM,KAAK,OAAO,CAAC,EAAIE,EAAK,QAAa,UAAWA,EAAK,SAEnE,
|
|
1
|
+
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupported","mockThis","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version"],"mappings":"AAUO,IAAMA,EAAoBC,GAAsC,CAEnE,IAAMC,EAAQD,GAAY,WAEpBE,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EAAM,MAAQ,CAAC,EAE5DG,EAAkBD,EAAK,MAAWA,EAAK,MAAW,CAAC,EAQnDE,EAAcC,GAA2B,CAC3C,IAAMC,EAAqBH,EAAK,QAAQ,IAAI,EAEtCI,EAAWJ,EAAK,UAAWK,GAASH,EAAM,KAAKG,CAAI,CAAC,EAE1D,OAAOD,IAAa,KAAOD,IAAuB,IAAMC,EAAWD,EACvE,EAEIG,EAAkD,CAAC,EAEvD,GAAI,CAGAA,EAAcR,EAASC,EAAK,IAAO,SAAS,EAAIA,EAAK,KAAU,CAAC,CACpE,MAAQ,CAER,CAEA,IAAMQ,EAAc,cACdC,EAAgBD,KAAeD,EAE/BG,EAAkBH,EAAYC,CAAW,EAAI,OAAOD,EAAYC,CAAW,CAAC,EAAI,OAChFG,EAA0B,OAAO,UAAU,SAAS,KAAKD,CAAe,EAAE,MAAM,EAAG,EAAE,IAAM,SAE7FE,EAAgC,EAgBpC,GAdIF,IAAoB,OACpBE,EAAa,EACNF,IAAoB,QAC3BE,EAAa,EACND,GAA4BD,EAA2B,SAAW,EACzEE,EAAa,EACND,GAA4BD,EAA2B,OAAS,IACvEE,EAAa,KAAK,IAAI,OAAO,SAASF,EAA2B,EAAE,EAAG,CAAC,G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,GAIGR,EAASD,EAAM,KAAK,OAAO,CAAC,EAAIE,EAAK,QAAa,UAAWA,EAAK,SAEnE,0EAA0E,KAAaO,EAAY,IAAO,GAInH,cAAeA,EACR,EAGJM,CACX","sourcesContent":["// Some of this code is taken from https://github.com/chalk/supports-color/blob/main/index.js\n// MIT License\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nimport type { ColorSupportLevel } from \"./types\";\n\n/**\n * @param {Object?} mockThis The mock object of globalThis, used by unit test only.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity,@typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any\nexport const isColorSupported = (mockThis?: any): ColorSupportLevel => {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const _this = mockThis ?? globalThis;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const isDeno = _this.Deno != null;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any\n const proc: Record<string, any> = _this.process ?? _this.Deno ?? {};\n // Node -> `argv`, Deno -> `args`\n const argv: string[] = (proc[\"argv\"] ?? proc[\"args\"] ?? []) as string[];\n\n /**\n * Detect whether flags exist with `-` or `--` prefix in command-line arguments.\n *\n * @param {RegExp} regex The RegEx to match all possible flags.\n * @return {boolean}\n */\n const oneOfFlags = (regex: RegExp): boolean => {\n const terminatorPosition = argv.indexOf(\"--\");\n\n const position = argv.findIndex((flag) => regex.test(flag));\n\n return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n };\n\n let environment: Record<string, string | undefined> = {};\n\n try {\n // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n environment = isDeno ? proc[\"env\"].toObject() : proc[\"env\"] ?? {};\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n\n const FORCE_COLOR = \"FORCE_COLOR\";\n const hasForceColor = FORCE_COLOR in environment;\n // eslint-disable-next-line security/detect-object-injection\n const forceColorValue = environment[FORCE_COLOR] ? String(environment[FORCE_COLOR]) : undefined;\n const forceColorValueIsString = Object.prototype.toString.call(forceColorValue).slice(8, -1) === \"String\";\n\n let forceColor: ColorSupportLevel = 0;\n\n if (forceColorValue === \"true\") {\n forceColor = 1;\n } else if (forceColorValue === \"false\") {\n forceColor = 0;\n } else if (forceColorValueIsString && (forceColorValue as string).length === 0) {\n forceColor = 1;\n } else if (forceColorValueIsString && (forceColorValue as string).length > 0) {\n forceColor = Math.min(Number.parseInt(forceColorValue as string, 10), 3) as ColorSupportLevel;\n }\n\n const isForceDisabled =\n // eslint-disable-next-line regexp/no-unused-capturing-group\n \"NO_COLOR\" in environment || (hasForceColor && forceColor === 0) || oneOfFlags(/^-{1,2}(no-color|no-colors|color=false|color=never)$/);\n\n if (isForceDisabled) {\n return 0;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=256)$/)) {\n return 2;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=16m|color=full|color=truecolor)$/)) {\n return 3;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n const isForceEnabled = oneOfFlags(/^-{1,2}(color|colors|color=true|color=always)$/);\n\n if (isForceEnabled) {\n return 1;\n }\n\n const minColorLevel = forceColor || 0;\n\n // Check for Azure DevOps pipelines.\n // Has to be above the `stream isTTY` check.\n if (\"TF_BUILD\" in environment && \"AGENT_NAME\" in environment) {\n return 1;\n }\n\n const isDumbTerminal: boolean = environment[\"TERM\"] === \"dumb\";\n\n if (isDumbTerminal) {\n return minColorLevel;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if ((isDeno ? _this.Deno.build.os : proc[\"platform\"]) === \"win32\") {\n try {\n // Deno requires the permission for the access to the operating system, use the `--allow-sys` flag: deno run --allow-sys ./app.js\n\n // Windows 10 build 10586 is the first Windows release that supports 256 colors.\n // Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const osRelease = (isDeno ? _this.Deno.osRelease() : proc[\"os\"].release()).split(\".\");\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return Number(osRelease[2]) >= 14_931 ? 3 : 2;\n }\n\n return 1;\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n }\n\n if (\"CI\" in environment) {\n if (\"GITHUB_ACTIONS\" in environment || \"GITHUB_WORKFLOW\" in environment || \"GITEA_ACTIONS\" in environment) {\n return 3;\n }\n\n if (\n [\"TRAVIS\", \"CIRCLECI\", \"APPVEYOR\", \"GITLAB_CI\", \"BUILDKITE\", \"DRONE\", \"GITLAB_CI\"].some((sign) => sign in environment) ||\n environment[\"CI_NAME\"] === \"codeship\"\n ) {\n return 1;\n }\n\n return minColorLevel;\n }\n\n if (\"TEAMCITY_VERSION\" in environment) {\n // https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingMessages\n // eslint-disable-next-line regexp/no-unused-capturing-group\n return /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(environment[\"TEAMCITY_VERSION\"] as string) ? 1 : 0;\n }\n\n if (environment[\"COLORTERM\"] === \"truecolor\") {\n return 3;\n }\n\n if (environment[\"TERM\"] === \"xterm-kitty\") {\n return 3;\n }\n\n if (\"TERM_PROGRAM\" in environment) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const version = Number.parseInt(((environment[\"TERM_PROGRAM_VERSION\"] as string) ?? \"\").split(\".\")[0] as string, 10);\n\n if (environment[\"TERM_PROGRAM\"] === \"iTerm.app\") {\n return version >= 3 ? 3 : 2;\n }\n\n if (environment[\"TERM_PROGRAM\"] === \"Apple_Terminal\") {\n return 2;\n }\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (/-256(color)?$/i.test(<string>environment[\"TERM\"])) {\n return 2;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const isTTY = isDeno ? _this.Deno.isatty(1) : proc[\"stdout\"] && \"isTTY\" in proc[\"stdout\"];\n\n if (isTTY && /^screen|^tmux|^xterm|^vt[1-5]\\d\\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(<string>environment[\"TERM\"])) {\n return 1;\n }\n\n if (\"COLORTERM\" in environment) {\n return 1;\n }\n\n return minColorLevel;\n};\n\n// eslint-disable-next-line import/no-unused-modules\nexport type { ColorSupportLevel } from \"./types\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/is-ansi-color-supported",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Detect whether a terminal or browser supports ansi colors.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"@rushstack/eslint-plugin-security": "^0.8.0",
|
|
104
104
|
"@secretlint/secretlint-rule-preset-recommend": "^8.1.1",
|
|
105
105
|
"@types/micromatch": "^4.0.6",
|
|
106
|
-
"@types/node": "18.18.
|
|
106
|
+
"@types/node": "18.18.14",
|
|
107
107
|
"@vitest/coverage-v8": "^1.2.2",
|
|
108
108
|
"@vitest/ui": "^1.2.2",
|
|
109
109
|
"cross-env": "^7.0.3",
|
|
@@ -112,14 +112,14 @@
|
|
|
112
112
|
"eslint-plugin-etc": "^2.0.3",
|
|
113
113
|
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
|
|
114
114
|
"eslint-plugin-mdx": "^3.1.5",
|
|
115
|
-
"eslint-plugin-vitest": "^0.3.
|
|
115
|
+
"eslint-plugin-vitest": "^0.3.22",
|
|
116
116
|
"eslint-plugin-vitest-globals": "^1.4.0",
|
|
117
|
-
"prettier": "^3.2.
|
|
117
|
+
"prettier": "^3.2.5",
|
|
118
118
|
"rimraf": "^5.0.5",
|
|
119
119
|
"secretlint": "8.1.1",
|
|
120
|
-
"semantic-release": "^23.0.
|
|
120
|
+
"semantic-release": "^23.0.2",
|
|
121
121
|
"sort-package-json": "^2.7.0",
|
|
122
|
-
"tsup": "^8.0.
|
|
122
|
+
"tsup": "^8.0.2",
|
|
123
123
|
"typescript": "^5.3.3",
|
|
124
124
|
"vitest": "^1.2.2"
|
|
125
125
|
},
|