oakscriptjs 0.22.0 → 0.23.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/dist/cjs/check/index.d.ts.map +1 -1
- package/dist/cjs/check/index.js +2 -1
- package/dist/cjs/check/index.js.map +2 -2
- package/dist/cjs/check/spec.d.ts +1 -1
- package/dist/cjs/check/spec.d.ts.map +1 -1
- package/dist/cjs/check/spec.js +1 -1
- package/dist/cjs/check/spec.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/runtime/adapters/SimpleInputAdapter.js +1 -1
- package/dist/cjs/runtime/adapters/SimpleInputAdapter.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +3 -2
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/index.d.ts +4 -1
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +7 -4
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/esm/check/index.d.ts.map +1 -1
- package/dist/esm/check/index.js +2 -1
- package/dist/esm/check/index.js.map +1 -1
- package/dist/esm/check/spec.d.ts +1 -1
- package/dist/esm/check/spec.d.ts.map +1 -1
- package/dist/esm/check/spec.js +1 -1
- package/dist/esm/check/spec.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/runtime/adapters/SimpleInputAdapter.js +1 -1
- package/dist/esm/runtime/adapters/SimpleInputAdapter.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +3 -2
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +4 -1
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +8 -4
- package/dist/esm/script/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/oakscript/reference/script-structure.md +1 -1
- package/skills/oakscript/spec.schema.json +2 -1
- package/src/check/index.ts +2 -1
- package/src/check/spec.ts +1 -1
- package/src/index.ts +1 -1
- package/src/runtime/adapters/SimpleInputAdapter.ts +1 -1
- package/src/runtime/types.ts +3 -2
- package/src/script/index.ts +8 -4
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ Every kind takes an options object after the title. `...common` stands for the o
|
|
|
43
43
|
|---|---|
|
|
44
44
|
| `input.int(defval, title, { minval, maxval, step, options: [...], ...common })` | integer (rounded; a choice list with `options`) |
|
|
45
45
|
| `input.float(defval, title, { minval, maxval, step, options: [...], ...common })` | number (a choice list with `options`) |
|
|
46
|
-
| `input.price(defval, title, { ...common })` | number (a price level) |
|
|
46
|
+
| `input.price(defval, title, { ...common })` | number (a price level; with `confirm`, the host can ask for it on the chart, and `inline` shared with an `input.time` makes one point) |
|
|
47
47
|
| `input.bool(defval, title, { ...common })` | boolean |
|
|
48
48
|
| `input.string(defval, title, { options: [...], ...common })` | string (a choice list with `options`) |
|
|
49
49
|
| `input.text_area(defval, title, { ...common })` | multi-line string |
|
package/src/check/index.ts
CHANGED
|
@@ -290,7 +290,8 @@ function alternative(input: InputConfig): unknown {
|
|
|
290
290
|
const d = Number(input.defval);
|
|
291
291
|
return [d + 1, d - 1, d * 2, d + 10].find((v) => Number.isFinite(v) && v !== d && inRange(v));
|
|
292
292
|
}
|
|
293
|
-
case 'float':
|
|
293
|
+
case 'float':
|
|
294
|
+
case 'price': {
|
|
294
295
|
const d = Number(input.defval);
|
|
295
296
|
return [d * 1.5, d + 1, d / 2, d - 1].find((v) => Number.isFinite(v) && v !== d && inRange(v));
|
|
296
297
|
}
|
package/src/check/spec.ts
CHANGED
|
@@ -15,7 +15,7 @@ type Field =
|
|
|
15
15
|
|
|
16
16
|
const num = (doc: string): Field => ({ kind: 'number', doc });
|
|
17
17
|
|
|
18
|
-
export const INPUT_TYPES = ['int', 'float', 'bool', 'string', 'text_area', 'source', 'color', 'timeframe', 'session', 'time', 'symbol', 'enum'] as const;
|
|
18
|
+
export const INPUT_TYPES = ['int', 'float', 'bool', 'string', 'text_area', 'source', 'color', 'timeframe', 'session', 'time', 'symbol', 'enum', 'price'] as const;
|
|
19
19
|
export const OUTPUT_KINDS = ['plot', 'shape', 'char', 'arrow', 'candle', 'bar', 'hline', 'bgcolor', 'barcolor', 'alertcondition'] as const;
|
|
20
20
|
|
|
21
21
|
/** The keys of a spec checked by checkScript. */
|
package/src/index.ts
CHANGED
|
@@ -232,7 +232,7 @@ export type { LightweightSeriesDefinitions } from './runtime/adapters/Lightweigh
|
|
|
232
232
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
233
233
|
|
|
234
234
|
// Version
|
|
235
|
-
export const VERSION = '0.
|
|
235
|
+
export const VERSION = '0.23.0';
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
238
|
* Library information
|
|
@@ -53,7 +53,7 @@ export class SimpleInputAdapter implements InputAdapter {
|
|
|
53
53
|
let validatedValue = value;
|
|
54
54
|
|
|
55
55
|
// Validate numeric inputs
|
|
56
|
-
if ((config.type === 'int' || config.type === 'float') && typeof value === 'number') {
|
|
56
|
+
if ((config.type === 'int' || config.type === 'float' || config.type === 'price') && typeof value === 'number') {
|
|
57
57
|
// Apply min constraint
|
|
58
58
|
if (config.min !== undefined && value < config.min) {
|
|
59
59
|
validatedValue = config.min;
|
package/src/runtime/types.ts
CHANGED
|
@@ -71,9 +71,10 @@ export interface InputConfig {
|
|
|
71
71
|
/**
|
|
72
72
|
* Type of input. `timeframe` and `session` values are strings ("60", "1D", "0930-1600:23456";
|
|
73
73
|
* an empty timeframe means the chart timeframe), `time` values are UNIX times in milliseconds. A `text_area`
|
|
74
|
-
* value is a string that can hold several lines. An `enum` value is the field name of one of its `options`.
|
|
74
|
+
* value is a string that can hold several lines. An `enum` value is the field name of one of its `options`. A `price`
|
|
75
|
+
* value is a number, a price level (a host can let the user pick it on the chart).
|
|
75
76
|
*/
|
|
76
|
-
type: 'int' | 'float' | 'bool' | 'string' | 'text_area' | 'source' | 'color' | 'timeframe' | 'session' | 'time' | 'symbol' | 'enum';
|
|
77
|
+
type: 'int' | 'float' | 'bool' | 'string' | 'text_area' | 'source' | 'color' | 'timeframe' | 'session' | 'time' | 'symbol' | 'enum' | 'price';
|
|
77
78
|
/** Default value */
|
|
78
79
|
defval: unknown;
|
|
79
80
|
/** Display title */
|
package/src/script/index.ts
CHANGED
|
@@ -1285,10 +1285,11 @@ function registerInput<T>(config: Omit<InputConfig, 'id'>, fallbackId: string):
|
|
|
1285
1285
|
return (value === undefined ? config.defval : value) as T;
|
|
1286
1286
|
}
|
|
1287
1287
|
|
|
1288
|
-
|
|
1288
|
+
/** `idKind`: the kind in the id of an input without title (a price input keeps the ids of the float input it was). */
|
|
1289
|
+
function registerNumeric(type: 'int' | 'float' | 'price', defval: number, title?: string, opts: NumericInputOptions = {}, idKind: string = type): number {
|
|
1289
1290
|
const v = registerInput<unknown>(
|
|
1290
1291
|
{ type, defval, title, min: opts.minval, max: opts.maxval, step: opts.step, ...(opts.options ? { options: opts.options } : {}), ...common(opts) },
|
|
1291
|
-
`input_${
|
|
1292
|
+
`input_${idKind}`
|
|
1292
1293
|
);
|
|
1293
1294
|
return typeof v === 'number' ? v : defval;
|
|
1294
1295
|
}
|
|
@@ -1408,10 +1409,13 @@ export const input = strictNamespace('input', {
|
|
|
1408
1409
|
const a = inputArgs<string, StringInputOptions>('symbol', defval, title, opts);
|
|
1409
1410
|
return registerInput<string>({ type: 'symbol', defval: a.defval, title: a.title, options: a.opts.options, ...common(a.opts) }, 'input_symbol');
|
|
1410
1411
|
},
|
|
1411
|
-
/**
|
|
1412
|
+
/**
|
|
1413
|
+
* PineScript `input.price`: a price level, `InputConfig.type` `'price'` (a number field; with `confirm`, a host can
|
|
1414
|
+
* ask for it on the chart; an `inline` id shared with an `input.time` makes one point of both).
|
|
1415
|
+
*/
|
|
1412
1416
|
price(defval: number | InputArgs<InputOptions, number>, title?: string | InputArgs<InputOptions, number>, opts?: InputOptions): number {
|
|
1413
1417
|
const a = inputArgs<number, InputOptions>('price', defval, title, opts);
|
|
1414
|
-
return registerNumeric('
|
|
1418
|
+
return registerNumeric('price', a.defval, a.title, a.opts, 'float');
|
|
1415
1419
|
},
|
|
1416
1420
|
/**
|
|
1417
1421
|
* A field of an enum made with `defineEnum()`: `input.enum(MaType.sma, "Average")`. The host lists the fields by
|