oakscriptjs 0.8.2 → 0.9.1

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