oakscriptjs 0.8.1 → 0.9.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 (544) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -9
  3. package/dist/cjs/array/index.d.ts +701 -0
  4. package/dist/cjs/array/index.d.ts.map +1 -0
  5. package/dist/cjs/array/index.js +392 -0
  6. package/dist/cjs/array/index.js.map +7 -0
  7. package/dist/cjs/box/index.d.ts +444 -0
  8. package/dist/cjs/box/index.d.ts.map +1 -0
  9. package/dist/cjs/box/index.js +246 -0
  10. package/dist/cjs/box/index.js.map +7 -0
  11. package/dist/cjs/callsite/index.d.ts +61 -0
  12. package/dist/cjs/callsite/index.d.ts.map +1 -0
  13. package/dist/cjs/callsite/index.js +65 -0
  14. package/dist/cjs/callsite/index.js.map +7 -0
  15. package/dist/cjs/chartpoint/index.d.ts +90 -0
  16. package/dist/cjs/chartpoint/index.d.ts.map +1 -0
  17. package/dist/cjs/chartpoint/index.js +56 -0
  18. package/dist/cjs/chartpoint/index.js.map +7 -0
  19. package/dist/cjs/color/index.d.ts +285 -0
  20. package/dist/cjs/color/index.d.ts.map +1 -0
  21. package/dist/cjs/color/index.js +143 -0
  22. package/dist/cjs/color/index.js.map +7 -0
  23. package/dist/cjs/compare/index.d.ts +26 -0
  24. package/dist/cjs/compare/index.d.ts.map +1 -0
  25. package/dist/cjs/compare/index.js +50 -0
  26. package/dist/cjs/compare/index.js.map +7 -0
  27. package/dist/cjs/drawing/registry.d.ts +42 -0
  28. package/dist/cjs/drawing/registry.d.ts.map +1 -0
  29. package/dist/cjs/drawing/registry.js +87 -0
  30. package/dist/cjs/drawing/registry.js.map +7 -0
  31. package/dist/cjs/index.d.ts +85 -0
  32. package/dist/cjs/index.d.ts.map +1 -0
  33. package/dist/cjs/index.js +184 -0
  34. package/dist/cjs/index.js.map +7 -0
  35. package/dist/cjs/indicator.d.ts +117 -0
  36. package/dist/cjs/indicator.d.ts.map +1 -0
  37. package/dist/cjs/indicator.js +74 -0
  38. package/dist/cjs/indicator.js.map +7 -0
  39. package/dist/cjs/input.d.ts +196 -0
  40. package/dist/cjs/input.d.ts.map +1 -0
  41. package/dist/cjs/input.js +197 -0
  42. package/dist/cjs/input.js.map +7 -0
  43. package/dist/cjs/label/index.d.ts +303 -0
  44. package/dist/cjs/label/index.d.ts.map +1 -0
  45. package/dist/cjs/label/index.js +190 -0
  46. package/dist/cjs/label/index.js.map +7 -0
  47. package/dist/cjs/lib/index.d.ts +8 -0
  48. package/dist/cjs/lib/index.d.ts.map +1 -0
  49. package/dist/cjs/lib/index.js +19 -0
  50. package/dist/cjs/lib/index.js.map +7 -0
  51. package/dist/{lib → cjs/lib}/zigzag/index.d.ts +4 -1
  52. package/dist/cjs/lib/zigzag/index.d.ts.map +1 -0
  53. package/dist/cjs/lib/zigzag/index.js +27 -0
  54. package/dist/cjs/lib/zigzag/index.js.map +7 -0
  55. package/dist/cjs/lib/zigzag/zigzag.d.ts +100 -0
  56. package/dist/cjs/lib/zigzag/zigzag.d.ts.map +1 -0
  57. package/dist/cjs/lib/zigzag/zigzag.js +207 -0
  58. package/dist/cjs/lib/zigzag/zigzag.js.map +7 -0
  59. package/dist/cjs/line/index.d.ts +342 -0
  60. package/dist/cjs/line/index.d.ts.map +1 -0
  61. package/dist/cjs/line/index.js +193 -0
  62. package/dist/cjs/line/index.js.map +7 -0
  63. package/dist/cjs/linefill/index.d.ts +124 -0
  64. package/dist/cjs/linefill/index.d.ts.map +1 -0
  65. package/dist/cjs/linefill/index.js +56 -0
  66. package/dist/cjs/linefill/index.js.map +7 -0
  67. package/dist/cjs/map/index.d.ts +69 -0
  68. package/dist/cjs/map/index.d.ts.map +1 -0
  69. package/dist/cjs/map/index.js +80 -0
  70. package/dist/cjs/map/index.js.map +7 -0
  71. package/dist/cjs/math/index.d.ts +560 -0
  72. package/dist/cjs/math/index.d.ts.map +1 -0
  73. package/dist/cjs/math/index.js +441 -0
  74. package/dist/cjs/math/index.js.map +7 -0
  75. package/dist/cjs/matrix/index.d.ts +1231 -0
  76. package/dist/cjs/matrix/index.d.ts.map +1 -0
  77. package/dist/cjs/matrix/index.js +1200 -0
  78. package/dist/cjs/matrix/index.js.map +7 -0
  79. package/dist/cjs/package.json +1 -0
  80. package/dist/cjs/plot.d.ts +76 -0
  81. package/dist/cjs/plot.d.ts.map +1 -0
  82. package/dist/cjs/plot.js +51 -0
  83. package/dist/cjs/plot.js.map +7 -0
  84. package/dist/cjs/polyline/index.d.ts +115 -0
  85. package/dist/cjs/polyline/index.d.ts.map +1 -0
  86. package/dist/cjs/polyline/index.js +76 -0
  87. package/dist/cjs/polyline/index.js.map +7 -0
  88. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.d.ts +86 -0
  89. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.d.ts.map +1 -0
  90. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.js +141 -0
  91. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.js.map +7 -0
  92. package/dist/cjs/runtime/adapters/SimpleInputAdapter.d.ts +59 -0
  93. package/dist/cjs/runtime/adapters/SimpleInputAdapter.d.ts.map +1 -0
  94. package/dist/cjs/runtime/adapters/SimpleInputAdapter.js +117 -0
  95. package/dist/cjs/runtime/adapters/SimpleInputAdapter.js.map +7 -0
  96. package/dist/{runtime → cjs/runtime}/index.d.ts +12 -5
  97. package/dist/cjs/runtime/index.d.ts.map +1 -0
  98. package/dist/cjs/runtime/index.js +49 -0
  99. package/dist/cjs/runtime/index.js.map +7 -0
  100. package/dist/cjs/runtime/inputs.d.ts +91 -0
  101. package/dist/cjs/runtime/inputs.d.ts.map +1 -0
  102. package/dist/cjs/runtime/inputs.js +262 -0
  103. package/dist/cjs/runtime/inputs.js.map +7 -0
  104. package/dist/cjs/runtime/runtime.d.ts +70 -0
  105. package/dist/cjs/runtime/runtime.d.ts.map +1 -0
  106. package/dist/cjs/runtime/runtime.js +148 -0
  107. package/dist/cjs/runtime/runtime.js.map +7 -0
  108. package/dist/cjs/runtime/series.d.ts +362 -0
  109. package/dist/cjs/runtime/series.d.ts.map +1 -0
  110. package/dist/cjs/runtime/series.js +560 -0
  111. package/dist/cjs/runtime/series.js.map +7 -0
  112. package/dist/cjs/runtime/types.d.ts +282 -0
  113. package/dist/cjs/runtime/types.d.ts.map +1 -0
  114. package/dist/cjs/runtime/types.js +17 -0
  115. package/dist/cjs/runtime/types.js.map +7 -0
  116. package/dist/cjs/script/index.d.ts +987 -0
  117. package/dist/cjs/script/index.d.ts.map +1 -0
  118. package/dist/cjs/script/index.js +1169 -0
  119. package/dist/cjs/script/index.js.map +7 -0
  120. package/dist/cjs/security/resample.d.ts +63 -0
  121. package/dist/cjs/security/resample.d.ts.map +1 -0
  122. package/dist/cjs/security/resample.js +84 -0
  123. package/dist/cjs/security/resample.js.map +7 -0
  124. package/dist/cjs/session/bars.d.ts +80 -0
  125. package/dist/cjs/session/bars.d.ts.map +1 -0
  126. package/dist/cjs/session/bars.js +219 -0
  127. package/dist/cjs/session/bars.js.map +7 -0
  128. package/dist/cjs/session/calendar.d.ts +70 -0
  129. package/dist/cjs/session/calendar.d.ts.map +1 -0
  130. package/dist/cjs/session/calendar.js +164 -0
  131. package/dist/cjs/session/calendar.js.map +7 -0
  132. package/dist/cjs/str/dateformat.d.ts +15 -0
  133. package/dist/cjs/str/dateformat.d.ts.map +1 -0
  134. package/dist/cjs/str/dateformat.js +149 -0
  135. package/dist/cjs/str/dateformat.js.map +7 -0
  136. package/dist/cjs/str/index.d.ts +459 -0
  137. package/dist/cjs/str/index.d.ts.map +1 -0
  138. package/dist/cjs/str/index.js +143 -0
  139. package/dist/cjs/str/index.js.map +7 -0
  140. package/dist/cjs/str/messageformat.d.ts +14 -0
  141. package/dist/cjs/str/messageformat.d.ts.map +1 -0
  142. package/dist/cjs/str/messageformat.js +114 -0
  143. package/dist/cjs/str/messageformat.js.map +7 -0
  144. package/dist/cjs/str/numberformat.d.ts +19 -0
  145. package/dist/cjs/str/numberformat.d.ts.map +1 -0
  146. package/dist/cjs/str/numberformat.js +170 -0
  147. package/dist/cjs/str/numberformat.js.map +7 -0
  148. package/dist/{strategy → cjs/strategy}/index.d.ts +50 -0
  149. package/dist/cjs/strategy/index.d.ts.map +1 -0
  150. package/dist/cjs/strategy/index.js +92 -0
  151. package/dist/cjs/strategy/index.js.map +7 -0
  152. package/dist/cjs/ta/index.d.ts +1397 -0
  153. package/dist/cjs/ta/index.d.ts.map +1 -0
  154. package/dist/cjs/ta/index.js +1715 -0
  155. package/dist/cjs/ta/index.js.map +7 -0
  156. package/dist/cjs/ta/running-sum.d.ts +30 -0
  157. package/dist/cjs/ta/running-sum.d.ts.map +1 -0
  158. package/dist/cjs/ta/running-sum.js +99 -0
  159. package/dist/cjs/ta/running-sum.js.map +7 -0
  160. package/dist/cjs/ta-series.d.ts +558 -0
  161. package/dist/cjs/ta-series.d.ts.map +1 -0
  162. package/dist/cjs/ta-series.js +606 -0
  163. package/dist/cjs/ta-series.js.map +7 -0
  164. package/dist/cjs/text/index.d.ts +14 -0
  165. package/dist/cjs/text/index.d.ts.map +1 -0
  166. package/dist/cjs/text/index.js +29 -0
  167. package/dist/cjs/text/index.js.map +7 -0
  168. package/dist/cjs/time/datestring.d.ts +23 -0
  169. package/dist/cjs/time/datestring.d.ts.map +1 -0
  170. package/dist/cjs/time/datestring.js +106 -0
  171. package/dist/cjs/time/datestring.js.map +7 -0
  172. package/dist/cjs/time/index.d.ts +89 -0
  173. package/dist/cjs/time/index.d.ts.map +1 -0
  174. package/dist/cjs/time/index.js +85 -0
  175. package/dist/cjs/time/index.js.map +7 -0
  176. package/dist/cjs/time/session.d.ts +17 -0
  177. package/dist/cjs/time/session.d.ts.map +1 -0
  178. package/dist/cjs/time/session.js +65 -0
  179. package/dist/cjs/time/session.js.map +7 -0
  180. package/dist/cjs/time/timezone.d.ts +40 -0
  181. package/dist/cjs/time/timezone.d.ts.map +1 -0
  182. package/dist/cjs/time/timezone.js +125 -0
  183. package/dist/cjs/time/timezone.js.map +7 -0
  184. package/dist/cjs/timeframe/index.d.ts +73 -0
  185. package/dist/cjs/timeframe/index.d.ts.map +1 -0
  186. package/dist/cjs/timeframe/index.js +85 -0
  187. package/dist/cjs/timeframe/index.js.map +7 -0
  188. package/dist/cjs/types/index.d.ts +343 -0
  189. package/dist/cjs/types/index.d.ts.map +1 -0
  190. package/dist/cjs/types/index.js +32 -0
  191. package/dist/cjs/types/index.js.map +7 -0
  192. package/dist/cjs/types/metadata.d.ts +300 -0
  193. package/dist/cjs/types/metadata.d.ts.map +1 -0
  194. package/dist/cjs/types/metadata.js +17 -0
  195. package/dist/cjs/types/metadata.js.map +7 -0
  196. package/dist/cjs/utils/index.d.ts +167 -0
  197. package/dist/cjs/utils/index.d.ts.map +1 -0
  198. package/dist/cjs/utils/index.js +209 -0
  199. package/dist/cjs/utils/index.js.map +7 -0
  200. package/dist/esm/array/index.d.ts +701 -0
  201. package/dist/esm/array/index.d.ts.map +1 -0
  202. package/dist/esm/array/index.js +983 -0
  203. package/dist/esm/array/index.js.map +1 -0
  204. package/dist/esm/box/index.d.ts +444 -0
  205. package/dist/esm/box/index.d.ts.map +1 -0
  206. package/dist/esm/box/index.js +602 -0
  207. package/dist/esm/box/index.js.map +1 -0
  208. package/dist/esm/callsite/index.d.ts +61 -0
  209. package/dist/esm/callsite/index.d.ts.map +1 -0
  210. package/dist/esm/callsite/index.js +97 -0
  211. package/dist/esm/callsite/index.js.map +1 -0
  212. package/dist/esm/chartpoint/index.d.ts +90 -0
  213. package/dist/esm/chartpoint/index.d.ts.map +1 -0
  214. package/dist/esm/chartpoint/index.js +113 -0
  215. package/dist/esm/chartpoint/index.js.map +1 -0
  216. package/dist/esm/color/index.d.ts +285 -0
  217. package/dist/esm/color/index.d.ts.map +1 -0
  218. package/dist/esm/color/index.js +373 -0
  219. package/dist/esm/color/index.js.map +1 -0
  220. package/dist/esm/compare/index.d.ts +26 -0
  221. package/dist/esm/compare/index.d.ts.map +1 -0
  222. package/dist/esm/compare/index.js +39 -0
  223. package/dist/esm/compare/index.js.map +1 -0
  224. package/dist/esm/drawing/registry.d.ts +42 -0
  225. package/dist/esm/drawing/registry.d.ts.map +1 -0
  226. package/dist/esm/drawing/registry.js +89 -0
  227. package/dist/esm/drawing/registry.js.map +1 -0
  228. package/dist/esm/index.d.ts +85 -0
  229. package/dist/esm/index.d.ts.map +1 -0
  230. package/dist/esm/index.js +96 -0
  231. package/dist/esm/index.js.map +1 -0
  232. package/dist/esm/indicator.d.ts +117 -0
  233. package/dist/esm/indicator.d.ts.map +1 -0
  234. package/dist/esm/indicator.js +84 -0
  235. package/dist/esm/indicator.js.map +1 -0
  236. package/dist/esm/input.d.ts +196 -0
  237. package/dist/esm/input.d.ts.map +1 -0
  238. package/dist/esm/input.js +183 -0
  239. package/dist/esm/input.js.map +1 -0
  240. package/dist/esm/label/index.d.ts +303 -0
  241. package/dist/esm/label/index.d.ts.map +1 -0
  242. package/dist/esm/label/index.js +417 -0
  243. package/dist/esm/label/index.js.map +1 -0
  244. package/dist/esm/lib/index.d.ts +8 -0
  245. package/dist/esm/lib/index.d.ts.map +1 -0
  246. package/dist/esm/lib/index.js +8 -0
  247. package/dist/esm/lib/index.js.map +1 -0
  248. package/dist/esm/lib/zigzag/index.d.ts +5 -0
  249. package/dist/esm/lib/zigzag/index.d.ts.map +1 -0
  250. package/dist/esm/lib/zigzag/index.js +5 -0
  251. package/dist/esm/lib/zigzag/index.js.map +1 -0
  252. package/dist/esm/lib/zigzag/zigzag.d.ts +100 -0
  253. package/dist/esm/lib/zigzag/zigzag.d.ts.map +1 -0
  254. package/dist/esm/lib/zigzag/zigzag.js +229 -0
  255. package/dist/esm/lib/zigzag/zigzag.js.map +1 -0
  256. package/dist/esm/line/index.d.ts +342 -0
  257. package/dist/esm/line/index.d.ts.map +1 -0
  258. package/dist/esm/line/index.js +470 -0
  259. package/dist/esm/line/index.js.map +1 -0
  260. package/dist/esm/linefill/index.d.ts +124 -0
  261. package/dist/esm/linefill/index.d.ts.map +1 -0
  262. package/dist/esm/linefill/index.js +144 -0
  263. package/dist/esm/linefill/index.js.map +1 -0
  264. package/dist/esm/map/index.d.ts +69 -0
  265. package/dist/esm/map/index.d.ts.map +1 -0
  266. package/dist/esm/map/index.js +106 -0
  267. package/dist/esm/map/index.js.map +1 -0
  268. package/dist/esm/math/index.d.ts +560 -0
  269. package/dist/esm/math/index.d.ts.map +1 -0
  270. package/dist/esm/math/index.js +495 -0
  271. package/dist/esm/math/index.js.map +1 -0
  272. package/dist/esm/matrix/index.d.ts +1231 -0
  273. package/dist/esm/matrix/index.d.ts.map +1 -0
  274. package/dist/esm/matrix/index.js +2450 -0
  275. package/dist/esm/matrix/index.js.map +1 -0
  276. package/dist/esm/plot.d.ts +76 -0
  277. package/dist/esm/plot.d.ts.map +1 -0
  278. package/dist/esm/plot.js +63 -0
  279. package/dist/esm/plot.js.map +1 -0
  280. package/dist/esm/polyline/index.d.ts +115 -0
  281. package/dist/esm/polyline/index.d.ts.map +1 -0
  282. package/dist/esm/polyline/index.js +157 -0
  283. package/dist/esm/polyline/index.js.map +1 -0
  284. package/dist/esm/runtime/adapters/LightweightChartsAdapter.d.ts +86 -0
  285. package/dist/esm/runtime/adapters/LightweightChartsAdapter.d.ts.map +1 -0
  286. package/dist/esm/runtime/adapters/LightweightChartsAdapter.js +140 -0
  287. package/dist/esm/runtime/adapters/LightweightChartsAdapter.js.map +1 -0
  288. package/dist/esm/runtime/adapters/SimpleInputAdapter.d.ts +59 -0
  289. package/dist/esm/runtime/adapters/SimpleInputAdapter.d.ts.map +1 -0
  290. package/dist/esm/runtime/adapters/SimpleInputAdapter.js +115 -0
  291. package/dist/esm/runtime/adapters/SimpleInputAdapter.js.map +1 -0
  292. package/dist/esm/runtime/index.d.ts +13 -0
  293. package/dist/esm/runtime/index.d.ts.map +1 -0
  294. package/dist/esm/runtime/index.js +14 -0
  295. package/dist/esm/runtime/index.js.map +1 -0
  296. package/dist/esm/runtime/inputs.d.ts +91 -0
  297. package/dist/esm/runtime/inputs.d.ts.map +1 -0
  298. package/dist/esm/runtime/inputs.js +334 -0
  299. package/dist/esm/runtime/inputs.js.map +1 -0
  300. package/dist/esm/runtime/runtime.d.ts +70 -0
  301. package/dist/esm/runtime/runtime.d.ts.map +1 -0
  302. package/dist/esm/runtime/runtime.js +193 -0
  303. package/dist/esm/runtime/runtime.js.map +1 -0
  304. package/dist/esm/runtime/series.d.ts +362 -0
  305. package/dist/esm/runtime/series.d.ts.map +1 -0
  306. package/dist/esm/runtime/series.js +583 -0
  307. package/dist/esm/runtime/series.js.map +1 -0
  308. package/dist/esm/runtime/types.d.ts +282 -0
  309. package/dist/esm/runtime/types.d.ts.map +1 -0
  310. package/dist/esm/runtime/types.js +7 -0
  311. package/dist/esm/runtime/types.js.map +1 -0
  312. package/dist/esm/script/index.d.ts +987 -0
  313. package/dist/esm/script/index.d.ts.map +1 -0
  314. package/dist/esm/script/index.js +1289 -0
  315. package/dist/esm/script/index.js.map +1 -0
  316. package/dist/esm/security/resample.d.ts +63 -0
  317. package/dist/esm/security/resample.d.ts.map +1 -0
  318. package/dist/esm/security/resample.js +110 -0
  319. package/dist/esm/security/resample.js.map +1 -0
  320. package/dist/esm/session/bars.d.ts +80 -0
  321. package/dist/esm/session/bars.d.ts.map +1 -0
  322. package/dist/esm/session/bars.js +232 -0
  323. package/dist/esm/session/bars.js.map +1 -0
  324. package/dist/esm/session/calendar.d.ts +70 -0
  325. package/dist/esm/session/calendar.d.ts.map +1 -0
  326. package/dist/esm/session/calendar.js +172 -0
  327. package/dist/esm/session/calendar.js.map +1 -0
  328. package/dist/esm/str/dateformat.d.ts +15 -0
  329. package/dist/esm/str/dateformat.d.ts.map +1 -0
  330. package/dist/esm/str/dateformat.js +136 -0
  331. package/dist/esm/str/dateformat.js.map +1 -0
  332. package/dist/esm/str/index.d.ts +459 -0
  333. package/dist/esm/str/index.d.ts.map +1 -0
  334. package/dist/esm/str/index.js +540 -0
  335. package/dist/esm/str/index.js.map +1 -0
  336. package/dist/esm/str/messageformat.d.ts +14 -0
  337. package/dist/esm/str/messageformat.d.ts.map +1 -0
  338. package/dist/esm/str/messageformat.js +111 -0
  339. package/dist/esm/str/messageformat.js.map +1 -0
  340. package/dist/esm/str/numberformat.d.ts +19 -0
  341. package/dist/esm/str/numberformat.d.ts.map +1 -0
  342. package/dist/esm/str/numberformat.js +189 -0
  343. package/dist/esm/str/numberformat.js.map +1 -0
  344. package/dist/esm/strategy/index.d.ts +245 -0
  345. package/dist/esm/strategy/index.d.ts.map +1 -0
  346. package/dist/esm/strategy/index.js +84 -0
  347. package/dist/esm/strategy/index.js.map +1 -0
  348. package/dist/esm/ta/index.d.ts +1397 -0
  349. package/dist/esm/ta/index.d.ts.map +1 -0
  350. package/dist/esm/ta/index.js +3227 -0
  351. package/dist/esm/ta/index.js.map +1 -0
  352. package/dist/esm/ta/running-sum.d.ts +30 -0
  353. package/dist/esm/ta/running-sum.d.ts.map +1 -0
  354. package/dist/esm/ta/running-sum.js +113 -0
  355. package/dist/esm/ta/running-sum.js.map +1 -0
  356. package/dist/esm/ta-series.d.ts +558 -0
  357. package/dist/esm/ta-series.d.ts.map +1 -0
  358. package/dist/esm/ta-series.js +910 -0
  359. package/dist/esm/ta-series.js.map +1 -0
  360. package/dist/esm/text/index.d.ts +14 -0
  361. package/dist/esm/text/index.d.ts.map +1 -0
  362. package/dist/esm/text/index.js +14 -0
  363. package/dist/esm/text/index.js.map +1 -0
  364. package/dist/esm/time/datestring.d.ts +23 -0
  365. package/dist/esm/time/datestring.d.ts.map +1 -0
  366. package/dist/esm/time/datestring.js +94 -0
  367. package/dist/esm/time/datestring.js.map +1 -0
  368. package/dist/esm/time/index.d.ts +89 -0
  369. package/dist/esm/time/index.d.ts.map +1 -0
  370. package/dist/esm/time/index.js +108 -0
  371. package/dist/esm/time/index.js.map +1 -0
  372. package/dist/esm/time/session.d.ts +17 -0
  373. package/dist/esm/time/session.d.ts.map +1 -0
  374. package/dist/esm/time/session.js +69 -0
  375. package/dist/esm/time/session.js.map +1 -0
  376. package/dist/esm/time/timezone.d.ts +40 -0
  377. package/dist/esm/time/timezone.d.ts.map +1 -0
  378. package/dist/esm/time/timezone.js +144 -0
  379. package/dist/esm/time/timezone.js.map +1 -0
  380. package/dist/esm/timeframe/index.d.ts +73 -0
  381. package/dist/esm/timeframe/index.d.ts.map +1 -0
  382. package/dist/esm/timeframe/index.js +131 -0
  383. package/dist/esm/timeframe/index.js.map +1 -0
  384. package/dist/esm/types/index.d.ts +343 -0
  385. package/dist/esm/types/index.d.ts.map +1 -0
  386. package/dist/esm/types/index.js +17 -0
  387. package/dist/esm/types/index.js.map +1 -0
  388. package/dist/esm/types/metadata.d.ts +300 -0
  389. package/dist/esm/types/metadata.d.ts.map +1 -0
  390. package/dist/esm/types/metadata.js +7 -0
  391. package/dist/esm/types/metadata.js.map +1 -0
  392. package/dist/esm/utils/index.d.ts +167 -0
  393. package/dist/esm/utils/index.d.ts.map +1 -0
  394. package/dist/esm/utils/index.js +295 -0
  395. package/dist/esm/utils/index.js.map +1 -0
  396. package/package.json +53 -23
  397. package/src/array/index.ts +1056 -0
  398. package/src/box/index.ts +680 -0
  399. package/src/callsite/index.ts +104 -0
  400. package/src/chartpoint/index.ts +126 -0
  401. package/src/color/index.ts +411 -0
  402. package/src/compare/index.ts +46 -0
  403. package/src/drawing/registry.ts +106 -0
  404. package/src/index.ts +201 -0
  405. package/src/indicator.ts +185 -0
  406. package/src/input.ts +280 -0
  407. package/src/label/index.ts +490 -0
  408. package/src/lib/index.ts +8 -0
  409. package/src/lib/zigzag/index.ts +13 -0
  410. package/src/lib/zigzag/zigzag.ts +318 -0
  411. package/src/line/index.ts +530 -0
  412. package/src/linefill/index.ts +152 -0
  413. package/src/map/index.ts +115 -0
  414. package/src/math/index.ts +1071 -0
  415. package/src/matrix/index.ts +2697 -0
  416. package/src/plot.ts +121 -0
  417. package/src/polyline/index.ts +184 -0
  418. package/src/runtime/adapters/LightweightChartsAdapter.ts +201 -0
  419. package/src/runtime/adapters/SimpleInputAdapter.ts +132 -0
  420. package/src/runtime/index.ts +52 -0
  421. package/src/runtime/inputs.ts +377 -0
  422. package/src/runtime/runtime.ts +241 -0
  423. package/src/runtime/series.ts +644 -0
  424. package/src/runtime/types.ts +292 -0
  425. package/src/script/index.ts +1865 -0
  426. package/src/security/resample.ts +119 -0
  427. package/src/session/bars.ts +262 -0
  428. package/src/session/calendar.ts +199 -0
  429. package/src/str/dateformat.ts +104 -0
  430. package/src/str/index.ts +557 -0
  431. package/src/str/messageformat.ts +109 -0
  432. package/src/str/numberformat.ts +197 -0
  433. package/src/strategy/index.ts +281 -0
  434. package/src/ta/index.ts +3580 -0
  435. package/src/ta/running-sum.ts +117 -0
  436. package/src/ta-series.ts +1036 -0
  437. package/src/text/index.ts +14 -0
  438. package/src/time/datestring.ts +96 -0
  439. package/src/time/index.ts +161 -0
  440. package/src/time/session.ts +79 -0
  441. package/src/time/timezone.ts +180 -0
  442. package/src/timeframe/index.ts +144 -0
  443. package/src/types/index.ts +398 -0
  444. package/src/types/metadata.ts +334 -0
  445. package/src/utils/index.ts +334 -0
  446. package/dist/array/index.d.ts +0 -57
  447. package/dist/array/index.d.ts.map +0 -1
  448. package/dist/box/index.d.ts +0 -37
  449. package/dist/box/index.d.ts.map +0 -1
  450. package/dist/callsite/index.d.ts +0 -7
  451. package/dist/callsite/index.d.ts.map +0 -1
  452. package/dist/chartpoint/index.d.ts +0 -8
  453. package/dist/chartpoint/index.d.ts.map +0 -1
  454. package/dist/color/index.d.ts +0 -28
  455. package/dist/color/index.d.ts.map +0 -1
  456. package/dist/compare/index.d.ts +0 -8
  457. package/dist/compare/index.d.ts.map +0 -1
  458. package/dist/drawing/registry.d.ts +0 -19
  459. package/dist/drawing/registry.d.ts.map +0 -1
  460. package/dist/index.cjs +0 -7979
  461. package/dist/index.d.ts +0 -64
  462. package/dist/index.d.ts.map +0 -1
  463. package/dist/index.mjs +0 -7962
  464. package/dist/indicator.d.ts +0 -42
  465. package/dist/indicator.d.ts.map +0 -1
  466. package/dist/input.d.ts +0 -47
  467. package/dist/input.d.ts.map +0 -1
  468. package/dist/label/index.d.ts +0 -30
  469. package/dist/label/index.d.ts.map +0 -1
  470. package/dist/lib/index.d.ts +0 -2
  471. package/dist/lib/index.d.ts.map +0 -1
  472. package/dist/lib/zigzag/index.d.ts.map +0 -1
  473. package/dist/lib/zigzag/zigzag.d.ts +0 -47
  474. package/dist/lib/zigzag/zigzag.d.ts.map +0 -1
  475. package/dist/line/index.d.ts +0 -30
  476. package/dist/line/index.d.ts.map +0 -1
  477. package/dist/linefill/index.d.ts +0 -10
  478. package/dist/linefill/index.d.ts.map +0 -1
  479. package/dist/map/index.d.ts +0 -14
  480. package/dist/map/index.d.ts.map +0 -1
  481. package/dist/math/index.d.ts +0 -53
  482. package/dist/math/index.d.ts.map +0 -1
  483. package/dist/matrix/index.d.ts +0 -52
  484. package/dist/matrix/index.d.ts.map +0 -1
  485. package/dist/plot.d.ts +0 -20
  486. package/dist/plot.d.ts.map +0 -1
  487. package/dist/polyline/index.d.ts +0 -11
  488. package/dist/polyline/index.d.ts.map +0 -1
  489. package/dist/runtime/adapters/LightweightChartsAdapter.d.ts +0 -15
  490. package/dist/runtime/adapters/LightweightChartsAdapter.d.ts.map +0 -1
  491. package/dist/runtime/adapters/SimpleInputAdapter.d.ts +0 -16
  492. package/dist/runtime/adapters/SimpleInputAdapter.d.ts.map +0 -1
  493. package/dist/runtime/index.cjs +0 -600
  494. package/dist/runtime/index.d.ts.map +0 -1
  495. package/dist/runtime/index.mjs +0 -577
  496. package/dist/runtime/inputs.d.ts +0 -13
  497. package/dist/runtime/inputs.d.ts.map +0 -1
  498. package/dist/runtime/runtime.d.ts +0 -16
  499. package/dist/runtime/runtime.d.ts.map +0 -1
  500. package/dist/runtime/series.d.ts +0 -60
  501. package/dist/runtime/series.d.ts.map +0 -1
  502. package/dist/runtime/types.d.ts +0 -122
  503. package/dist/runtime/types.d.ts.map +0 -1
  504. package/dist/script/index.cjs +0 -6372
  505. package/dist/script/index.d.ts +0 -709
  506. package/dist/script/index.d.ts.map +0 -1
  507. package/dist/script/index.mjs +0 -6355
  508. package/dist/security/resample.d.ts +0 -13
  509. package/dist/security/resample.d.ts.map +0 -1
  510. package/dist/session/bars.d.ts +0 -34
  511. package/dist/session/bars.d.ts.map +0 -1
  512. package/dist/session/calendar.d.ts +0 -31
  513. package/dist/session/calendar.d.ts.map +0 -1
  514. package/dist/str/dateformat.d.ts +0 -2
  515. package/dist/str/dateformat.d.ts.map +0 -1
  516. package/dist/str/index.d.ts +0 -24
  517. package/dist/str/index.d.ts.map +0 -1
  518. package/dist/str/messageformat.d.ts +0 -2
  519. package/dist/str/messageformat.d.ts.map +0 -1
  520. package/dist/str/numberformat.d.ts +0 -3
  521. package/dist/str/numberformat.d.ts.map +0 -1
  522. package/dist/strategy/index.d.ts.map +0 -1
  523. package/dist/ta/index.d.ts +0 -72
  524. package/dist/ta/index.d.ts.map +0 -1
  525. package/dist/ta-series.d.ts +0 -143
  526. package/dist/ta-series.d.ts.map +0 -1
  527. package/dist/text/index.d.ts +0 -4
  528. package/dist/text/index.d.ts.map +0 -1
  529. package/dist/time/datestring.d.ts +0 -2
  530. package/dist/time/datestring.d.ts.map +0 -1
  531. package/dist/time/index.d.ts +0 -15
  532. package/dist/time/index.d.ts.map +0 -1
  533. package/dist/time/session.d.ts +0 -2
  534. package/dist/time/session.d.ts.map +0 -1
  535. package/dist/time/timezone.d.ts +0 -13
  536. package/dist/time/timezone.d.ts.map +0 -1
  537. package/dist/timeframe/index.d.ts +0 -17
  538. package/dist/timeframe/index.d.ts.map +0 -1
  539. package/dist/types/index.d.ts +0 -181
  540. package/dist/types/index.d.ts.map +0 -1
  541. package/dist/types/metadata.d.ts +0 -131
  542. package/dist/types/metadata.d.ts.map +0 -1
  543. package/dist/utils/index.d.ts +0 -26
  544. package/dist/utils/index.d.ts.map +0 -1
