Skip to content

Commit

Permalink
fix(chart): belatedly promote to stable ("chart" vs "_chart")
Browse files Browse the repository at this point in the history
Fix some typescript and eslint warnings.
  • Loading branch information
gadicc committed Sep 18, 2023
1 parent fd5c873 commit 28ba479
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/yahoo-finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import yahooFinance from "../dist/esm/src/index-node.js";
const moduleNames = Object.keys(yahooFinance).filter((n) => !n.startsWith("_"));
moduleNames.push("_chart"); // modules in development
// moduleNames.push("_chart"); // modules in development

const node = process.argv[0];
const script = process.argv[1];
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const result = await yahooFinance.module(query, queryOpts, moduleOpts);
## Modules

1. ~[autoc](./modules/autoc.md)~ - decomissioned, use [search](./modules/search.md) instead.
1. [_chart](./modules/chart.md) - chart, like historical on steroids.
1. [chart](./modules/chart.md) - chart, like historical on steroids.
1. [historical](./modules/historical.md) - historical market prices.
1. [quote](./modules/quote.md) - essential symbol info.
1. [quoteSummary](./modules/quoteSummary.md) - comprehensive symbol info.
Expand Down
13 changes: 4 additions & 9 deletions docs/modules/chart.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# _chart

WARNING: the `chart` module is still in development; as such, it is currently
prefixed with an underscore (`_`), i.e. as `_chart`, to reflect that the API
is not final and may still change. Until this module is available as `chart`
(without the underscore), you should expect that package upgrades MAY break.
# chart

## Usage:

Expand All @@ -12,7 +7,7 @@ import yahooFinance from 'yahoo-finance2';

const query = 'AAPL';
const queryOptions = { period1: '2021-05-08', /* ... */ };
const result = await yahooFinance._chart(query, queryOptions);
const result = await yahooFinance.chart(query, queryOptions);

{
meta: {
Expand Down Expand Up @@ -100,7 +95,7 @@ libraries might actually prefer the original format, which you can get with

const query = 'AAPL';
const queryOptions = { period1: '2021-05-08', return: "object", /* ... */ };
const result = await yahooFinance._chart(query, queryOptions);
const result = await yahooFinance.chart(query, queryOptions);

{
meta: { /* same format as previous example */ },
Expand Down Expand Up @@ -152,7 +147,7 @@ const result = await yahooFinance._chart(query, queryOptions);
## API

```js
await yahooFinance._chart(query, queryOptions, moduleOptions);
await yahooFinance.chart(query, queryOptions, moduleOptions);
```

### Query term
Expand Down
3 changes: 2 additions & 1 deletion src/index-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { disallowAdditionalProps } from "./lib/validateAndCoerceTypes.js";

// modules
import autoc from "./modules/autoc.js";
import _chart from "./modules/chart.js";
import chart, { _chart } from "./modules/chart.js";
import historical from "./modules/historical.js";
import insights from "./modules/insights.js";
import optionsModule from "./modules/options.js";
Expand Down Expand Up @@ -36,6 +36,7 @@ export default {

// modules,
autoc,
chart,
_chart,
historical,
insights,
Expand Down
22 changes: 11 additions & 11 deletions src/modules/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,31 @@ export interface ChartOptionsWithReturnObject extends ChartOptions {

/* --- array input, typed output, honor "return" param --- */

export default function _chart(
// TODO: make this a deprecration passthrough
export const _chart = chart;

export default function chart(
this: ModuleThis,
symbol: string,
queryOptionsOverrides: ChartOptionsWithReturnObject,
moduleOptions?: ModuleOptionsWithValidateTrue
): Promise<ChartResultObject>;

export default function _chart(
export default function chart(
this: ModuleThis,
symbol: string,
queryOptionsOverrides: ChartOptionsWithReturnArray,
moduleOptions?: ModuleOptionsWithValidateTrue
): Promise<ChartResultArray>;

export default function _chart(
export default function chart(
this: ModuleThis,
symbol: string,
queryOptionsOverrides: ChartOptions,
moduleOptions?: ModuleOptionsWithValidateFalse
): Promise<any>;

export default async function _chart(
export default async function chart(
this: ModuleThis,
symbol: string,
queryOptionsOverrides: ChartOptions,
Expand All @@ -201,7 +204,7 @@ export default async function _chart(
const returnAs = queryOptionsOverrides?.return || "array";

const result = (await this._moduleExec({
moduleName: "_chart",
moduleName: "chart",

query: {
assertSymbol: symbol,
Expand Down Expand Up @@ -272,7 +275,7 @@ export default async function _chart(
if (returnAs === "object") {
return result;
} else if (returnAs === "array") {
let timestamp = result.timestamp;
const timestamp = result.timestamp;

/*
seems as though yahoo inserts extra quotes at the event times, so no need.
Expand Down Expand Up @@ -304,7 +307,7 @@ export default async function _chart(

const result2 = {
meta: result.meta,
quotes: timestamp ? new Array(timestamp.length) : new Array(),
quotes: timestamp ? new Array(timestamp.length) : [],
} as ChartResultArray;

const adjclose = result?.indicators?.adjclose?.[0].adjclose;
Expand All @@ -319,17 +322,14 @@ export default async function _chart(
low: result.indicators.quote[0].low[i],
close: result.indicators.quote[0].close[i],
};
// @ts-ignore: adjClose guarantees the chain.
if (adjclose) result2.quotes[i].adjclose = adjclose[i];
}

if (result.events) {
result2.events = {};

for (let event of ["dividends", "splits"]) {
// @ts-ignore
for (const event of ["dividends", "splits"]) {
if (result.events[event])
// @ts-ignore: TODO?
result2.events[event] = Object.values(result.events[event]);
}
}
Expand Down

0 comments on commit 28ba479

Please sign in to comment.