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.
Files changed (45) hide show
  1. package/dist/cjs/check/index.d.ts.map +1 -1
  2. package/dist/cjs/check/index.js +2 -1
  3. package/dist/cjs/check/index.js.map +2 -2
  4. package/dist/cjs/check/spec.d.ts +1 -1
  5. package/dist/cjs/check/spec.d.ts.map +1 -1
  6. package/dist/cjs/check/spec.js +1 -1
  7. package/dist/cjs/check/spec.js.map +2 -2
  8. package/dist/cjs/index.d.ts +1 -1
  9. package/dist/cjs/index.js +1 -1
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/runtime/adapters/SimpleInputAdapter.js +1 -1
  12. package/dist/cjs/runtime/adapters/SimpleInputAdapter.js.map +2 -2
  13. package/dist/cjs/runtime/types.d.ts +3 -2
  14. package/dist/cjs/runtime/types.d.ts.map +1 -1
  15. package/dist/cjs/runtime/types.js.map +1 -1
  16. package/dist/cjs/script/index.d.ts +4 -1
  17. package/dist/cjs/script/index.d.ts.map +1 -1
  18. package/dist/cjs/script/index.js +7 -4
  19. package/dist/cjs/script/index.js.map +2 -2
  20. package/dist/esm/check/index.d.ts.map +1 -1
  21. package/dist/esm/check/index.js +2 -1
  22. package/dist/esm/check/index.js.map +1 -1
  23. package/dist/esm/check/spec.d.ts +1 -1
  24. package/dist/esm/check/spec.d.ts.map +1 -1
  25. package/dist/esm/check/spec.js +1 -1
  26. package/dist/esm/check/spec.js.map +1 -1
  27. package/dist/esm/index.d.ts +1 -1
  28. package/dist/esm/index.js +1 -1
  29. package/dist/esm/runtime/adapters/SimpleInputAdapter.js +1 -1
  30. package/dist/esm/runtime/adapters/SimpleInputAdapter.js.map +1 -1
  31. package/dist/esm/runtime/types.d.ts +3 -2
  32. package/dist/esm/runtime/types.d.ts.map +1 -1
  33. package/dist/esm/script/index.d.ts +4 -1
  34. package/dist/esm/script/index.d.ts.map +1 -1
  35. package/dist/esm/script/index.js +8 -4
  36. package/dist/esm/script/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/skills/oakscript/reference/script-structure.md +1 -1
  39. package/skills/oakscript/spec.schema.json +2 -1
  40. package/src/check/index.ts +2 -1
  41. package/src/check/spec.ts +1 -1
  42. package/src/index.ts +1 -1
  43. package/src/runtime/adapters/SimpleInputAdapter.ts +1 -1
  44. package/src/runtime/types.ts +3 -2
  45. package/src/script/index.ts +8 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oakscriptjs",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "description": "PineScript v6 compatible technical analysis library for JavaScript/TypeScript",
6
6
  "main": "./dist/cjs/index.js",
@@ -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 |
@@ -41,7 +41,8 @@
41
41
  "session",
42
42
  "time",
43
43
  "symbol",
44
- "enum"
44
+ "enum",
45
+ "price"
45
46
  ],
46
47
  "description": "input type"
47
48
  },
@@ -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.20.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;
@@ -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 */
@@ -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
- function registerNumeric(type: 'int' | 'float', defval: number, title?: string, opts: NumericInputOptions = {}): number {
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_${type}`
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
- /** PineScript `input.price`: a price level, a float input (the host shows it as a number). */
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('float', a.defval, a.title, a.opts);
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