@@ -0,0 +1,1056 @@
1
+ /**
2
+ * Array namespace
3
+ * Mirrors PineScript's array.* functions
4
+ */
5
+
6
+ import type { PineArray, int, float, bool, simple_int, color, Line, Box, Label, Linefill } from '../types/index.js';
7
+
8
+ /**
9
+ * Creates a new array with initial size and default value
10
+ */
11
+ export function new_array<T>(size: simple_int = 0, initial_value?: T): PineArray<T> {
12
+ const arr: PineArray<T> = [];
13
+ for (let i = 0; i < size; i++) {
14
+ arr.push(initial_value as T);
15
+ }
16
+ return arr;
17
+ }
18
+
19
+ /**
20
+ * Returns the number of elements in an array
21
+ */
22
+ export function size<T>(id: PineArray<T>): int {
23
+ return id.length;
24
+ }
25
+
26
+ /**
27
+ * Returns the element at the specified index
28
+ */
29
+ export function get<T>(id: PineArray<T>, index: simple_int): T {
30
+ return id[index]!;
31
+ }
32
+
33
+ /**
34
+ * Sets the value of the element at the specified index
35
+ */
36
+ export function set<T>(id: PineArray<T>, index: simple_int, value: T): void {
37
+ id[index] = value;
38
+ }
39
+
40
+ /**
41
+ * Appends a value to the end of the array
42
+ */
43
+ export function push<T>(id: PineArray<T>, value: T): void {
44
+ id.push(value);
45
+ }
46
+
47
+ /**
48
+ * Removes and returns the last element of the array
49
+ */
50
+ export function pop<T>(id: PineArray<T>): T {
51
+ return id.pop() as T;
52
+ }
53
+
54
+ /**
55
+ * Inserts a value at the beginning of the array
56
+ */
57
+ export function unshift<T>(id: PineArray<T>, value: T): void {
58
+ id.unshift(value);
59
+ }
60
+
61
+ /**
62
+ * Removes and returns the first element of the array
63
+ */
64
+ export function shift<T>(id: PineArray<T>): T {
65
+ return id.shift() as T;
66
+ }
67
+
68
+ /**
69
+ * Removes all elements from the array
70
+ */
71
+ export function clear<T>(id: PineArray<T>): void {
72
+ id.length = 0;
73
+ }
74
+
75
+ /**
76
+ * Inserts a value at the specified index
77
+ */
78
+ export function insert<T>(id: PineArray<T>, index: simple_int, value: T): void {
79
+ id.splice(index, 0, value);
80
+ }
81
+
82
+ /**
83
+ * Removes the element at the specified index
84
+ */
85
+ export function remove<T>(id: PineArray<T>, index: simple_int): T {
86
+ return id.splice(index, 1)[0]!;
87
+ }
88
+
89
+ /**
90
+ * Returns true if the array contains the value
91
+ */
92
+ export function includes<T>(id: PineArray<T>, value: T): bool {
93
+ return id.includes(value);
94
+ }
95
+
96
+ /**
97
+ * Returns the index of the first occurrence of the value
98
+ */
99
+ export function indexof<T>(id: PineArray<T>, value: T): int {
100
+ return id.indexOf(value);
101
+ }
102
+
103
+ /**
104
+ * Returns the index of the last occurrence of the value
105
+ */
106
+ export function lastindexof<T>(id: PineArray<T>, value: T): int {
107
+ return id.lastIndexOf(value);
108
+ }
109
+
110
+ /**
111
+ * Returns a shallow copy of the array
112
+ */
113
+ export function copy<T>(id: PineArray<T>): PineArray<T> {
114
+ return [...id] as PineArray<T>;
115
+ }
116
+
117
+ /**
118
+ * Concatenates two arrays
119
+ */
120
+ export function concat<T>(id1: PineArray<T>, id2: PineArray<T>): PineArray<T> {
121
+ return [...id1, ...id2] as PineArray<T>;
122
+ }
123
+
124
+ /**
125
+ * Joins all elements into a string
126
+ */
127
+ export function join(id: PineArray<any>, separator: string = ','): string {
128
+ return id.join(separator);
129
+ }
130
+
131
+ /**
132
+ * Reverses the array in place
133
+ */
134
+ export function reverse<T>(id: PineArray<T>): void {
135
+ id.reverse();
136
+ }
137
+
138
+ /**
139
+ * Returns a slice of the array
140
+ */
141
+ export function slice<T>(id: PineArray<T>, index_from: simple_int, index_to?: simple_int): PineArray<T> {
142
+ return id.slice(index_from, index_to) as PineArray<T>;
143
+ }
144
+
145
+ /**
146
+ * Sorts array elements (numeric)
147
+ */
148
+ export function sort<T>(id: PineArray<T>, order: 'asc' | 'desc' = 'asc'): void {
149
+ id.sort((a, b) => {
150
+ if (order === 'asc') {
151
+ return (a as any) - (b as any);
152
+ } else {
153
+ return (b as any) - (a as any);
154
+ }
155
+ });
156
+ }
157
+
158
+ /**
159
+ * Returns the sum of all elements (numeric arrays only)
160
+ */
161
+ export function sum(id: PineArray<float>): float {
162
+ return id.reduce((acc, val) => acc + val, 0);
163
+ }
164
+
165
+ /**
166
+ * Returns the average of all elements (numeric arrays only)
167
+ */
168
+ export function avg(id: PineArray<float>): float {
169
+ return sum(id) / size(id);
170
+ }
171
+
172
+ /**
173
+ * The `nth` smallest value (0 = the smallest) of the non-na elements (PineScript `array.min(id, nth)`).
174
+ * An `nth` past the end gives the greatest value; an array without values gives NaN.
175
+ */
176
+ export function min(id: PineArray<float>, nth: simple_int = 0): float {
177
+ const values = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);
178
+ return values.length ? values[Math.min(nth, values.length - 1)]! : NaN;
179
+ }
180
+
181
+ /**
182
+ * The `nth` greatest value (0 = the greatest) of the non-na elements (PineScript `array.max(id, nth)`).
183
+ * An `nth` past the end gives the smallest value; an array without values gives NaN.
184
+ */
185
+ export function max(id: PineArray<float>, nth: simple_int = 0): float {
186
+ const values = id.filter((v) => !Number.isNaN(v)).sort((a, b) => b - a);
187
+ return values.length ? values[Math.min(nth, values.length - 1)]! : NaN;
188
+ }
189
+
190
+ /**
191
+ * Returns the median value (numeric arrays only)
192
+ */
193
+ export function median(id: PineArray<float>): float {
194
+ const sorted = [...id].sort((a, b) => a - b);
195
+ const mid = Math.floor(sorted.length / 2);
196
+ return sorted.length % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!;
197
+ }
198
+
199
+ /**
200
+ * Returns the mode (most frequent value)
201
+ */
202
+ export function mode(id: PineArray<float>): float {
203
+ const frequency: Map<float, int> = new Map();
204
+ let maxFreq = 0;
205
+ let mode = id[0]!;
206
+
207
+ for (const val of id) {
208
+ const freq = (frequency.get(val) || 0) + 1;
209
+ frequency.set(val, freq);
210
+ if (freq > maxFreq) {
211
+ maxFreq = freq;
212
+ mode = val;
213
+ }
214
+ }
215
+
216
+ return mode;
217
+ }
218
+
219
+ /**
220
+ * Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`).
221
+ * `biased` true (default) divides by the count, false by the count - 1.
222
+ */
223
+ export function stdev(id: PineArray<float>, biased: bool = true): float {
224
+ return Math.sqrt(variance(id, biased));
225
+ }
226
+
227
+ /**
228
+ * Variance of the non-na elements (PineScript `array.variance(id, biased)`).
229
+ * `biased` true (default) divides by the count, false by the count - 1.
230
+ */
231
+ export function variance(id: PineArray<float>, biased: bool = true): float {
232
+ const values = id.filter((v) => !Number.isNaN(v));
233
+ if (!values.length) return NaN;
234
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
235
+ const squares = values.reduce((a, b) => a + (b - mean) * (b - mean), 0);
236
+ return squares / (biased ? values.length : values.length - 1);
237
+ }
238
+
239
+ /**
240
+ * Fills the array with the specified value
241
+ */
242
+ export function fill<T>(id: PineArray<T>, value: T, index_from: simple_int = 0, index_to?: simple_int): void {
243
+ const end = index_to ?? id.length;
244
+ for (let i = index_from; i < end; i++) {
245
+ id[i] = value;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Creates an array from its arguments (PineScript `array.from(arg0, arg1, ...)`).
251
+ * `na` values are kept.
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * array.from(0.236, 0.382, 0.5, 0.618); // [0.236, 0.382, 0.5, 0.618]
256
+ * ```
257
+ */
258
+ export function from<T>(...values: T[]): PineArray<T> {
259
+ return [...values];
260
+ }
261
+
262
+ /**
263
+ * Returns the first element of the array
264
+ *
265
+ * @param id - The array
266
+ * @returns The first element, or undefined if array is empty
267
+ *
268
+ * @remarks
269
+ * - Equivalent to `array.get(id, 0)`
270
+ * - Returns undefined for empty arrays
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const arr = [1, 2, 3, 4, 5];
275
+ * const firstElement = array.first(arr); // Returns: 1
276
+ * ```
277
+ */
278
+ export function first<T>(id: PineArray<T>): T {
279
+ return id[0]!;
280
+ }
281
+
282
+ /**
283
+ * Returns the last element of the array
284
+ *
285
+ * @param id - The array
286
+ * @returns The last element, or undefined if array is empty
287
+ *
288
+ * @remarks
289
+ * - Equivalent to `array.get(id, array.size(id) - 1)`
290
+ * - Returns undefined for empty arrays
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const arr = [1, 2, 3, 4, 5];
295
+ * const lastElement = array.last(arr); // Returns: 5
296
+ * ```
297
+ */
298
+ export function last<T>(id: PineArray<T>): T {
299
+ return id[id.length - 1]!;
300
+ }
301
+
302
+ /**
303
+ * True when at least one element of a bool array is true (PineScript `array.some(id)`).
304
+ * An empty array gives false.
305
+ */
306
+ export function some(id: PineArray<bool>): bool {
307
+ return id.some((v) => v === true);
308
+ }
309
+
310
+ /**
311
+ * True when every element of a bool array is true (PineScript `array.every(id)`).
312
+ * An empty array gives false, as in PineScript.
313
+ */
314
+ export function every(id: PineArray<bool>): bool {
315
+ return id.length > 0 && id.every((v) => v === true);
316
+ }
317
+
318
+ /**
319
+ * Create new boolean array
320
+ *
321
+ * Creates a new array object of bool type elements.
322
+ *
323
+ * @param size - Initial size of array (default: 0)
324
+ * @param initial_value - Initial value for all elements (default: false)
325
+ * @returns New boolean array
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * const arr = array.new_bool(5, true);
330
+ * // Creates: [true, true, true, true, true]
331
+ * ```
332
+ */
333
+ export function new_bool(size: simple_int = 0, initial_value: bool = false): PineArray<bool> {
334
+ return new_array<bool>(size, initial_value);
335
+ }
336
+
337
+ /**
338
+ * Create new float array
339
+ *
340
+ * Creates a new array object of float type elements.
341
+ *
342
+ * @param size - Initial size of array (default: 0)
343
+ * @param initial_value - Initial value for all elements (default: NaN)
344
+ * @returns New float array
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * const arr = array.new_float(5, 0.0);
349
+ * // Creates: [0.0, 0.0, 0.0, 0.0, 0.0]
350
+ * ```
351
+ */
352
+ export function new_float(size: simple_int = 0, initial_value: float = NaN): PineArray<float> {
353
+ return new_array<float>(size, initial_value);
354
+ }
355
+
356
+ /**
357
+ * Create new integer array
358
+ *
359
+ * Creates a new array object of int type elements.
360
+ *
361
+ * @param size - Initial size of array (default: 0)
362
+ * @param initial_value - Initial value for all elements (default: NaN)
363
+ * @returns New integer array
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * const arr = array.new_int(5, 0);
368
+ * // Creates: [0, 0, 0, 0, 0]
369
+ * ```
370
+ */
371
+ export function new_int(size: simple_int = 0, initial_value: int = NaN): PineArray<int> {
372
+ return new_array<int>(size, initial_value);
373
+ }
374
+
375
+ /**
376
+ * Create new string array
377
+ *
378
+ * Creates a new array object of string type elements.
379
+ *
380
+ * @param size - Initial size of array (default: 0)
381
+ * @param initial_value - Initial value for all elements (default: undefined)
382
+ * @returns New string array
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const arr = array.new_string(5, "text");
387
+ * // Creates: ["text", "text", "text", "text", "text"]
388
+ * ```
389
+ */
390
+ export function new_string(size: simple_int = 0, initial_value?: string): PineArray<string> {
391
+ return new_array<string>(size, initial_value);
392
+ }
393
+
394
+ /**
395
+ * Create new color array
396
+ *
397
+ * Creates a new array object of color type elements.
398
+ *
399
+ * @param size - Initial size of array (default: 0)
400
+ * @param initial_value - Initial value for all elements (default: undefined)
401
+ * @returns New color array
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * const arr = array.new_color(5, "#FF0000");
406
+ * // Creates: ["#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000"]
407
+ * ```
408
+ */
409
+ export function new_color(size: simple_int = 0, initial_value?: color): PineArray<color> {
410
+ return new_array<color>(size, initial_value);
411
+ }
412
+
413
+ /**
414
+ * Create new line array
415
+ *
416
+ * Creates a new array object of line type elements.
417
+ *
418
+ * @param size - Initial size of array (default: 0)
419
+ * @param initial_value - Initial value for all elements (default: undefined)
420
+ * @returns New line array
421
+ *
422
+ * @example
423
+ * ```typescript
424
+ * import { array, line } from 'oakscriptjs';
425
+ *
426
+ * // Create array to store last 15 lines
427
+ * const lines = array.new_line();
428
+ * const trendLine = line.new(0, 100, 50, 150);
429
+ * array.push(lines, trendLine);
430
+ *
431
+ * // Manage line count
432
+ * if (array.size(lines) > 15) {
433
+ * const oldLine = array.shift(lines);
434
+ * }
435
+ * ```
436
+ *
437
+ * @remarks
438
+ * Useful for managing collections of trend lines, support/resistance levels, or channel lines.
439
+ * In PineScript, this is typically used with line.delete() to manage chart object limits.
440
+ */
441
+ export function new_line(size: simple_int = 0, initial_value?: Line): PineArray<Line> {
442
+ return new_array<Line>(size, initial_value);
443
+ }
444
+
445
+ /**
446
+ * Create new box array
447
+ *
448
+ * Creates a new array object of box type elements.
449
+ *
450
+ * @param size - Initial size of array (default: 0)
451
+ * @param initial_value - Initial value for all elements (default: undefined)
452
+ * @returns New box array
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * import { array, box } from 'oakscriptjs';
457
+ *
458
+ * // Create array to store gap boxes
459
+ * const gaps = array.new_box();
460
+ * const gapBox = box.new(10, 120, 15, 110);
461
+ * array.push(gaps, gapBox);
462
+ *
463
+ * // Track multiple gaps
464
+ * for (let i = 0; i < array.size(gaps); i++) {
465
+ * const gap = array.get(gaps, i);
466
+ * const gapTop = box.get_top(gap);
467
+ * const gapBottom = box.get_bottom(gap);
468
+ * // Check if gap filled...
469
+ * }
470
+ * ```
471
+ *
472
+ * @remarks
473
+ * Useful for tracking ranges, gaps, consolidation zones, or rectangle patterns.
474
+ * Enables systematic analysis of multiple box objects.
475
+ */
476
+ export function new_box(size: simple_int = 0, initial_value?: Box): PineArray<Box> {
477
+ return new_array<Box>(size, initial_value);
478
+ }
479
+
480
+ /**
481
+ * Create new label array
482
+ *
483
+ * Creates a new array object of label type elements.
484
+ *
485
+ * @param size - Initial size of array (default: 0)
486
+ * @param initial_value - Initial value for all elements (default: undefined)
487
+ * @returns New label array
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * import { array, label } from 'oakscriptjs';
492
+ *
493
+ * // Create array to store pivot labels
494
+ * const pivotLabels = array.new_label();
495
+ *
496
+ * // Add labels for pivot highs
497
+ * const pivotLabel = label.new(50, 155.5, 'PH', 'bar_index', 'abovebar');
498
+ * array.push(pivotLabels, pivotLabel);
499
+ *
500
+ * // Limit number of labels shown
501
+ * const maxLabels = 50;
502
+ * if (array.size(pivotLabels) > maxLabels) {
503
+ * array.shift(pivotLabels);
504
+ * }
505
+ * ```
506
+ *
507
+ * @remarks
508
+ * Useful for managing collections of annotations, pivot markers, or signal labels.
509
+ * Helps limit the number of labels displayed by removing old ones.
510
+ */
511
+ export function new_label(size: simple_int = 0, initial_value?: Label): PineArray<Label> {
512
+ return new_array<Label>(size, initial_value);
513
+ }
514
+
515
+ /**
516
+ * Create new linefill array
517
+ *
518
+ * Creates a new array object of linefill type elements.
519
+ *
520
+ * @param size - Initial size of array (default: 0)
521
+ * @param initial_value - Initial value for all elements (default: undefined)
522
+ * @returns New linefill array
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * import { array, line, linefill } from 'oakscriptjs';
527
+ *
528
+ * // Create array to store channel fills
529
+ * const channels = array.new_linefill();
530
+ *
531
+ * // Create channel
532
+ * const upperLine = line.new(0, 120, 50, 130);
533
+ * const lowerLine = line.new(0, 100, 50, 110);
534
+ * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF15');
535
+ *
536
+ * array.push(channels, channelFill);
537
+ * ```
538
+ *
539
+ * @remarks
540
+ * Useful for managing collections of channel fills, Bollinger Band fills, or regression channel fills.
541
+ * Enables dynamic color changes across multiple channels.
542
+ */
543
+ export function new_linefill(size: simple_int = 0, initial_value?: Linefill): PineArray<Linefill> {
544
+ return new_array<Linefill>(size, initial_value);
545
+ }
546
+
547
+ /**
548
+ * Absolute value of array elements
549
+ *
550
+ * Returns an array containing the absolute value of each element in the original array.
551
+ *
552
+ * @param id - Array of numeric values
553
+ * @returns New array with absolute values
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * const arr = [-1, -2, 3, -4, 5];
558
+ * const result = array.abs(arr);
559
+ * // Returns: [1, 2, 3, 4, 5]
560
+ * ```
561
+ */
562
+ export function abs(id: PineArray<float>): PineArray<float> {
563
+ return id.map(x => Math.abs(x)) as PineArray<float>;
564
+ }
565
+
566
+ /**
567
+ * Range of array values
568
+ *
569
+ * Returns the difference between the maximum and minimum values in the array.
570
+ *
571
+ * @param id - Array of numeric values
572
+ * @returns Difference between max and min (range)
573
+ *
574
+ * @example
575
+ * ```typescript
576
+ * const arr = [1, 5, 3, 9, 2];
577
+ * const result = array.range(arr);
578
+ * // Returns: 8 (9 - 1)
579
+ * ```
580
+ *
581
+ * @remarks
582
+ * Returns NaN if the array is empty.
583
+ */
584
+ export function range(id: PineArray<float>): float {
585
+ if (id.length === 0) {
586
+ return NaN;
587
+ }
588
+ return max(id) - min(id);
589
+ }
590
+
591
+ /**
592
+ * Binary Search
593
+ *
594
+ * Searches for a value in a sorted array using binary search algorithm.
595
+ * Returns the index of the value if found, or -1 if not found.
596
+ *
597
+ * @param id - Sorted array (ascending order)
598
+ * @param val - Value to search for
599
+ * @returns Index of the value, or -1 if not found
600
+ *
601
+ * @example
602
+ * ```typescript
603
+ * const arr = [-2, 0, 1, 5, 9]; // Must be sorted
604
+ * const index = array.binary_search(arr, 5);
605
+ * // Returns: 3
606
+ * ```
607
+ *
608
+ * @remarks
609
+ * - Array must be sorted in ascending order
610
+ * - Uses standard binary search algorithm
611
+ * - Time complexity: O(log n)
612
+ */
613
+ export function binary_search(id: PineArray<float>, val: float): int {
614
+ let left = 0;
615
+ let right = id.length - 1;
616
+
617
+ while (left <= right) {
618
+ const mid = Math.floor((left + right) / 2);
619
+
620
+ if (id[mid]! === val) {
621
+ return mid;
622
+ }
623
+
624
+ if (id[mid]! < val) {
625
+ left = mid + 1;
626
+ } else {
627
+ right = mid - 1;
628
+ }
629
+ }
630
+
631
+ return -1; // Not found
632
+ }
633
+
634
+ /**
635
+ * Binary Search Leftmost
636
+ *
637
+ * Returns the index of the value if found. When not found, returns the index
638
+ * of the next smallest element to the left of where the value would be.
639
+ *
640
+ * @param id - Sorted array (ascending order)
641
+ * @param val - Value to search for
642
+ * @returns Index of value or insertion point to the left
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * const arr = [-2, 0, 1, 5, 9];
647
+ * const index = array.binary_search_leftmost(arr, 3);
648
+ * // Returns: 2 (index of 1, which is left of where 3 would be)
649
+ * ```
650
+ *
651
+ * @example
652
+ * ```typescript
653
+ * const arr = [4, 5, 5, 5];
654
+ * const index = array.binary_search_leftmost(arr, 5);
655
+ * // Returns: 1 (index of first instance of 5)
656
+ * ```
657
+ *
658
+ * @remarks
659
+ * - Array must be sorted in ascending order
660
+ * - For duplicate values, returns leftmost occurrence
661
+ * - When value not found, returns position of next smaller element
662
+ */
663
+ export function binary_search_leftmost(id: PineArray<float>, val: float): int {
664
+ let left = 0;
665
+ let right = id.length - 1;
666
+ let result = -1;
667
+ let found = false;
668
+
669
+ while (left <= right) {
670
+ const mid = Math.floor((left + right) / 2);
671
+
672
+ if (id[mid]! < val) {
673
+ if (!found) {
674
+ result = mid; // Track the last element smaller than val (only if not found)
675
+ }
676
+ left = mid + 1;
677
+ } else if (id[mid]! === val) {
678
+ result = mid;
679
+ found = true;
680
+ // Continue searching to the left for leftmost occurrence
681
+ right = mid - 1;
682
+ } else {
683
+ // id[mid] > val
684
+ right = mid - 1;
685
+ }
686
+ }
687
+
688
+ return result;
689
+ }
690
+
691
+ /**
692
+ * Binary Search Rightmost
693
+ *
694
+ * Returns the index of the value if found. When not found, returns the index
695
+ * of the element to the right of where the value would be.
696
+ *
697
+ * @param id - Sorted array (ascending order)
698
+ * @param val - Value to search for
699
+ * @returns Index of value or insertion point to the right
700
+ *
701
+ * @example
702
+ * ```typescript
703
+ * const arr = [-2, 0, 1, 5, 9];
704
+ * const index = array.binary_search_rightmost(arr, 3);
705
+ * // Returns: 3 (index of 5, which is right of where 3 would be)
706
+ * ```
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * const arr = [4, 5, 5, 5];
711
+ * const index = array.binary_search_rightmost(arr, 5);
712
+ * // Returns: 3 (index of last instance of 5)
713
+ * ```
714
+ *
715
+ * @remarks
716
+ * - Array must be sorted in ascending order
717
+ * - For duplicate values, returns rightmost occurrence
718
+ * - When value not found, returns position of next larger element
719
+ */
720
+ export function binary_search_rightmost(id: PineArray<float>, val: float): int {
721
+ let left = 0;
722
+ let right = id.length - 1;
723
+ let result = -1;
724
+ let found = false;
725
+
726
+ while (left <= right) {
727
+ const mid = Math.floor((left + right) / 2);
728
+
729
+ if (id[mid]! <= val) {
730
+ if (id[mid]! === val) {
731
+ result = mid;
732
+ found = true;
733
+ }
734
+ // Continue searching to the right for rightmost occurrence
735
+ left = mid + 1;
736
+ } else {
737
+ // id[mid] > val
738
+ if (!found) {
739
+ result = mid; // Track the first element greater than val (only if not found)
740
+ }
741
+ right = mid - 1;
742
+ }
743
+ }
744
+
745
+ return result;
746
+ }
747
+
748
+ /**
749
+ * Covariance
750
+ *
751
+ * Returns the covariance between two arrays.
752
+ *
753
+ * @param id1 - First array
754
+ * @param id2 - Second array
755
+ * @param biased - If true, uses biased estimate (population). If false, uses unbiased estimate (sample). Default: true
756
+ * @returns Covariance between the two arrays
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * const prices = [100, 102, 98, 105, 103];
761
+ * const volume = [1000, 1200, 950, 1300, 1100];
762
+ * const cov = array.covariance(prices, volume);
763
+ * // Returns covariance between price and volume
764
+ * ```
765
+ *
766
+ * @remarks
767
+ * - Biased (true): divides by n (population covariance)
768
+ * - Unbiased (false): divides by n-1 (sample covariance)
769
+ * - Returns NaN if arrays are empty or have different lengths
770
+ * - Formula: Cov(X,Y) = E[(X - μX)(Y - μY)]
771
+ */
772
+ export function covariance(id1: PineArray<float>, id2: PineArray<float>, biased: bool = true): float {
773
+ if (id1.length === 0 || id2.length === 0) {
774
+ return NaN;
775
+ }
776
+
777
+ if (id1.length !== id2.length) {
778
+ return NaN;
779
+ }
780
+
781
+ const n = id1.length;
782
+ const mean1 = avg(id1);
783
+ const mean2 = avg(id2);
784
+
785
+ let sum = 0;
786
+ for (let i = 0; i < n; i++) {
787
+ sum += (id1[i]! - mean1) * (id2[i]! - mean2);
788
+ }
789
+
790
+ // Biased: divide by n, Unbiased: divide by n-1
791
+ const divisor = biased ? n : n - 1;
792
+ return sum / divisor;
793
+ }
794
+
795
+ /**
796
+ * Percentile Linear Interpolation
797
+ *
798
+ * Returns the value for which the specified percentage of array values are
799
+ * less than or equal to it, using linear interpolation.
800
+ *
801
+ * @param id - Array of numeric values
802
+ * @param percentage - Percentage (0-100)
803
+ * @returns Percentile value using linear interpolation
804
+ *
805
+ * @example
806
+ * ```typescript
807
+ * const arr = [1, 2, 3, 4, 5];
808
+ * const p50 = array.percentile_linear_interpolation(arr, 50);
809
+ * // Returns: 3 (median)
810
+ * ```
811
+ *
812
+ * @remarks
813
+ * - Uses linear interpolation between adjacent values
814
+ * - Result may not be a member of the array
815
+ * - Returns NaN if array is empty
816
+ *
817
+ * PineScript rules:
818
+ * - position in the sorted array: `percentage / 100 * size - 0.5`, clamped to the first / last value, linear
819
+ * interpolation between the two neighbours
820
+ * - `na` values are sorted after all numbers; with an `na` in the array, a position between two values gives `na`
821
+ */
822
+ export function percentile_linear_interpolation(id: PineArray<float>, percentage: float): float {
823
+ if (id.length === 0) {
824
+ return NaN;
825
+ }
826
+ const s = sortedNaLast(id);
827
+ const n = s.length;
828
+ const pos = (percentage / 100) * n - 0.5;
829
+ if (pos <= 0) return s[0]!;
830
+ if (pos >= n - 1) return s[n - 1]!;
831
+ const lo = Math.floor(pos);
832
+ const f = pos - lo;
833
+ if (f === 0) return s[lo]!;
834
+ return Number.isNaN(s[n - 1]!) ? NaN : s[lo]! + f * (s[lo + 1]! - s[lo]!);
835
+ }
836
+
837
+ /** Array values sorted ascending, `na` values after the numbers (array.percentile_*). */
838
+ function sortedNaLast(id: PineArray<float>): number[] {
839
+ const numbers = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);
840
+ return [...numbers, ...Array<number>(id.length - numbers.length).fill(NaN)];
841
+ }
842
+
843
+ /**
844
+ * Percentile Nearest Rank
845
+ *
846
+ * Returns the value for which the specified percentage of array values are
847
+ * less than or equal to it, using the nearest-rank method.
848
+ *
849
+ * @param id - Array of numeric values
850
+ * @param percentage - Percentage (0-100)
851
+ * @returns Percentile value using nearest rank
852
+ *
853
+ * @example
854
+ * ```typescript
855
+ * const arr = [1, 2, 3, 4, 5];
856
+ * const p50 = array.percentile_nearest_rank(arr, 50);
857
+ * // Returns: 3 (median, always a member of array)
858
+ * ```
859
+ *
860
+ * @remarks
861
+ * - Result is always a member of the array
862
+ * - Uses nearest-rank method (no interpolation)
863
+ * - Returns NaN if array is empty
864
+ *
865
+ * PineScript rules:
866
+ * - the value at rank `ceil(percentage / 100 * size)` of the sorted array
867
+ * - `na` values are sorted after all numbers (na when that rank holds an `na`)
868
+ */
869
+ export function percentile_nearest_rank(id: PineArray<float>, percentage: float): float {
870
+ if (id.length === 0) {
871
+ return NaN;
872
+ }
873
+ const s = sortedNaLast(id);
874
+ const rank = Math.min(s.length, Math.max(1, Math.ceil((percentage / 100) * s.length)));
875
+ return s[rank - 1]!;
876
+ }
877
+
878
+ /**
879
+ * Percent Rank
880
+ *
881
+ * Returns the percentile rank of the element at the specified index.
882
+ * The percentile rank is the percentage of elements that are less than
883
+ * or equal to the reference value.
884
+ *
885
+ * @param id - Array of numeric values
886
+ * @param index - Index of element to rank
887
+ * @returns Percentile rank (0-100)
888
+ *
889
+ * @example
890
+ * ```typescript
891
+ * const arr = [1, 2, 3, 4, 5];
892
+ * const rank = array.percentrank(arr, 2); // Value at index 2 is 3
893
+ * // Returns: 40 (40% of values <= 3)
894
+ * ```
895
+ *
896
+ * @remarks
897
+ * - Returns percentage of elements <= the value at given index
898
+ * - Range: 0 to 100
899
+ * - Returns NaN if array is empty or index out of bounds
900
+ */
901
+ export function percentrank(id: PineArray<float>, index: int): float {
902
+ if (id.length === 0 || index < 0 || index >= id.length) {
903
+ return NaN;
904
+ }
905
+
906
+ const value = id[index]!;
907
+
908
+ if (isNaN(value)) {
909
+ return NaN;
910
+ }
911
+
912
+ // Count elements less than or equal to the value
913
+ let count = 0;
914
+ for (let i = 0; i < id.length; i++) {
915
+ if (!isNaN(id[i]!) && id[i]! <= value) {
916
+ count++;
917
+ }
918
+ }
919
+
920
+ // Calculate percentage
921
+ return (count / id.length) * 100;
922
+ }
923
+
924
+ /**
925
+ * Sort Indices
926
+ *
927
+ * Returns an array of indices which, when used to index the original array,
928
+ * will access its elements in their sorted order. Does not modify the original array.
929
+ *
930
+ * @param id - Array to get sorted indices from
931
+ * @param order - Sort order: 'asc' or 'desc' (default: 'asc')
932
+ * @returns Array of indices in sorted order
933
+ *
934
+ * @example
935
+ * ```typescript
936
+ * const arr = [5, -2, 0, 9, 1];
937
+ * const indices = array.sort_indices(arr); // [1, 2, 4, 0, 3]
938
+ * // arr[1] = -2 (smallest)
939
+ * // arr[2] = 0
940
+ * // arr[4] = 1
941
+ * // arr[0] = 5
942
+ * // arr[3] = 9 (largest)
943
+ * ```
944
+ *
945
+ * @remarks
946
+ * - Original array is not modified
947
+ * - Returns indices that would sort the array
948
+ * - Useful for maintaining correspondence with other arrays
949
+ */
950
+ export function sort_indices(id: PineArray<float>, order: 'asc' | 'desc' = 'asc'): PineArray<int> {
951
+ // Create array of indices
952
+ const indices: PineArray<int> = Array.from({ length: id.length }, (_, i) => i) as PineArray<int>;
953
+
954
+ // Sort indices based on values in original array
955
+ indices.sort((a, b) => {
956
+ if (order === 'asc') {
957
+ return id[a]! - id[b]!;
958
+ } else {
959
+ return id[b]! - id[a]!;
960
+ }
961
+ });
962
+
963
+ return indices;
964
+ }
965
+
966
+ /**
967
+ * Standardize
968
+ *
969
+ * Returns an array of standardized elements (z-score normalization).
970
+ * Each element is transformed to (value - mean) / stddev.
971
+ *
972
+ * @param id - Array of numeric values
973
+ * @returns Array of standardized values (z-scores)
974
+ *
975
+ * @example
976
+ * ```typescript
977
+ * const arr = [1, 2, 3, 4, 5];
978
+ * const standardized = array.standardize(arr);
979
+ * // Mean = 3, StdDev ≈ 1.414
980
+ * // Result ≈ [-1.414, -0.707, 0, 0.707, 1.414]
981
+ * ```
982
+ *
983
+ * @remarks
984
+ * - Formula: z = (x - μ) / σ
985
+ * - Result has mean of 0 and standard deviation of 1
986
+ * - Returns array of NaN if standard deviation is 0
987
+ * - Useful for comparing values on different scales
988
+ */
989
+ export function standardize(id: PineArray<float>): PineArray<float> {
990
+ if (id.length === 0) {
991
+ return [] as PineArray<float>;
992
+ }
993
+
994
+ const mean = avg(id);
995
+ const stdDev = stdev(id);
996
+
997
+ // If stddev is 0, all values are the same - return array of 0s or NaN
998
+ if (stdDev === 0) {
999
+ return id.map(() => NaN) as PineArray<float>;
1000
+ }
1001
+
1002
+ // Calculate z-score for each element
1003
+ return id.map(value => (value - mean) / stdDev) as PineArray<float>;
1004
+ }
1005
+
1006
+ /**
1007
+ * New Type (User-Defined Type Array)
1008
+ *
1009
+ * Creates a new array of user-defined type elements.
1010
+ *
1011
+ * @param size - Initial size of array (default: 0)
1012
+ * @param initial_value - Initial value for all elements
1013
+ * @returns New array of user-defined type
1014
+ *
1015
+ * @example
1016
+ * ```typescript
1017
+ * // NOTE: User-defined types (UDTs) are not fully supported yet
1018
+ * // This is a placeholder for future implementation
1019
+ * const arr = array.newtype<MyType>(5);
1020
+ * ```
1021
+ *
1022
+ * @remarks
1023
+ * - **⚠️ LIMITED SUPPORT**: User-defined types (UDTs) require a type system
1024
+ * that is not yet fully implemented in this library
1025
+ * - This function currently works like `new_array<T>()` for basic types
1026
+ * - Full UDT support will be added in a future version
1027
+ * - See PineScript documentation for UDT usage patterns
1028
+ */
1029
+ export function newtype<T>(size: simple_int = 0, initial_value?: T): PineArray<T> {
1030
+ // For now, this is just an alias for new_array
1031
+ // Full UDT support requires implementing the type system
1032
+ return new_array<T>(size, initial_value);
1033
+ }
1034
+
1035
+ /**
1036
+ * ⚠️ RENDERING FUNCTIONS NOT IMPLEMENTED
1037
+ *
1038
+ * The following array constructor functions are intentionally excluded
1039
+ * because they create arrays for rendering objects, which are outside
1040
+ * the scope of this calculation-focused library:
1041
+ *
1042
+ * - `new_box()` - Creates arrays of box drawing objects
1043
+ * - `new_label()` - Creates arrays of label objects
1044
+ * - `new_line()` - Creates arrays of line drawing objects
1045
+ * - `new_linefill()` - Creates arrays of line fill objects
1046
+ * - `new_table()` - Creates arrays of table layout objects
1047
+ *
1048
+ * **Design Constraint**: This library focuses on calculation and indicator
1049
+ * functions only. Rendering, visualization, and UI functions require a
1050
+ * rendering engine and are not included.
1051
+ *
1052
+ * If you need these functions, consider:
1053
+ * 1. Using PineScript directly
1054
+ * 2. Implementing a rendering layer separately
1055
+ * 3. Using this library for calculations and another library for visualization
1056
+ */