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,557 @@
1
+ /**
2
+ * String namespace
3
+ * Mirrors PineScript's str.* functions for string manipulation and analysis.
4
+ *
5
+ * @remarks
6
+ * All string functions in this namespace follow PineScript v6 API specifications.
7
+ * String operations are case-sensitive unless otherwise specified.
8
+ *
9
+ * @version 6
10
+ */
11
+
12
+ import { formatNumber } from './numberformat.js';
13
+ import { formatMessage } from './messageformat.js';
14
+ import { formatDate } from './dateformat.js';
15
+ import type { int, bool, float, simple_int, simple_string } from '../types/index.js';
16
+
17
+ /**
18
+ * Returns the length of a string.
19
+ *
20
+ * @param str - The string to measure
21
+ * @returns The number of characters in the string
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * str.length("Hello") // Returns: 5
26
+ * str.length("") // Returns: 0
27
+ * ```
28
+ */
29
+ export function length(str: simple_string): int {
30
+ return str.length;
31
+ }
32
+
33
+ /**
34
+ * Converts a value to its string representation (PineScript `str.tostring`).
35
+ *
36
+ * @param value - The value to convert (number, boolean, string, etc.)
37
+ * @param format - Optional number format: a pattern ("#.##", "#,###.00", "0.00%", "0.00E0") or
38
+ * `format.percent` ("percent"), `format.volume` ("volume"), `format.price` / `format.inherit`
39
+ * @returns String representation of the value
40
+ *
41
+ * @remarks
42
+ * As in PineScript:
43
+ * - without format, numbers show up to 10 decimals ("0.3333333333"); 1e21 and more use "1E21"
44
+ * - patterns round half away from zero on the shortest decimal form: 1.005 with "#.##" gives "1.01"
45
+ * - "#" is an optional digit ("1.5" with "#.##"), "0" a required digit ("1.50" with "0.00"),
46
+ * "," groups thousands, "%" multiplies by 100, 'text' is literal text
47
+ * - `format.percent` shows 2 decimals and "%" without multiplying; `format.volume` uses K, M, B, T
48
+ * - `format.price` and `format.inherit` give "price1" / "inherit1" in PineScript: they are patterns
49
+ * without digit characters, and oakscriptjs does the same
50
+ * - `format.mintick` needs the symbol's tick size and throws here
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * str.tostring(123) // "123"
55
+ * str.tostring(1.5, "#.##") // "1.5"
56
+ * str.tostring(0.5, "#.00") // ".50"
57
+ * str.tostring(12345.678, format.volume) // "12.346K"
58
+ * ```
59
+ */
60
+ export function tostring(value: any, format?: simple_string): string {
61
+ if (typeof value !== 'number') return String(value);
62
+ if (!Number.isFinite(value)) return String(value); // NaN (na), Infinity
63
+ if (format === undefined || format === '') {
64
+ if (Math.abs(value) >= 1e21 && Number.isFinite(value)) {
65
+ return String(value).replace('e+', 'E').replace(/\.0+E/, 'E');
66
+ }
67
+ return formatNumber(value, '#.##########', 'halfUpShortest');
68
+ }
69
+ switch (format) {
70
+ case 'percent':
71
+ return formatNumber(value, '0.00', 'halfUpShortest') + '%';
72
+ case 'volume': {
73
+ const abs = Math.abs(value);
74
+ for (const [size, unit] of [[1e12, 'T'], [1e9, 'B'], [1e6, 'M'], [1e3, 'K']] as const) {
75
+ if (abs >= size) return formatNumber(value / size, '#.###', 'halfUpShortest') + unit;
76
+ }
77
+ return formatNumber(value, '#', 'halfUpShortest');
78
+ }
79
+ case 'mintick':
80
+ throw new Error('str.tostring(x, format.mintick) needs the symbol tick size (syminfo.mintick), which is not known here');
81
+ default:
82
+ return formatNumber(value, format, 'halfUpShortest');
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Converts a string to a number (float).
88
+ *
89
+ * @param str - The string to convert
90
+ * @returns The numeric value, or null if conversion fails
91
+ *
92
+ * @remarks
93
+ * - Returns null for invalid number strings
94
+ * - Supports scientific notation (e.g., "1e3")
95
+ * - Supports decimal numbers (e.g., "0.5", ".5")
96
+ * - Whitespace is ignored
97
+ * - "NaN" string returns null
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * str.tonumber("123") // Returns: 123
102
+ * str.tonumber("45.67") // Returns: 45.67
103
+ * str.tonumber("abc") // Returns: null
104
+ * str.tonumber("1e3") // Returns: 1000
105
+ * ```
106
+ */
107
+ export function tonumber(str: simple_string): float | null {
108
+ const num = parseFloat(str);
109
+ return isNaN(num) ? null : num;
110
+ }
111
+
112
+ /**
113
+ * Extracts a substring from a string.
114
+ *
115
+ * @param str - The source string
116
+ * @param begin - Starting index (0-based, inclusive)
117
+ * @param end - Ending index (0-based, exclusive). If omitted, extracts to end of string
118
+ * @returns The extracted substring
119
+ *
120
+ * @remarks
121
+ * - If begin > end, indices are swapped (JavaScript behavior)
122
+ * - Negative indices are treated as 0
123
+ * - Indices beyond string length return empty string
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * str.substring("hello world", 0, 5) // Returns: "hello"
128
+ * str.substring("hello world", 6) // Returns: "world"
129
+ * str.substring("test", 1, 3) // Returns: "es"
130
+ * ```
131
+ */
132
+ export function substring(str: simple_string, begin: simple_int, end?: simple_int): string {
133
+ return str.substring(begin, end);
134
+ }
135
+
136
+ /**
137
+ * Converts all characters in a string to uppercase.
138
+ *
139
+ * @param str - The string to convert
140
+ * @returns The uppercase string
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * str.upper("hello") // Returns: "HELLO"
145
+ * str.upper("Hello World") // Returns: "HELLO WORLD"
146
+ * str.upper("test123") // Returns: "TEST123"
147
+ * ```
148
+ */
149
+ export function upper(str: simple_string): string {
150
+ return str.toUpperCase();
151
+ }
152
+
153
+ /**
154
+ * Converts all characters in a string to lowercase.
155
+ *
156
+ * @param str - The string to convert
157
+ * @returns The lowercase string
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * str.lower("HELLO") // Returns: "hello"
162
+ * str.lower("Hello World") // Returns: "hello world"
163
+ * str.lower("TEST123") // Returns: "test123"
164
+ * ```
165
+ */
166
+ export function lower(str: simple_string): string {
167
+ return str.toLowerCase();
168
+ }
169
+
170
+ /**
171
+ * Checks if a string contains a substring.
172
+ *
173
+ * @param source - The string to search in
174
+ * @param str - The substring to search for
175
+ * @returns True if source contains str, false otherwise
176
+ *
177
+ * @remarks
178
+ * - Search is case-sensitive
179
+ * - Empty string is contained in any string
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * str.contains("hello world", "world") // Returns: true
184
+ * str.contains("hello world", "World") // Returns: false (case-sensitive)
185
+ * str.contains("test", "xyz") // Returns: false
186
+ * ```
187
+ */
188
+ export function contains(source: simple_string, str: simple_string): bool {
189
+ return source.includes(str);
190
+ }
191
+
192
+ /**
193
+ * Returns the position of the first occurrence of a substring.
194
+ *
195
+ * @param source - The string to search in
196
+ * @param str - The substring to search for
197
+ * @returns The 0-based index of the first occurrence, or -1 if not found
198
+ *
199
+ * @remarks
200
+ * - Search is case-sensitive
201
+ * - Returns 0 for empty search string
202
+ * - Returns -1 if substring is not found
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * str.pos("hello world", "world") // Returns: 6
207
+ * str.pos("hello world", "o") // Returns: 4 (first occurrence)
208
+ * str.pos("hello", "xyz") // Returns: -1
209
+ * ```
210
+ */
211
+ export function pos(source: simple_string, str: simple_string): int {
212
+ return source.indexOf(str);
213
+ }
214
+
215
+ /**
216
+ * Replaces occurrences of a substring with another string.
217
+ *
218
+ * @param source - The source string
219
+ * @param target - The substring to replace
220
+ * @param replacement - The string to replace with
221
+ * @param occurrence - If 0, replaces first occurrence only; otherwise replaces all occurrences (default: all)
222
+ * @returns The string with replacements made
223
+ *
224
+ * @remarks
225
+ * - Search is case-sensitive
226
+ * - If target is not found, returns source unchanged
227
+ * - occurrence parameter: 0 = first only, any other value = all occurrences
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * str.replace("hello world hello", "hello", "hi", 0) // Returns: "hi world hello"
232
+ * str.replace("hello world hello", "hello", "hi") // Returns: "hi world hi"
233
+ * str.replace("test", "xyz", "abc") // Returns: "test"
234
+ * ```
235
+ */
236
+ export function replace(source: simple_string, target: simple_string, replacement: simple_string, occurrence?: simple_int): string {
237
+ if (occurrence === 0) {
238
+ return source.replace(target, replacement);
239
+ } else {
240
+ return source.replaceAll(target, replacement);
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Replaces all occurrences of a target string with a replacement string.
246
+ *
247
+ * @param source - The source string
248
+ * @param target - The substring to find
249
+ * @param replacement - The replacement string
250
+ * @returns String with all occurrences replaced
251
+ *
252
+ * @remarks
253
+ * - Replaces all occurrences of the target string
254
+ * - Case sensitive
255
+ * - If target is empty string, returns original string
256
+ * - This matches PineScript's `str.replace_all()` behavior
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * str.replace_all("hello world hello", "hello", "hi") // Returns: "hi world hi"
261
+ * str.replace_all("a-b-c", "-", "_") // Returns: "a_b_c"
262
+ * str.replace_all("test", "x", "y") // Returns: "test" (no match)
263
+ * ```
264
+ */
265
+ export function replace_all(source: simple_string, target: simple_string, replacement: simple_string): string {
266
+ return source.replaceAll(target, replacement);
267
+ }
268
+
269
+ /**
270
+ * Splits a string into an array of substrings using a separator.
271
+ *
272
+ * @param str - The string to split
273
+ * @param separator - The separator string
274
+ * @returns Array of substrings
275
+ *
276
+ * @remarks
277
+ * - Empty separator splits into individual characters
278
+ * - If separator is not found, returns array with original string
279
+ * - Consecutive separators create empty strings in result
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * str.split("a,b,c", ",") // Returns: ["a", "b", "c"]
284
+ * str.split("hello", "") // Returns: ["h", "e", "l", "l", "o"]
285
+ * str.split("a,,b", ",") // Returns: ["a", "", "b"]
286
+ * ```
287
+ */
288
+ export function split(str: simple_string, separator: simple_string): string[] {
289
+ return str.split(separator);
290
+ }
291
+
292
+ /**
293
+ * Concatenates multiple strings into one.
294
+ *
295
+ * @param strings - Variable number of strings to concatenate
296
+ * @returns The concatenated string
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * str.concat("hello", " ", "world") // Returns: "hello world"
301
+ * str.concat("a", "b", "c") // Returns: "abc"
302
+ * str.concat("test") // Returns: "test"
303
+ * ```
304
+ */
305
+ export function concat(...strings: simple_string[]): string {
306
+ return strings.join('');
307
+ }
308
+
309
+ /**
310
+ * Formats a string with placeholders (PineScript `str.format`, Java MessageFormat syntax).
311
+ *
312
+ * @param formatStr - Pattern with `{0}`, `{1,number,#.##}`, `{0,number,percent}`, `{0,date,yyyy-MM-dd}`...
313
+ * @param args - Values for the placeholders
314
+ * @returns Formatted string
315
+ *
316
+ * @remarks
317
+ * As in PineScript: numbers in `{n}` use
318
+ * "#,##0.###" (1234.5678 gives "1,234.568"); number patterns round half to even on the exact
319
+ * value; `'...'` is literal text and `''` a quote; a missing argument leaves `{n}` in the text.
320
+ * Dates are formatted in UTC here; PineScript uses the exchange time zone.
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * str.format('Close: {0,number,#.##}', 101.456) // "Close: 101.46"
325
+ * str.format('{0} and {1}', 'a', 2) // "a and 2"
326
+ * ```
327
+ */
328
+ export function format(formatStr: simple_string, ...args: any[]): string {
329
+ return formatMessage(formatStr, args, 'Etc/UTC');
330
+ }
331
+
332
+ /**
333
+ * Checks if a string starts with a specific prefix.
334
+ *
335
+ * @param source - The string to check
336
+ * @param str - The prefix to look for
337
+ * @returns True if source starts with str, false otherwise
338
+ *
339
+ * @remarks
340
+ * - Search is case-sensitive
341
+ * - Empty string prefix always returns true
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * str.startswith("hello world", "hello") // Returns: true
346
+ * str.startswith("hello world", "Hello") // Returns: false (case-sensitive)
347
+ * str.startswith("test", "testing") // Returns: false
348
+ * ```
349
+ */
350
+ export function startswith(source: simple_string, str: simple_string): bool {
351
+ return source.startsWith(str);
352
+ }
353
+
354
+ /**
355
+ * Checks if a string ends with a specific suffix.
356
+ *
357
+ * @param source - The string to check
358
+ * @param str - The suffix to look for
359
+ * @returns True if source ends with str, false otherwise
360
+ *
361
+ * @remarks
362
+ * - Search is case-sensitive
363
+ * - Empty string suffix always returns true
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * str.endswith("hello world", "world") // Returns: true
368
+ * str.endswith("hello world", "World") // Returns: false (case-sensitive)
369
+ * str.endswith("testing", "test") // Returns: false
370
+ * ```
371
+ */
372
+ export function endswith(source: simple_string, str: simple_string): bool {
373
+ return source.endsWith(str);
374
+ }
375
+
376
+ /**
377
+ * Returns the character at a specific position in a string.
378
+ *
379
+ * @param str - The source string
380
+ * @param pos - The 0-based position
381
+ * @returns The character at the position, or empty string if out of bounds
382
+ *
383
+ * @remarks
384
+ * - Returns empty string for negative or out-of-bounds positions
385
+ * - Unicode characters may span multiple code units
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * str.charAt("hello", 0) // Returns: "h"
390
+ * str.charAt("hello", 4) // Returns: "o"
391
+ * str.charAt("hello", 10) // Returns: ""
392
+ * ```
393
+ */
394
+ export function charAt(str: simple_string, pos: simple_int): string {
395
+ return str.charAt(pos);
396
+ }
397
+
398
+ /**
399
+ * Removes whitespace from both ends of a string.
400
+ *
401
+ * @param str - The string to trim
402
+ * @returns The trimmed string
403
+ *
404
+ * @remarks
405
+ * - Removes spaces, tabs, newlines, and other whitespace characters
406
+ * - Preserves internal whitespace
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * str.trim(" hello ") // Returns: "hello"
411
+ * str.trim(" hello world ") // Returns: "hello world"
412
+ * str.trim("\thello\n") // Returns: "hello"
413
+ * ```
414
+ */
415
+ export function trim(str: simple_string): string {
416
+ return str.trim();
417
+ }
418
+
419
+ /**
420
+ * Removes whitespace from the left (start) of a string.
421
+ *
422
+ * @param str - The string to trim
423
+ * @returns The trimmed string
424
+ *
425
+ * @remarks
426
+ * - Only removes leading whitespace
427
+ * - Preserves trailing and internal whitespace
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * str.trimLeft(" hello ") // Returns: "hello "
432
+ * str.trimLeft(" hello") // Returns: "hello"
433
+ * str.trimLeft("\thello") // Returns: "hello"
434
+ * ```
435
+ */
436
+ export function trimLeft(str: simple_string): string {
437
+ return str.trimStart();
438
+ }
439
+
440
+ /**
441
+ * Removes whitespace from the right (end) of a string.
442
+ *
443
+ * @param str - The string to trim
444
+ * @returns The trimmed string
445
+ *
446
+ * @remarks
447
+ * - Only removes trailing whitespace
448
+ * - Preserves leading and internal whitespace
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * str.trimRight(" hello ") // Returns: " hello"
453
+ * str.trimRight("hello ") // Returns: "hello"
454
+ * str.trimRight("hello\t") // Returns: "hello"
455
+ * ```
456
+ */
457
+ export function trimRight(str: simple_string): string {
458
+ return str.trimEnd();
459
+ }
460
+
461
+ /**
462
+ * Tests if a string matches a regular expression pattern.
463
+ *
464
+ * @param source - The string to test
465
+ * @param regex - The regular expression pattern
466
+ * @returns True if the pattern matches, false otherwise
467
+ *
468
+ * @remarks
469
+ * - Uses JavaScript regex syntax
470
+ * - Match is case-sensitive by default
471
+ * - Pattern is tested against entire string
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * str.match("hello123", "\\d+") // Returns: true
476
+ * str.match("test@example.com", "^[a-z]+@[a-z]+\\.[a-z]+$") // Returns: true
477
+ * str.match("abc", "[A-Z]+") // Returns: false
478
+ * ```
479
+ */
480
+ export function match(source: simple_string, regex: simple_string): bool {
481
+ return new RegExp(regex).test(source);
482
+ }
483
+
484
+ /**
485
+ * Formats a timestamp as a string according to the specified format.
486
+ *
487
+ * @param time - Unix timestamp in milliseconds
488
+ * @param format - Format string using PineScript format specifiers
489
+ * @returns Formatted date/time string
490
+ *
491
+ * @remarks
492
+ * Supported format specifiers (case-sensitive):
493
+ * - `yyyy` - 4-digit year (e.g., "2024")
494
+ * - `yy` - 2-digit year (e.g., "24")
495
+ * - `MMMM` - Full month name (e.g., "January")
496
+ * - `MMM` - Abbreviated month name (e.g., "Jan")
497
+ * - `MM` - 2-digit month (01-12)
498
+ * - `M` - Month (1-12)
499
+ * - `dd` - 2-digit day (01-31)
500
+ * - `d` - Day (1-31)
501
+ * - `HH` - 2-digit hour (00-23)
502
+ * - `H` - Hour (0-23)
503
+ * - `hh` - 2-digit hour (01-12)
504
+ * - `h` - Hour (1-12)
505
+ * - `mm` - 2-digit minute (00-59)
506
+ * - `m` - Minute (0-59)
507
+ * - `ss` - 2-digit second (00-59)
508
+ * - `s` - Second (0-59)
509
+ * - `a` - AM/PM
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const timestamp = 1609459200000; // Jan 1, 2021 00:00:00 UTC
514
+ * str.format_time(timestamp, "dd MMM yyyy") // Returns: "01 Jan 2021"
515
+ * str.format_time(timestamp, "yyyy-MM-dd HH:mm:ss") // Returns: "2021-01-01 00:00:00"
516
+ * str.format_time(timestamp, "MMM d, yyyy") // Returns: "Jan 1, 2021"
517
+ * str.format_time(timestamp, "hh:mm a") // Returns: "12:00 AM"
518
+ * ```
519
+ */
520
+ /**
521
+ * Constructs a new string containing the source string repeated N times with an optional separator.
522
+ *
523
+ * @param source - The string to repeat
524
+ * @param count - Number of times to repeat (must be >= 0)
525
+ * @param separator - String to inject between repeated instances. Optional, defaults to empty string.
526
+ * @returns The repeated string, or null if source is null/undefined
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * str.repeat("ab", 3) // Returns: "ababab"
531
+ * str.repeat("?", 3, ",") // Returns: "?,?,?"
532
+ * str.repeat("hello", 0) // Returns: ""
533
+ * str.repeat("x", 1) // Returns: "x"
534
+ * ```
535
+ */
536
+ export function repeat(source: simple_string, count: simple_int, separator: simple_string = ''): string | null {
537
+ if (source == null) return null;
538
+ if (count <= 0) return '';
539
+ return Array(count).fill(source).join(separator);
540
+ }
541
+
542
+ /**
543
+ * Formats a UNIX time (ms) with a date pattern (PineScript `str.format_time`).
544
+ *
545
+ * @param time - UNIX time in milliseconds
546
+ * @param format - Java SimpleDateFormat pattern, e.g. "yyyy-MM-dd HH:mm:ss", "dd MMM yyyy", "hh:mm a"
547
+ * @param timezone - UTC/GMT offset ("UTC-5") or IANA name ("America/New_York"). PineScript's default is
548
+ * the exchange time zone, which is not known here: the default is UTC
549
+ * @returns Formatted date string
550
+ *
551
+ * @remarks
552
+ * Letters: y, M, d, E, u, D, w,
553
+ * H, k, K, h, a, m, s, S, Z, z; 'text' is literal text.
554
+ */
555
+ export function format_time(time: simple_int, format: simple_string = "yyyy-MM-dd'T'HH:mm:ssZ", timezone: simple_string = 'Etc/UTC'): string {
556
+ return formatDate(time, format, timezone);
557
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * `str.format` patterns as PineScript formats them (Java MessageFormat):
3
+ *
4
+ * - `{n}` inserts argument n; numbers use "#,##0.###" (1234.5678 gives "1,234.568")
5
+ * - `{n,number}`, `{n,number,integer}` ("#,##0"), `{n,number,percent}` ("#,##0%"),
6
+ * `{n,number,currency}` ("$1,234.57", "-$7.00"), `{n,number,<pattern>}`
7
+ * - `{n,date}`, `{n,time}`, `{n,date,<pattern>}`, `{n,time,<pattern>}` (styles short, medium, long, full)
8
+ * - `{n,choice,0#zero|1#one|1<many}`
9
+ * - numbers round half to even on the exact binary value (0.5 as integer gives "0")
10
+ * - `'...'` is literal text and `''` is a quote; a missing argument leaves `{n}` in the text
11
+ */
12
+
13
+ import { formatNumber } from './numberformat.js';
14
+ import { formatDate } from './dateformat.js';
15
+
16
+ const DATE_STYLES: Record<string, string> = {
17
+ short: 'M/d/yy', medium: 'MMM d, yyyy', long: 'MMMM d, yyyy', full: 'EEEE, MMMM d, yyyy',
18
+ };
19
+ // PineScript writes a narrow no-break space (U+202F) before AM/PM in the time styles
20
+ const TIME_STYLES: Record<string, string> = {
21
+ short: 'h:mm a', medium: 'h:mm:ss a', long: 'h:mm:ss a z', full: 'h:mm:ss a z',
22
+ };
23
+
24
+ function number(value: unknown, pattern: string): string {
25
+ return typeof value === 'number' ? formatNumber(value, pattern, 'halfEvenExact') : String(value);
26
+ }
27
+
28
+ function choice(value: number, spec: string): string {
29
+ const options = spec.split('|').map((part) => {
30
+ const m = /^\s*(-?[\d.]+|-?∞)\s*([#<≤])(.*)$/.exec(part);
31
+ if (!m) throw new SyntaxError(`Invalid choice format "${spec}"`);
32
+ const limit = m[1]!.includes('∞') ? (m[1]!.startsWith('-') ? -Infinity : Infinity) : Number(m[1]);
33
+ return { limit: m[2] === '<' ? limit + Number.EPSILON * Math.max(1, Math.abs(limit)) : limit, text: m[3]! };
34
+ });
35
+ let chosen = options[0]!;
36
+ for (const o of options) if (value >= o.limit) chosen = o;
37
+ return chosen.text;
38
+ }
39
+
40
+ function formatArgument(
41
+ value: unknown,
42
+ type: string | undefined,
43
+ style: string | undefined,
44
+ timezone: string | (() => string)
45
+ ): string {
46
+ if (value === undefined) return '';
47
+ if (!type) return typeof value === 'number' ? number(value, '#,##0.###') : String(value);
48
+ switch (type.trim()) {
49
+ case 'number': {
50
+ const s = style?.trim();
51
+ if (!s) return number(value, '#,##0.###');
52
+ if (s === 'integer') return number(value, '#,##0');
53
+ if (s === 'percent') return number(value, '#,##0%');
54
+ if (s === 'currency') return number(value, "'$'#,##0.00");
55
+ return number(value, style!);
56
+ }
57
+ case 'date':
58
+ case 'time': {
59
+ const styles = type.trim() === 'date' ? DATE_STYLES : TIME_STYLES;
60
+ const s = style?.trim() ?? 'medium';
61
+ return formatDate(Number(value), styles[s] ?? style!, typeof timezone === 'function' ? timezone() : timezone);
62
+ }
63
+ case 'choice':
64
+ return choice(Number(value), style ?? '');
65
+ default:
66
+ throw new SyntaxError(`Unknown format type "${type}"`);
67
+ }
68
+ }
69
+
70
+ /** Formats `pattern` with `args` like PineScript `str.format`; dates use `timezone` (read only when a date is formatted). */
71
+ export function formatMessage(pattern: string, args: unknown[], timezone: string | (() => string)): string {
72
+ let out = '';
73
+ for (let i = 0; i < pattern.length; ) {
74
+ const ch = pattern[i]!;
75
+ if (ch === "'") {
76
+ if (pattern[i + 1] === "'") {
77
+ out += "'";
78
+ i += 2;
79
+ continue;
80
+ }
81
+ const end = pattern.indexOf("'", i + 1);
82
+ out += pattern.slice(i + 1, end === -1 ? undefined : end);
83
+ i = end === -1 ? pattern.length : end + 1;
84
+ continue;
85
+ }
86
+ if (ch !== '{') {
87
+ out += ch;
88
+ i++;
89
+ continue;
90
+ }
91
+ // {index[,type[,style]]}; the style may contain quoted text and nested braces
92
+ let depth = 1;
93
+ let j = i + 1;
94
+ let inQuote = false;
95
+ for (; j < pattern.length && depth > 0; j++) {
96
+ const c = pattern[j];
97
+ if (c === "'") inQuote = !inQuote;
98
+ else if (!inQuote && c === '{') depth++;
99
+ else if (!inQuote && c === '}') depth--;
100
+ }
101
+ const inner = pattern.slice(i + 1, j - 1);
102
+ const [index = '', type, ...rest] = inner.split(',');
103
+ const style = rest.length ? rest.join(',') : undefined;
104
+ const n = Number(index.trim());
105
+ out += n < args.length ? formatArgument(args[n], type, style, timezone) : `{${inner}}`;
106
+ i = j;
107
+ }
108
+ return out;
109
+ }