oakscriptjs 0.11.6 → 0.11.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/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/runtime/inputs.d.ts.map +1 -1
- package/dist/cjs/runtime/inputs.js +6 -2
- package/dist/cjs/runtime/inputs.js.map +2 -2
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +7 -1
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +13 -2
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/source-resolver.d.ts +17 -0
- package/dist/cjs/utils/source-resolver.d.ts.map +1 -0
- package/dist/cjs/utils/source-resolver.js +45 -0
- package/dist/cjs/utils/source-resolver.js.map +7 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/runtime/inputs.d.ts.map +1 -1
- package/dist/esm/runtime/inputs.js +8 -2
- package/dist/esm/runtime/inputs.js.map +1 -1
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +10 -1
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +18 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/source-resolver.d.ts +17 -0
- package/dist/esm/utils/source-resolver.d.ts.map +1 -0
- package/dist/esm/utils/source-resolver.js +24 -0
- package/dist/esm/utils/source-resolver.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/runtime/inputs.ts +7 -2
- package/src/script/index.ts +8 -1
- package/src/utils/index.ts +15 -1
- package/src/utils/source-resolver.ts +29 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sources other than the bar fields: a study calculated on another study's output (PineScript hosts call it "study
|
|
3
|
+
* on study"). A source input then holds a host name such as `"<sourceId>$<plotIndex>"`; the host resolves it to
|
|
4
|
+
* values aligned with the bars it passes to the calculation (`NaN` where there is no value).
|
|
5
|
+
*
|
|
6
|
+
* The host sets the resolver around a calculation and clears it after; a name it does not know falls back to
|
|
7
|
+
* `close`, as before.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Values of a source by name, aligned with the bars of the calculation; null/undefined = unknown name. */
|
|
11
|
+
export type SourceResolver = (name: string) => ArrayLike<number> | null | undefined;
|
|
12
|
+
|
|
13
|
+
let resolver: SourceResolver | null = null;
|
|
14
|
+
|
|
15
|
+
/** Built-in sources (bar fields and their averages). */
|
|
16
|
+
export const BUILTIN_SOURCES: ReadonlySet<string> = new Set([
|
|
17
|
+
'open', 'high', 'low', 'close', 'hl2', 'hlc3', 'ohlc4', 'hlcc4', 'volume',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
/** Set (or clear with null) how source names other than the built-ins are read. */
|
|
21
|
+
export function setSourceResolver(fn: SourceResolver | null): void {
|
|
22
|
+
resolver = fn;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Values of a non built-in source name, or null when no resolver knows it. */
|
|
26
|
+
export function externalSource(name: string): ArrayLike<number> | null {
|
|
27
|
+
if (!resolver || BUILTIN_SOURCES.has(name)) return null;
|
|
28
|
+
return resolver(name) ?? null;
|
|
29
|
+
}
|