gloomberb 0.20.5 → 0.20.7
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +2 -1
- package/src/api-client/data.ts +10 -2
- package/src/api-client/fund-facts.ts +20 -4
- package/src/api-client/hk-tenders.ts +59 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/socket.ts +4 -4
- package/src/api-client/types/econ.ts +20 -2
- package/src/app.tsx +18 -13
- package/src/architecture/floating-promise-allowlist.json +313 -0
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/commands/market.ts +197 -57
- package/src/cli/commands/news-search.ts +22 -7
- package/src/cli/commands/overview.ts +12 -6
- package/src/cli/commands/search.ts +19 -3
- package/src/cli/commands/ticker.ts +3 -1
- package/src/cli/desktop-pane-shot.ts +61 -0
- package/src/cli/early-command.ts +2 -0
- package/src/cli/errors.ts +10 -1
- package/src/cli/fx-forward.ts +76 -12
- package/src/cli/fx-pair.ts +1 -1
- package/src/cli/fx-quote-rate.ts +23 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/index-roots.ts +5 -4
- package/src/cli/index.ts +40 -3
- package/src/cli/known-gaps.ts +11 -8
- package/src/cli/listing-arg.ts +6 -4
- package/src/cli/options.ts +52 -3
- package/src/cli/output-file.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +15 -0
- package/src/cli/pane-functions/dom.ts +4 -4
- package/src/cli/pane-functions/freshness.ts +38 -5
- package/src/cli/pane-functions/function-help.ts +4 -4
- package/src/cli/pane-functions/headless.ts +9 -4
- package/src/cli/pane-functions/index.ts +6 -4
- package/src/cli/pane-functions/resolver.ts +2 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +16 -4
- package/src/cli/quote-answer.ts +57 -1
- package/src/cli/result.ts +38 -2
- package/src/cli/spreadsheet-hint.ts +7 -3
- package/src/cli/treasury-yields.ts +5 -3
- package/src/components/chart/composite/legend.tsx +40 -2
- package/src/components/command-bar/workflow/tickers.ts +2 -2
- package/src/components/data-table/view.tsx +9 -2
- package/src/components/ui/data-table/opentui/index.tsx +11 -4
- package/src/components/ui/data-table/opentui/model.ts +8 -6
- package/src/components/ui/data-table/types.ts +6 -1
- package/src/components/ui/table-layout.ts +38 -1
- package/src/docs/snapshot.json +58 -19
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/market-data/market/change-basis.ts +57 -12
- package/src/market-data/market/dated-previous-close.ts +184 -10
- package/src/market-data/market/freshness.ts +18 -6
- package/src/market-data/market/status.ts +9 -1
- package/src/market-data/published-nse-sessions.ts +16 -1
- package/src/market-data/quotes/contributions.ts +2 -0
- package/src/market-data/quotes/freshness.ts +15 -0
- package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
- package/src/plugins/builtin/alerts/alert-engine.ts +15 -0
- package/src/plugins/builtin/alerts/cli.ts +22 -9
- package/src/plugins/builtin/alerts/headless.ts +1 -1
- package/src/plugins/builtin/alerts/index.tsx +5 -1
- package/src/plugins/builtin/alerts/metric-command.ts +1 -1
- package/src/plugins/builtin/alerts/metric-data.ts +15 -2
- package/src/plugins/builtin/backtest/headless.ts +1 -1
- package/src/plugins/builtin/cds/model.ts +0 -6
- package/src/plugins/builtin/chart-composer/formula.ts +16 -3
- package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/presets.ts +1 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +20 -7
- package/src/plugins/builtin/credit-boards/client.ts +8 -0
- package/src/plugins/builtin/credit-boards/headless.ts +4 -1
- package/src/plugins/builtin/credit-boards/model.ts +58 -4
- package/src/plugins/builtin/credit-boards/series.ts +63 -6
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +3 -2
- package/src/plugins/builtin/credit-conditions/headless.ts +24 -6
- package/src/plugins/builtin/credit-conditions/index.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/model.ts +12 -6
- package/src/plugins/builtin/credit-conditions/series.ts +2 -1
- package/src/plugins/builtin/econ/calendar-model.ts +41 -7
- package/src/plugins/builtin/econ/calendar-source.ts +7 -1
- package/src/plugins/builtin/econ/index.tsx +41 -8
- package/src/plugins/builtin/econ/types.ts +3 -0
- package/src/plugins/builtin/fixed-income/index.tsx +2 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
- package/src/plugins/builtin/help/keybindings-editor.tsx +6 -2
- package/src/plugins/builtin/holders/fund-holders.ts +22 -1
- package/src/plugins/builtin/holders/headless.ts +5 -4
- package/src/plugins/builtin/holders/pane.tsx +7 -3
- package/src/plugins/builtin/holders/report-header.ts +23 -0
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/members/headless.ts +2 -0
- package/src/plugins/builtin/members/model.ts +10 -8
- package/src/plugins/builtin/members/pane.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +5 -2
- package/src/plugins/builtin/portfolio-list/cli/render.ts +86 -26
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
- package/src/plugins/builtin/portfolio-list/headless.ts +2 -1
- package/src/plugins/builtin/portfolio-list/income.ts +46 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +16 -6
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -4
- package/src/plugins/builtin/portfolio-list/use-throttled-ticker-order.ts +40 -3
- package/src/plugins/builtin/research/headless-schema.ts +4 -3
- package/src/plugins/builtin/research/relative-valuation-columns.ts +145 -47
- package/src/plugins/builtin/research/relative-valuation-currency.ts +31 -0
- package/src/plugins/builtin/research/relative-valuation-headless.ts +25 -8
- package/src/plugins/builtin/research/relative-valuation-model.ts +40 -9
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +3 -2
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -2
- package/src/plugins/builtin/sec/fund-facts.ts +25 -5
- package/src/plugins/builtin/shared/report-freshness.ts +15 -6
- package/src/plugins/builtin/supply-chain/model.ts +18 -6
- package/src/plugins/builtin/thirteenf/api.ts +47 -4
- package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +8 -7
- package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +8 -5
- package/src/plugins/builtin/ticker-detail/financials/model.ts +6 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/headless.ts +6 -4
- package/src/plugins/builtin/treasury-auctions/cache.ts +36 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +42 -4
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +126 -0
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +347 -0
- package/src/plugins/builtin/treasury-auctions/hk.ts +363 -0
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -1
- package/src/plugins/builtin/treasury-auctions/model.ts +16 -8
- package/src/plugins/builtin/treasury-auctions/pane.tsx +45 -21
- package/src/portfolio/collection-name.ts +22 -0
- package/src/portfolio/column-values.ts +3 -0
- package/src/portfolio/valuation-basis.ts +23 -1
- package/src/renderers/dom/data-table/frozen-column.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +27 -9
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +27 -24
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +3 -3
- package/src/renderers/electrobun/bun/desktop/snapshot-commit.ts +77 -0
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +3 -0
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +3 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +9 -5
- package/src/sources/provider-router/cache.ts +3 -1
- package/src/state/hooks/quote-streaming.ts +14 -6
- package/src/sync/controller.ts +17 -2
- package/src/sync/other-window-tabs.ts +32 -1
- package/src/sync/react.ts +4 -4
- package/src/tickers/instrument-kind.ts +22 -1
- package/src/tickers/search/index.ts +5 -0
- package/src/tickers/terminal-codes.ts +17 -5
- package/src/time-series/bar-spacing.ts +33 -0
- package/src/time-series/base-series.ts +21 -3
- package/src/time-series/chart-bounds.ts +31 -0
- package/src/time-series/field-catalog.ts +17 -0
- package/src/time-series/fundamentals/current-valuation.ts +244 -0
- package/src/time-series/fundamentals/historical-valuation.ts +99 -0
- package/src/time-series/fundamentals/metric-ids.ts +61 -0
- package/src/time-series/fundamentals/period-points.ts +104 -0
- package/src/time-series/fundamentals/quarterly-ttm.ts +220 -0
- package/src/time-series/fundamentals/series.ts +164 -0
- package/src/time-series/fundamentals/source-statements.ts +177 -0
- package/src/time-series/fundamentals/statement-fields.ts +154 -0
- package/src/time-series/fundamentals/statement-merge.ts +124 -0
- package/src/time-series/fundamentals/statement.ts +114 -0
- package/src/time-series/fundamentals/valuation-multiples.ts +50 -0
- package/src/time-series/fundamentals.ts +18 -1275
- package/src/time-series/ice-credit.ts +32 -6
- package/src/time-series/resolve.ts +9 -5
- package/src/time-series/session-bar.ts +78 -9
- package/src/time-series/studies/formula.ts +53 -10
- package/src/time-series/studies/pair.ts +18 -7
- package/src/time-series/studies/units.ts +49 -2
- package/src/time-series/types.ts +12 -0
- package/src/types/desktop-window.ts +2 -0
- package/src/types/financials.ts +15 -0
- package/src/types/headless.ts +8 -0
- package/src/utils/cli-output.ts +6 -3
- package/src/utils/debug-log.ts +29 -0
- package/src/utils/ebitda.ts +128 -0
- package/src/utils/format.ts +1 -1
- package/src/utils/shell-word.ts +13 -0
package/src/utils/debug-log.ts
CHANGED
|
@@ -10,6 +10,35 @@ export interface LogEntry {
|
|
|
10
10
|
data?: unknown;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/** How many items of a long list a log entry keeps; the rest is only counted. */
|
|
14
|
+
const LOG_LIST_PREVIEW_LENGTH = 5;
|
|
15
|
+
|
|
16
|
+
export interface ListPreview<T> {
|
|
17
|
+
count: number;
|
|
18
|
+
first: T[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A long list as its length and first few items. The log keeps each entry's
|
|
23
|
+
* data for its 5,000 entries, so one that names every row of a 300-row list
|
|
24
|
+
* holds those names for as long as the entry lives.
|
|
25
|
+
*/
|
|
26
|
+
export function previewList<T, R = T>(
|
|
27
|
+
items: readonly T[],
|
|
28
|
+
map: (item: T) => R = (item) => item as unknown as R,
|
|
29
|
+
): ListPreview<R> {
|
|
30
|
+
return { count: items.length, first: items.slice(0, LOG_LIST_PREVIEW_LENGTH).map(map) };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `data` with each list longer than the preview replaced by its length and first items. */
|
|
34
|
+
export function previewLongLists(data: Record<string, unknown>): Record<string, unknown> {
|
|
35
|
+
const preview: Record<string, unknown> = {};
|
|
36
|
+
for (const [key, value] of Object.entries(data)) {
|
|
37
|
+
preview[key] = Array.isArray(value) && value.length > LOG_LIST_PREVIEW_LENGTH ? previewList(value) : value;
|
|
38
|
+
}
|
|
39
|
+
return preview;
|
|
40
|
+
}
|
|
41
|
+
|
|
13
42
|
type LogListener = (entry: LogEntry) => void;
|
|
14
43
|
type ConsoleMethod = (...args: unknown[]) => void;
|
|
15
44
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { FinancialStatement } from "../types/financials";
|
|
2
|
+
import { completeAvailability, statementFieldAvailability } from "./financial-statements";
|
|
3
|
+
|
|
4
|
+
const finite = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
|
|
5
|
+
|
|
6
|
+
type DepreciationField = "depreciationAndAmortization" | "depreciationAmortizationDepletion";
|
|
7
|
+
|
|
8
|
+
/** The row's D&A: the cash flow statement's line, or D&A with depletion where only that is reported. */
|
|
9
|
+
function depreciation(row: FinancialStatement): { value: number; field: DepreciationField } | null {
|
|
10
|
+
for (const field of ["depreciationAndAmortization", "depreciationAmortizationDepletion"] as const) {
|
|
11
|
+
const value = row[field];
|
|
12
|
+
// An add-back: some sources sign it as the cash flow line, others as the expense.
|
|
13
|
+
if (finite(value)) return { value: Math.abs(value), field };
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Operating income, and how it was read when the row does not report it: the lines it was derived from. */
|
|
19
|
+
interface OperatingIncome {
|
|
20
|
+
value: number;
|
|
21
|
+
/** Null where the row reports operating income; else what it was derived as ("pretax income + interest expense - other income"). */
|
|
22
|
+
basis: string | null;
|
|
23
|
+
fields: readonly (keyof FinancialStatement)[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The row's operating income: the reported line, or, where a row lacks it (an
|
|
28
|
+
* energy major's quarter filed without one), derived from the lines it
|
|
29
|
+
* carries: revenue less total expenses, revenue less cost of revenue and
|
|
30
|
+
* operating expenses, else pretax income (or net income with its income tax
|
|
31
|
+
* added back) with interest expense added back and non-operating items taken
|
|
32
|
+
* out, as far as the row carries them. On Exxon Mobil's 2025 year each gives
|
|
33
|
+
* the 33.94B it reported.
|
|
34
|
+
*/
|
|
35
|
+
function operatingIncome(row: FinancialStatement, derive: boolean): OperatingIncome | null {
|
|
36
|
+
if (finite(row.operatingIncome)) return { value: row.operatingIncome, basis: null, fields: ["operatingIncome"] };
|
|
37
|
+
if (!derive) return null;
|
|
38
|
+
if (finite(row.totalRevenue) && finite(row.totalExpenses)) {
|
|
39
|
+
return { value: row.totalRevenue - row.totalExpenses, basis: "revenue less total expenses", fields: ["totalRevenue", "totalExpenses"] };
|
|
40
|
+
}
|
|
41
|
+
if (finite(row.totalRevenue) && finite(row.costOfRevenue) && finite(row.operatingExpense)) {
|
|
42
|
+
return {
|
|
43
|
+
value: row.totalRevenue - row.costOfRevenue - row.operatingExpense,
|
|
44
|
+
basis: "revenue less cost of revenue and operating expenses",
|
|
45
|
+
fields: ["totalRevenue", "costOfRevenue", "operatingExpense"],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const pretax = pretaxIncome(row);
|
|
49
|
+
if (!pretax) return null;
|
|
50
|
+
const interest = finite(row.interestExpense) ? Math.abs(row.interestExpense) : null;
|
|
51
|
+
// Other income and expense is every non-operating line together; the other non-operating line alone is part of it.
|
|
52
|
+
const nonOperating = finite(row.otherIncomeExpense) ? { value: row.otherIncomeExpense, field: "otherIncomeExpense" as const }
|
|
53
|
+
: finite(row.otherNonOperatingIncomeExpenses) ? { value: row.otherNonOperatingIncomeExpenses, field: "otherNonOperatingIncomeExpenses" as const }
|
|
54
|
+
: null;
|
|
55
|
+
return {
|
|
56
|
+
value: pretax.value + (interest ?? 0) - (nonOperating?.value ?? 0),
|
|
57
|
+
basis: [pretax.basis, ...interest !== null ? ["+ interest expense"] : [], ...nonOperating ? ["- non-operating items"] : []].join(" "),
|
|
58
|
+
fields: [...pretax.fields, ...interest !== null ? ["interestExpense" as const] : [], ...nonOperating ? [nonOperating.field] : []],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Pretax income as reported, or as net income (with minority interests) plus its income tax (Chevron's quarters file no pretax line). */
|
|
63
|
+
function pretaxIncome(row: FinancialStatement): { value: number; basis: string; fields: readonly (keyof FinancialStatement)[] } | null {
|
|
64
|
+
if (finite(row.pretaxIncome)) return { value: row.pretaxIncome, basis: "pretax income", fields: ["pretaxIncome"] };
|
|
65
|
+
if (!finite(row.taxProvision)) return null;
|
|
66
|
+
const income = finite(row.netIncomeIncludingNoncontrollingInterests) ? "netIncomeIncludingNoncontrollingInterests" as const
|
|
67
|
+
: finite(row.netIncome) ? "netIncome" as const : null;
|
|
68
|
+
return income ? { value: row[income]! + row.taxProvision, basis: "net income + income tax", fields: [income, "taxProvision"] } : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Whether a company's statements carry no EBITDA that means anything: a bank's
|
|
73
|
+
* or an insurer's interest and claims are its operations, so operating income
|
|
74
|
+
* is not derived for it and an EV over its EBITDA reads N/M.
|
|
75
|
+
*/
|
|
76
|
+
export function isBankOrInsurerIndustry(industry: string | null | undefined): boolean {
|
|
77
|
+
return /\b(banks?|insurance|insurers?|reinsurance)\b/i.test(industry ?? "");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** What an EV/EBITDA reads for a bank or an insurer (isBankOrInsurerIndustry). */
|
|
81
|
+
export const BANK_OR_INSURER_EBITDA = "not meaningful for banks and insurers";
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* EBITDA as the glossary defines it and sell-side comps read it: operating
|
|
85
|
+
* income with D&A added back. Null when the row lacks either; a source's own
|
|
86
|
+
* EBITDA line can carry non-operating income and is never used in its place.
|
|
87
|
+
*/
|
|
88
|
+
function statementEbitda(row: FinancialStatement, derive: boolean): { value: number; income: OperatingIncome; amortization: { value: number; field: DepreciationField } } | null {
|
|
89
|
+
const amortization = depreciation(row);
|
|
90
|
+
const income = operatingIncome(row, derive);
|
|
91
|
+
return income && amortization ? { value: income.value + amortization.value, income, amortization } : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whether the row's EBITDA is missing for want of D&A beside a reported operating income, which a cell says. */
|
|
95
|
+
export function ebitdaLacksDepreciation(row: FinancialStatement | null | undefined): boolean {
|
|
96
|
+
return !!row && !finite(row.ebitda) && finite(row.operatingIncome) && !depreciation(row);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* How the row's EBITDA read its operating income where the row reports none:
|
|
101
|
+
* `pretax income + interest expense - non-operating items`. Null where it was
|
|
102
|
+
* reported, or where the row has no EBITDA.
|
|
103
|
+
*/
|
|
104
|
+
export function ebitdaOperatingIncomeBasis(row: FinancialStatement | null | undefined): string | null {
|
|
105
|
+
if (!row || !finite(row.ebitda) || finite(row.operatingIncome)) return null;
|
|
106
|
+
return operatingIncome(row, true)?.basis ?? null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The row with `ebitda` on that definition, dated by the later of its inputs:
|
|
111
|
+
* the source's figure is dropped, and a row without D&A has none. `derive`
|
|
112
|
+
* false (a bank's or an insurer's rows) reads reported operating income alone.
|
|
113
|
+
*/
|
|
114
|
+
export function withStatementEbitda<T extends FinancialStatement>(row: T, derive = true): T {
|
|
115
|
+
const ebitda = statementEbitda(row, derive);
|
|
116
|
+
const value = ebitda?.value ?? null;
|
|
117
|
+
const availableAt = ebitda
|
|
118
|
+
? completeAvailability([...ebitda.income.fields, ebitda.amortization.field].map((field) => statementFieldAvailability(row, field)))
|
|
119
|
+
: undefined;
|
|
120
|
+
if (row.ebitda === (value ?? undefined) && (!row.fieldAvailability || row.fieldAvailability.ebitda === availableAt)) return row;
|
|
121
|
+
const { ebitda: _source, ...rest } = row;
|
|
122
|
+
const next = (value === null ? rest : { ...rest, ebitda: value }) as T;
|
|
123
|
+
if (row.fieldAvailability) {
|
|
124
|
+
const { ebitda: _dated, ...fieldAvailability } = row.fieldAvailability;
|
|
125
|
+
next.fieldAvailability = availableAt ? { ...fieldAvailability, ebitda: availableAt } : fieldAvailability;
|
|
126
|
+
}
|
|
127
|
+
return next;
|
|
128
|
+
}
|
package/src/utils/format.ts
CHANGED
|
@@ -353,7 +353,7 @@ export function displayWidth(value: string): number {
|
|
|
353
353
|
return segmentGraphemes(value).reduce((total, segment) => total + graphemeWidth(segment), 0);
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
function truncateToWidth(value: string, width: number): string {
|
|
356
|
+
export function truncateToWidth(value: string, width: number): string {
|
|
357
357
|
if (width <= 0) return "";
|
|
358
358
|
if (SINGLE_WIDTH_ASCII_RE.test(value)) return value.slice(0, width);
|
|
359
359
|
let output = "";
|
package/src/utils/shell-word.ts
CHANGED
|
@@ -6,3 +6,16 @@
|
|
|
6
6
|
export function shellWord(word: string): string {
|
|
7
7
|
return /^[\p{L}\p{N}._:@%+,/][\p{L}\p{N}._:@%+,/=-]*$/u.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A word of a command the CLI suggests, which may be run in cmd.exe or
|
|
12
|
+
* PowerShell as well as a POSIX shell: as written when nothing in it is
|
|
13
|
+
* special (`NVDA`, `SAN:EPA`), else in double quotes, which all three read as
|
|
14
|
+
* typed (`"^SPX"`, `"Main Portfolio"`). cmd.exe reads `^` as its escape and
|
|
15
|
+
* dropped it, so `gloom quote ^SPX` asked for SPX there. A word with a
|
|
16
|
+
* character double quotes would expand is quoted as `shellWord` quotes it.
|
|
17
|
+
*/
|
|
18
|
+
export function commandWord(word: string): string {
|
|
19
|
+
if (/^[\p{L}\p{N}._:@%+,/][\p{L}\p{N}._:@%+,/=-]*$/u.test(word)) return word;
|
|
20
|
+
return /["$`!%\\]/.test(word) ? shellWord(word) : `"${word}"`;
|
|
21
|
+
}
|