oakscriptjs 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/bin/oakscript.mjs +10 -3
- package/dist/cjs/box/index.d.ts +348 -289
- package/dist/cjs/box/index.d.ts.map +1 -1
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/check/node.d.ts.map +1 -1
- package/dist/cjs/check/node.js +1 -0
- package/dist/cjs/check/node.js.map +2 -2
- package/dist/cjs/check/preview.d.ts +31 -0
- package/dist/cjs/check/preview.d.ts.map +1 -0
- package/dist/cjs/check/preview.js +303 -0
- package/dist/cjs/check/preview.js.map +7 -0
- package/dist/cjs/color/index.d.ts +11 -11
- package/dist/cjs/color/index.js.map +1 -1
- package/dist/cjs/color/parse.d.ts +2 -0
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +6 -0
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/compare/index.d.ts +76 -12
- package/dist/cjs/compare/index.d.ts.map +1 -1
- package/dist/cjs/compare/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +28 -5
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +14 -0
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/label/index.d.ts +265 -187
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +1 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +247 -207
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +61 -89
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +49 -40
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +57 -78
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/input-active.d.ts +2 -2
- package/dist/cjs/runtime/input-active.js.map +1 -1
- package/dist/cjs/runtime/series.d.ts +241 -161
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +223 -127
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/api/alert.d.ts +37 -0
- package/dist/cjs/script/api/alert.d.ts.map +1 -0
- package/dist/cjs/script/api/alert.js +17 -0
- package/dist/cjs/script/api/alert.js.map +7 -0
- package/dist/cjs/script/api/calc.d.ts +232 -0
- package/dist/cjs/script/api/calc.d.ts.map +1 -0
- package/dist/cjs/script/api/calc.js +17 -0
- package/dist/cjs/script/api/calc.js.map +7 -0
- package/dist/cjs/script/api/color.d.ts +213 -0
- package/dist/cjs/script/api/color.d.ts.map +1 -0
- package/dist/cjs/script/api/color.js +17 -0
- package/dist/cjs/script/api/color.js.map +7 -0
- package/dist/cjs/script/api/context.d.ts +764 -0
- package/dist/cjs/script/api/context.d.ts.map +1 -0
- package/dist/cjs/script/api/context.js +17 -0
- package/dist/cjs/script/api/context.js.map +7 -0
- package/dist/cjs/script/api/log.d.ts +58 -0
- package/dist/cjs/script/api/log.d.ts.map +1 -0
- package/dist/cjs/script/api/log.js +17 -0
- package/dist/cjs/script/api/log.js.map +7 -0
- package/dist/cjs/script/api/strategy.d.ts +391 -0
- package/dist/cjs/script/api/strategy.d.ts.map +1 -0
- package/dist/cjs/script/api/strategy.js +17 -0
- package/dist/cjs/script/api/strategy.js.map +7 -0
- package/dist/cjs/script/api/ta.d.ts +1012 -0
- package/dist/cjs/script/api/ta.d.ts.map +1 -0
- package/dist/cjs/script/api/ta.js +17 -0
- package/dist/cjs/script/api/ta.js.map +7 -0
- package/dist/cjs/script/api/table.d.ts +479 -0
- package/dist/cjs/script/api/table.d.ts.map +1 -0
- package/dist/cjs/script/api/table.js +17 -0
- package/dist/cjs/script/api/table.js.map +7 -0
- package/dist/cjs/script/constants.d.ts +228 -83
- package/dist/cjs/script/constants.d.ts.map +1 -1
- package/dist/cjs/script/constants.js +87 -0
- package/dist/cjs/script/constants.js.map +2 -2
- package/dist/cjs/script/define.d.ts +94 -0
- package/dist/cjs/script/define.d.ts.map +1 -0
- package/dist/cjs/script/define.js +127 -0
- package/dist/cjs/script/define.js.map +7 -0
- package/dist/cjs/script/drawing-args.d.ts.map +1 -1
- package/dist/cjs/script/drawing-args.js +1 -1
- package/dist/cjs/script/drawing-args.js.map +2 -2
- package/dist/cjs/script/formula.d.ts +53 -0
- package/dist/cjs/script/formula.d.ts.map +1 -0
- package/dist/cjs/script/formula.js +402 -0
- package/dist/cjs/script/formula.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +10 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/index.d.ts +1065 -1006
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +532 -61
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/script/json.d.ts +117 -0
- package/dist/cjs/script/json.d.ts.map +1 -0
- package/dist/cjs/script/json.js +321 -0
- package/dist/cjs/script/json.js.map +7 -0
- package/dist/cjs/security/other.d.ts +8 -3
- package/dist/cjs/security/other.d.ts.map +1 -1
- package/dist/cjs/security/other.js +23 -6
- package/dist/cjs/security/other.js.map +2 -2
- package/dist/cjs/str/index.d.ts +50 -75
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +2 -2
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +102 -1
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +2 -2
- package/dist/cjs/table/index.d.ts +330 -49
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +55 -27
- package/dist/cjs/table/index.js.map +2 -2
- package/dist/cjs/text/index.d.ts +12 -14
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/types/index.d.ts +15 -8
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -3
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/esm/box/index.d.ts +348 -289
- package/dist/esm/box/index.d.ts.map +1 -1
- package/dist/esm/box/index.js +276 -276
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/check/node.d.ts.map +1 -1
- package/dist/esm/check/node.js +1 -0
- package/dist/esm/check/node.js.map +1 -1
- package/dist/esm/check/preview.d.ts +31 -0
- package/dist/esm/check/preview.d.ts.map +1 -0
- package/dist/esm/check/preview.js +296 -0
- package/dist/esm/check/preview.js.map +1 -0
- package/dist/esm/color/index.d.ts +11 -11
- package/dist/esm/color/index.js +11 -11
- package/dist/esm/color/parse.d.ts +2 -0
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +7 -0
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/compare/index.d.ts +76 -12
- package/dist/esm/compare/index.d.ts.map +1 -1
- package/dist/esm/compare/index.js +76 -12
- package/dist/esm/compare/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +28 -5
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +39 -3
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/label/index.d.ts +265 -187
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +207 -177
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +247 -207
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +202 -194
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +61 -89
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +61 -89
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +49 -40
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +22 -9
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +57 -78
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +57 -78
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/input-active.d.ts +2 -2
- package/dist/esm/runtime/input-active.js +2 -2
- package/dist/esm/runtime/series.d.ts +241 -161
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +241 -161
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/api/alert.d.ts +37 -0
- package/dist/esm/script/api/alert.d.ts.map +1 -0
- package/dist/esm/script/api/alert.js +7 -0
- package/dist/esm/script/api/alert.js.map +1 -0
- package/dist/esm/script/api/calc.d.ts +232 -0
- package/dist/esm/script/api/calc.d.ts.map +1 -0
- package/dist/esm/script/api/calc.js +6 -0
- package/dist/esm/script/api/calc.js.map +1 -0
- package/dist/esm/script/api/color.d.ts +213 -0
- package/dist/esm/script/api/color.d.ts.map +1 -0
- package/dist/esm/script/api/color.js +6 -0
- package/dist/esm/script/api/color.js.map +1 -0
- package/dist/esm/script/api/context.d.ts +764 -0
- package/dist/esm/script/api/context.d.ts.map +1 -0
- package/dist/esm/script/api/context.js +7 -0
- package/dist/esm/script/api/context.js.map +1 -0
- package/dist/esm/script/api/log.d.ts +58 -0
- package/dist/esm/script/api/log.d.ts.map +1 -0
- package/dist/esm/script/api/log.js +6 -0
- package/dist/esm/script/api/log.js.map +1 -0
- package/dist/esm/script/api/strategy.d.ts +391 -0
- package/dist/esm/script/api/strategy.d.ts.map +1 -0
- package/dist/esm/script/api/strategy.js +7 -0
- package/dist/esm/script/api/strategy.js.map +1 -0
- package/dist/esm/script/api/ta.d.ts +1012 -0
- package/dist/esm/script/api/ta.d.ts.map +1 -0
- package/dist/esm/script/api/ta.js +6 -0
- package/dist/esm/script/api/ta.js.map +1 -0
- package/dist/esm/script/api/table.d.ts +479 -0
- package/dist/esm/script/api/table.d.ts.map +1 -0
- package/dist/esm/script/api/table.js +7 -0
- package/dist/esm/script/api/table.js.map +1 -0
- package/dist/esm/script/constants.d.ts +228 -83
- package/dist/esm/script/constants.d.ts.map +1 -1
- package/dist/esm/script/constants.js +110 -24
- package/dist/esm/script/constants.js.map +1 -1
- package/dist/esm/script/define.d.ts +94 -0
- package/dist/esm/script/define.d.ts.map +1 -0
- package/dist/esm/script/define.js +136 -0
- package/dist/esm/script/define.js.map +1 -0
- package/dist/esm/script/drawing-args.d.ts.map +1 -1
- package/dist/esm/script/drawing-args.js +2 -1
- package/dist/esm/script/drawing-args.js.map +1 -1
- package/dist/esm/script/formula.d.ts +53 -0
- package/dist/esm/script/formula.d.ts.map +1 -0
- package/dist/esm/script/formula.js +408 -0
- package/dist/esm/script/formula.js.map +1 -0
- package/dist/esm/script/globals.d.ts +10 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/index.d.ts +1065 -1006
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +1099 -153
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/script/json.d.ts +117 -0
- package/dist/esm/script/json.d.ts.map +1 -0
- package/dist/esm/script/json.js +375 -0
- package/dist/esm/script/json.js.map +1 -0
- package/dist/esm/security/other.d.ts +8 -3
- package/dist/esm/security/other.d.ts.map +1 -1
- package/dist/esm/security/other.js +45 -10
- package/dist/esm/security/other.js.map +1 -1
- package/dist/esm/str/index.d.ts +50 -75
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +51 -76
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +102 -1
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/strategy/index.js +1 -1
- package/dist/esm/strategy/index.js.map +1 -1
- package/dist/esm/table/index.d.ts +330 -49
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +372 -61
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/text/index.d.ts +12 -14
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +12 -14
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +15 -8
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +15 -8
- package/dist/esm/types/index.js.map +1 -1
- package/docs/first-indicator.md +152 -0
- package/docs/guide.md +1185 -0
- package/docs/inventory.md +772 -0
- package/docs/no-code.md +207 -0
- package/docs/recipes.md +202 -0
- package/package.json +2 -1
- package/skills/oakscript/SKILL.md +8 -0
- package/skills/oakscript/reference/errors.md +3 -2
- package/skills/oakscript/reference/timeframes-symbols.md +4 -0
- package/src/box/index.ts +348 -289
- package/src/check/node.ts +1 -0
- package/src/check/preview.ts +307 -0
- package/src/color/index.ts +11 -11
- package/src/color/parse.ts +7 -0
- package/src/compare/index.ts +76 -12
- package/src/drawing/registry.ts +44 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +267 -189
- package/src/line/index.ts +248 -208
- package/src/linefill/index.ts +61 -89
- package/src/math/index.ts +51 -42
- package/src/polyline/index.ts +57 -78
- package/src/runtime/input-active.ts +2 -2
- package/src/runtime/series.ts +243 -163
- package/src/script/api/alert.ts +43 -0
- package/src/script/api/calc.ts +250 -0
- package/src/script/api/color.ts +245 -0
- package/src/script/api/context.ts +944 -0
- package/src/script/api/log.ts +60 -0
- package/src/script/api/strategy.ts +410 -0
- package/src/script/api/ta.ts +1115 -0
- package/src/script/api/table.ts +538 -0
- package/src/script/constants.ts +229 -25
- package/src/script/define.ts +221 -0
- package/src/script/drawing-args.ts +2 -1
- package/src/script/formula.ts +438 -0
- package/src/script/globals.ts +10 -0
- package/src/script/index.ts +1520 -241
- package/src/script/json.ts +457 -0
- package/src/security/other.ts +43 -9
- package/src/str/index.ts +51 -76
- package/src/strategy/index.ts +102 -1
- package/src/table/index.ts +388 -62
- package/src/text/index.ts +12 -14
- package/src/types/index.ts +15 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/security/other.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * PineScript `request.security(symbol, timeframe, expression, gaps, lookahead)` of another symbol: which bar of the\n * other symbol each chart bar shows (#179). The bars of the other symbol are given by the caller, already on the\n * requested timeframe; the expression is computed on them and its values are mapped to the chart bars with the index\n * given here. The script API does this with the `bars` accessor of its chart context.\n *\n * PineScript rules (measured on stocks, crypto and an exchange whose trading day starts on the previous UTC day; the\n * chart timeframe, D, W and M on intraday and daily charts; the four gaps / lookahead combinations):\n * - lookahead off: the last bar of the other symbol whose close time is at or before the close time of the chart bar\n * (a daily stock bar closes at the session end, a crypto daily bar at 00:00 UTC: a stock chart shows the crypto\n * bar of the day before, a crypto chart the stock bar of the same day)\n * - lookahead on, intraday chart or intraday request: the last bar of the other symbol that opened at or before the\n * open of the chart bar\n * - lookahead on, D / W / M chart and request: the last bar of the other symbol whose period starts at or before the trading day\n * of the chart bar: the trading day of a D bar, the Monday of a W bar, the first day of the month of an M bar, each\n * in the exchange time zone of its symbol (a week that opens on a Tuesday after a holiday still starts on Monday)\n * - before the first bar of the other symbol: na; on chart bars where the other symbol has no bar (weekends,\n * holidays, closed hours), gaps off repeats the last value\n * - gaps on: a value only on the chart bar where the shown bar changes (and on the first chart bar), na on the others\n * - the last bar while it is open (`lastBarConfirmed` false) with gaps off: the realtime update shows the bar given by\n * lookahead on (the open bar of a higher timeframe), with lookahead off as well; a lower timeframe keeps the rules\n * above (the last lower bar so far with lookahead off, the first one of the chart bar with lookahead on)\n *\n * Close times, trading days and time zones come from the exchange calendars of the chart and of the other symbol\n * (time zone and session, read by the session functions). Without them:\n * - a symbol that trades every day (bars on Saturdays or Sundays; W bars at Monday 00:00 UTC; M bars on the first day\n * at 00:00 UTC) is on the \"24x7\" UTC calendar\n * - another symbol whose bars open where the chart calendar starts its periods is on the calendar of the chart\n * - else the UTC rule: an intraday bar closes one bar interval after its open (or at the next bar), a D / W / M bar at\n * the end of the last weekday (UTC) of its day / week / month; the trading day is the UTC date of the bar\n * The fallback is exact between symbols of the same calendar and with 24x7 symbols; between a stock and a 24x7 symbol,\n * or an exchange whose trading day starts on the previous UTC day, it needs the session of the stock.\n *\n * @module security/other\n */\n\nimport * as timeframe from '../timeframe/index.js';\nimport { chartSessions, periodClose, periodTime, tradingDayTime, type SessionContext } from '../session/context.js';\nimport type { SessionSpec } from '../session/calendar.js';\n\nconst DAY = 86_400_000;\n\n/** Exchange calendar of a symbol: time zone and session (hours, corrections, holidays). */\nexport interface SymbolCalendar {\n timezone?: string;\n session?: SessionSpec | string;\n}\n\n/** Options of {@link securityOther}. */\nexport interface OtherSymbolOptions {\n /** PineScript `barmerge.lookahead_on`; default false */\n lookahead?: boolean;\n /** PineScript `barmerge.gaps_on`; default false */\n gaps?: boolean;\n /** Calendar of the other symbol; see the module notes for the fallback */\n other?: SymbolCalendar;\n}\n\n/** The chart: its timeframe, calendar, time unit and whether its last bar is closed. */\nexport interface OtherSymbolChart extends SymbolCalendar {\n /** Chart timeframe (\"60\", \"1D\"...) */\n timeframe: string;\n /** Unit of the bar times: 's' (default) or 'ms' */\n timeUnit?: 's' | 'ms';\n /** false: the last chart bar is still open (realtime rule) */\n lastBarConfirmed?: boolean;\n}\n\ninterface Zone {\n timezone: string;\n session: SessionSpec | string;\n}\n\nconst calendars = new Map<string, SessionContext | null>();\n\n/** The session context of a zone and a timeframe (bar times in ms); null when the session cannot be read. */\nfunction calendarOf(zone: Zone | null, tf: string): SessionContext | null {\n if (!zone) return null;\n const key = `${zone.timezone}|${typeof zone.session === 'string' ? zone.session : JSON.stringify(zone.session)}|${tf}`;\n let context = calendars.get(key);\n if (context === undefined) {\n context = { timeframe: tf, timezone: zone.timezone, session: zone.session, timeUnit: 'ms' };\n try {\n chartSessions(context);\n } catch {\n context = null;\n }\n if (calendars.size > 64) calendars.clear();\n calendars.set(key, context);\n }\n return context;\n}\n\nconst UTC_24X7: Zone = { timezone: 'Etc/UTC', session: '24x7' };\n\n/** True when bars of timeframe `tf` opening at `times` (ms) are those of a symbol that trades every day in UTC. */\nfunction tradesEveryDay(times: number[], tf: string): boolean {\n if (times.length === 0) return false;\n const info = timeframe.info(tf);\n if (info.isweekly) return times.every((t) => t % DAY === 0 && new Date(t).getUTCDay() === 1);\n if (info.ismonthly) return times.every((t) => t % DAY === 0 && new Date(t).getUTCDate() === 1);\n return times.some((t) => {\n const wd = new Date(t).getUTCDay();\n return wd === 0 || wd === 6;\n });\n}\n\n/** True when most of the last bars open at the start of a period of `tf` on the calendar `zone`. */\nfunction onCalendar(times: number[], tf: string, zone: Zone | null): boolean {\n const calendar = calendarOf(zone, tf);\n if (!calendar || times.length === 0) return false;\n const last = times.slice(-50);\n return last.filter((t) => periodTime(t, tf, calendar) === t).length >= 0.9 * last.length;\n}\n\nconst utcDay = (t: number): number => Math.floor(t / DAY) * DAY;\n/** Monday 00:00 UTC of the week of the day `day` (00:00 UTC, ms). */\nconst weekStart = (day: number): number => day - ((new Date(day).getUTCDay() + 6) % 7) * DAY;\nconst monthStart = (day: number): number => {\n const d = new Date(day);\n return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1);\n};\n\n/** 00:00 UTC after the last weekday before `end` (00:00 UTC, ms): the end of a period of a Monday-to-Friday symbol. */\nfunction afterLastWeekday(end: number): number {\n let day = end - DAY;\n while (new Date(day).getUTCDay() % 6 === 0) day -= DAY;\n return day + DAY;\n}\n\n/** Close time (ms) of each bar of timeframe `tf` opening at `times` (ms). */\nfunction closeTimes(times: number[], tf: string, zone: Zone | null): number[] {\n const calendar = calendarOf(zone, tf);\n const info = timeframe.info(tf);\n const len = timeframe.in_seconds(tf) * 1000;\n return times.map((t, i) => {\n if (calendar) {\n const c = periodClose(t, tf, calendar);\n if (!Number.isNaN(c)) return c;\n }\n if (info.isintraday) return i + 1 < times.length ? Math.min(t + len, times[i + 1]!) : t + len;\n const day = utcDay(t);\n if (info.isweekly) return afterLastWeekday(weekStart(day) + 7 * DAY * info.multiplier);\n if (info.ismonthly) {\n const d = new Date(day);\n return afterLastWeekday(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + info.multiplier, 1));\n }\n return day + DAY * info.multiplier;\n });\n}\n\n/** Trading day (00:00 UTC, ms) of each bar opening at `times` (ms): its date in the exchange time zone. */\nfunction tradingDays(times: number[], zone: Zone | null): number[] {\n const calendar = calendarOf(zone, '1D');\n return times.map((t) => {\n const d = calendar ? tradingDayTime(t, calendar) : NaN;\n return Number.isNaN(d) ? utcDay(t) : d;\n });\n}\n\n/** For each element of `at` (non-decreasing), the index of the last element of `keys` (non-decreasing) <= it; -1: none. */\nfunction latestAtOrBefore(keys: number[], at: number[]): number[] {\n let j = -1;\n return at.map((x) => {\n while (j + 1 < keys.length && keys[j + 1]! <= x) j++;\n return j;\n });\n}\n\nconst zoneOf = (c: SymbolCalendar | undefined): Zone | null =>\n c?.timezone && c.session ? { timezone: c.timezone, session: c.session } : null;\n\n/** Timeframes and exchange calendars of a merge: given, 24x7, the chart's, else the UTC rule. */\nfunction setup(\n ct: number[],\n ot: number[],\n tf: string,\n chart: OtherSymbolChart,\n options: OtherSymbolOptions\n): { chartTf: string; otherTf: string; chartZone: Zone | null; otherZone: Zone | null } {\n const chartTf = timeframe.info(chart.timeframe).period;\n const otherTf = tf.trim() === '' ? chartTf : timeframe.info(tf).period;\n if (timeframe.info(otherTf).isticks) throw new RangeError(`request.security: tick timeframe \"${tf}\" is not supported.`);\n const chartZone = zoneOf(chart) ?? (tradesEveryDay(ct, chartTf) ? UTC_24X7 : null);\n const otherZone =\n zoneOf(options.other) ??\n (tradesEveryDay(ot, otherTf) ? UTC_24X7 : chartZone && onCalendar(ot, otherTf, chartZone) ? chartZone : null);\n return { chartTf, otherTf, chartZone, otherZone };\n}\n\n/**\n * PineScript `request.security` of another symbol: the index in `otherBars` of the bar shown on each chart bar, -1\n * for na (#179). `otherBars` are the bars of the other symbol on `tf` (\"\" for the chart timeframe, or a higher\n * or a lower one), with times in the unit of the chart bars. Rules in the module notes; the same rules hold for a\n * lower timeframe (#181): lookahead off shows the last lower bar that closes by the close of the chart bar, lookahead\n * on the last one that opened by its open. It also serves the chart symbol on a lower timeframe.\n * @throws RangeError for a tick timeframe\n */\nexport function securityOther(\n chartBars: ReadonlyArray<{ time: number }>,\n otherBars: ReadonlyArray<{ time: number }>,\n tf: string,\n chart: OtherSymbolChart,\n options: OtherSymbolOptions = {}\n): number[] {\n const n = chartBars.length;\n if (n === 0) return [];\n const unit = chart.timeUnit === 'ms' ? 1 : 1000;\n const ct = chartBars.map((b) => b.time * unit);\n const ot = otherBars.map((b) => b.time * unit);\n const { chartTf, otherTf, chartZone, otherZone } = setup(ct, ot, tf, chart, options);\n if (ot.length === 0) return new Array<number>(n).fill(-1);\n\n // by trading day when both timeframes are D / W / M; by open time with an intraday side (#181)\n const daily = timeframe.info(chartTf).isdwm && timeframe.info(otherTf).isdwm;\n // a lower timeframe keeps its rule on the open last bar: the last lower bar so far, not the first one (#184)\n const realtime =\n chart.lastBarConfirmed === false && !options.gaps && timeframe.in_seconds(otherTf) >= timeframe.in_seconds(chartTf);\n let on: number[] = [];\n if (options.lookahead || realtime) {\n if (daily) {\n const info = timeframe.info(otherTf);\n const starts = tradingDays(ot, otherZone).map((d) => (info.isweekly ? weekStart(d) : info.ismonthly ? monthStart(d) : d));\n on = latestAtOrBefore(starts, tradingDays(ct, chartZone));\n } else {\n on = latestAtOrBefore(ot, ct);\n }\n }\n const index = options.lookahead ? on : latestAtOrBefore(closeTimes(ot, otherTf, otherZone), closeTimes(ct, chartTf, chartZone));\n // realtime updates of the open last bar: lookahead off shows the bar of lookahead on\n if (realtime) index[n - 1] = on[n - 1]!;\n if (!options.gaps) return index;\n return index.map((j, i) => (i === 0 || j !== index[i - 1] ? j : -1));\n}\n\n/**\n * PineScript `request.security_lower_tf` (#181): for each chart bar, the range `[from, to)` of the bars of\n * `otherBars` (a lower timeframe, the chart symbol or another one) that it contains: the bars whose close time is\n * after the open of the chart bar and at or before its close (a 13:00 hourly bar of a 24x7 symbol is in a 13:30 stock\n * day, which closes at 20:00). An empty range for a chart bar without such bars.\n *\n * As PineScript, at most the last {@link MAX_INTRABARS} (100,000) lower-timeframe bars are given out\n * (`options.maxIntrabars` changes it): the older chart bars get an empty range (#192).\n */\nexport function securityLowerTf(\n chartBars: ReadonlyArray<{ time: number }>,\n otherBars: ReadonlyArray<{ time: number }>,\n tf: string,\n chart: OtherSymbolChart,\n options: Pick<OtherSymbolOptions, 'other'> & { maxIntrabars?: number } = {}\n): Array<[number, number]> {\n const unit = chart.timeUnit === 'ms' ? 1 : 1000;\n const ct = chartBars.map((b) => b.time * unit);\n const ot = otherBars.map((b) => b.time * unit);\n const { chartTf, otherTf, chartZone, otherZone } = setup(ct, ot, tf, chart, options);\n const oc = closeTimes(ot, otherTf, otherZone);\n const from = latestAtOrBefore(oc, ct);\n const to = latestAtOrBefore(oc, closeTimes(ct, chartTf, chartZone));\n const ranges = ct.map((_, i): [number, number] => [from[i]! + 1, Math.max(from[i]! + 1, to[i]! + 1)]);\n // the last `max` intrabars of the chart bars: the ones before are not given\n const max = options.maxIntrabars ?? MAX_INTRABARS;\n const end = ranges.reduce((m, [, t]) => Math.max(m, t), 0);\n const first = end - max;\n if (first <= 0) return ranges;\n return ranges.map(([f, t]) => (t <= first ? [f, f] : [Math.max(f, first), t]));\n}\n\n/** Lower-timeframe bars `request.security_lower_tf` gives out at most, as PineScript (the last ones). */\nexport const MAX_INTRABARS = 100_000;\n\n/**\n * {@link securityOther} with the values of an expression: `values` has one value per bar of the other symbol; the\n * result has one value per chart bar, NaN for na.\n */\nexport function securityOtherValues(\n chartBars: ReadonlyArray<{ time: number }>,\n otherBars: ReadonlyArray<{ time: number }>,\n tf: string,\n values: ArrayLike<number>,\n chart: OtherSymbolChart,\n options: OtherSymbolOptions = {}\n): number[] {\n return securityOther(chartBars, otherBars, tf, chart, options).map((j) => (j < 0 ? NaN : (values[j] ?? NaN)));\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * PineScript `request.security(symbol, timeframe, expression, gaps, lookahead)` of another symbol: which bar of the\n * other symbol each chart bar shows (#179). The bars of the other symbol are given by the caller, already on the\n * requested timeframe; the expression is computed on them and its values are mapped to the chart bars with the index\n * given here. The script API does this with the `bars` accessor of its chart context.\n *\n * PineScript rules (measured on stocks, crypto and an exchange whose trading day starts on the previous UTC day; the\n * chart timeframe, D, W and M on intraday and daily charts; the four gaps / lookahead combinations):\n * - lookahead off: the last bar of the other symbol whose close time is at or before the close time of the chart bar\n * (a daily stock bar closes at the session end, a crypto daily bar at 00:00 UTC: a stock chart shows the crypto\n * bar of the day before, a crypto chart the stock bar of the same day)\n * - lookahead on, intraday chart or intraday request: the last bar of the other symbol that opened at or before the\n * open of the chart bar\n * - lookahead on, D / W / M chart and request: the last bar of the other symbol whose period starts at or before the trading day\n * of the chart bar: the trading day of a D bar, the Monday of a W bar, the first day of the month of an M bar, each\n * in the exchange time zone of its symbol (a week that opens on a Tuesday after a holiday still starts on Monday)\n * - before the first bar of the other symbol: na; on chart bars where the other symbol has no bar (weekends,\n * holidays, closed hours), gaps off repeats the last value\n * - gaps on: a value only on the chart bar where the shown bar changes (and on the first chart bar), na on the others\n * - the last bar while it is open (`lastBarConfirmed` false) with gaps off: the realtime update shows the bar given by\n * lookahead on (the open bar of a higher timeframe), with lookahead off as well; a lower timeframe keeps the rules\n * above (the last lower bar so far with lookahead off, the first one of the chart bar with lookahead on)\n *\n * Tick timeframes (\"1T\", \"10T\"\u2026, #214): a tick bar has no duration, so it is placed by its open time. A chart bar\n * holds the tick bars that open at or after its open and before its close; lookahead off shows the last tick bar\n * that opened before the close of the chart bar, lookahead on the last one that opened at or before its open. On a\n * chart of ticks, a bar closes when the next one opens (the last one is still open): it shows the bars that closed\n * before then.\n *\n * Close times, trading days and time zones come from the exchange calendars of the chart and of the other symbol\n * (time zone and session, read by the session functions). Without them:\n * - a symbol that trades every day (bars on Saturdays or Sundays; W bars at Monday 00:00 UTC; M bars on the first day\n * at 00:00 UTC) is on the \"24x7\" UTC calendar\n * - another symbol whose bars open where the chart calendar starts its periods is on the calendar of the chart\n * - else the UTC rule: an intraday bar closes one bar interval after its open (or at the next bar), a D / W / M bar at\n * the end of the last weekday (UTC) of its day / week / month; the trading day is the UTC date of the bar\n * The fallback is exact between symbols of the same calendar and with 24x7 symbols; between a stock and a 24x7 symbol,\n * or an exchange whose trading day starts on the previous UTC day, it needs the session of the stock.\n *\n * @module security/other\n */\n\nimport * as timeframe from '../timeframe/index.js';\nimport { chartSessions, periodClose, periodTime, tradingDayTime, type SessionContext } from '../session/context.js';\nimport type { SessionSpec } from '../session/calendar.js';\n\nconst DAY = 86_400_000;\n\n/** Exchange calendar of a symbol: time zone and session (hours, corrections, holidays). */\nexport interface SymbolCalendar {\n timezone?: string;\n session?: SessionSpec | string;\n}\n\n/** Options of {@link securityOther}. */\nexport interface OtherSymbolOptions {\n /** PineScript `barmerge.lookahead_on`; default false */\n lookahead?: boolean;\n /** PineScript `barmerge.gaps_on`; default false */\n gaps?: boolean;\n /** Calendar of the other symbol; see the module notes for the fallback */\n other?: SymbolCalendar;\n}\n\n/** The chart: its timeframe, calendar, time unit and whether its last bar is closed. */\nexport interface OtherSymbolChart extends SymbolCalendar {\n /** Chart timeframe (\"60\", \"1D\"...) */\n timeframe: string;\n /** Unit of the bar times: 's' (default) or 'ms' */\n timeUnit?: 's' | 'ms';\n /** false: the last chart bar is still open (realtime rule) */\n lastBarConfirmed?: boolean;\n}\n\ninterface Zone {\n timezone: string;\n session: SessionSpec | string;\n}\n\nconst calendars = new Map<string, SessionContext | null>();\n\n/** The session context of a zone and a timeframe (bar times in ms); null when the session cannot be read. */\nfunction calendarOf(zone: Zone | null, tf: string): SessionContext | null {\n if (!zone) return null;\n const key = `${zone.timezone}|${typeof zone.session === 'string' ? zone.session : JSON.stringify(zone.session)}|${tf}`;\n let context = calendars.get(key);\n if (context === undefined) {\n context = { timeframe: tf, timezone: zone.timezone, session: zone.session, timeUnit: 'ms' };\n try {\n chartSessions(context);\n } catch {\n context = null;\n }\n if (calendars.size > 64) calendars.clear();\n calendars.set(key, context);\n }\n return context;\n}\n\nconst UTC_24X7: Zone = { timezone: 'Etc/UTC', session: '24x7' };\n\n/** True when bars of timeframe `tf` opening at `times` (ms) are those of a symbol that trades every day in UTC. */\nfunction tradesEveryDay(times: number[], tf: string): boolean {\n if (times.length === 0) return false;\n const info = timeframe.info(tf);\n if (info.isweekly) return times.every((t) => t % DAY === 0 && new Date(t).getUTCDay() === 1);\n if (info.ismonthly) return times.every((t) => t % DAY === 0 && new Date(t).getUTCDate() === 1);\n return times.some((t) => {\n const wd = new Date(t).getUTCDay();\n return wd === 0 || wd === 6;\n });\n}\n\n/** True when most of the last bars open at the start of a period of `tf` on the calendar `zone`. */\nfunction onCalendar(times: number[], tf: string, zone: Zone | null): boolean {\n const calendar = calendarOf(zone, tf);\n if (!calendar || times.length === 0) return false;\n const last = times.slice(-50);\n return last.filter((t) => periodTime(t, tf, calendar) === t).length >= 0.9 * last.length;\n}\n\nconst utcDay = (t: number): number => Math.floor(t / DAY) * DAY;\n/** Monday 00:00 UTC of the week of the day `day` (00:00 UTC, ms). */\nconst weekStart = (day: number): number => day - ((new Date(day).getUTCDay() + 6) % 7) * DAY;\nconst monthStart = (day: number): number => {\n const d = new Date(day);\n return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1);\n};\n\n/** 00:00 UTC after the last weekday before `end` (00:00 UTC, ms): the end of a period of a Monday-to-Friday symbol. */\nfunction afterLastWeekday(end: number): number {\n let day = end - DAY;\n while (new Date(day).getUTCDay() % 6 === 0) day -= DAY;\n return day + DAY;\n}\n\n/** Close time (ms) of each bar of timeframe `tf` opening at `times` (ms). */\nfunction closeTimes(times: number[], tf: string, zone: Zone | null): number[] {\n const calendar = calendarOf(zone, tf);\n const info = timeframe.info(tf);\n const len = timeframe.in_seconds(tf) * 1000;\n if (info.isticks) return times.map((_, i) => (i + 1 < times.length ? times[i + 1]! : Infinity));\n return times.map((t, i) => {\n if (calendar) {\n const c = periodClose(t, tf, calendar);\n if (!Number.isNaN(c)) return c;\n }\n if (info.isintraday) return i + 1 < times.length ? Math.min(t + len, times[i + 1]!) : t + len;\n const day = utcDay(t);\n if (info.isweekly) return afterLastWeekday(weekStart(day) + 7 * DAY * info.multiplier);\n if (info.ismonthly) {\n const d = new Date(day);\n return afterLastWeekday(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + info.multiplier, 1));\n }\n return day + DAY * info.multiplier;\n });\n}\n\n/** Trading day (00:00 UTC, ms) of each bar opening at `times` (ms): its date in the exchange time zone. */\nfunction tradingDays(times: number[], zone: Zone | null): number[] {\n const calendar = calendarOf(zone, '1D');\n return times.map((t) => {\n const d = calendar ? tradingDayTime(t, calendar) : NaN;\n return Number.isNaN(d) ? utcDay(t) : d;\n });\n}\n\n/** For each element of `at` (non-decreasing), the index of the last element of `keys` (non-decreasing) <= it; -1: none. */\nfunction latestAtOrBefore(keys: number[], at: number[]): number[] {\n let j = -1;\n return at.map((x) => {\n while (j + 1 < keys.length && keys[j + 1]! <= x) j++;\n return j;\n });\n}\n\n/** For each element of `at` (non-decreasing), the index of the first element of `keys` (non-decreasing) >= it;\n * `keys.length`: none. */\nfunction firstAtOrAfter(keys: number[], at: number[]): number[] {\n let j = 0;\n return at.map((x) => {\n while (j < keys.length && keys[j]! < x) j++;\n return j;\n });\n}\n\nconst zoneOf = (c: SymbolCalendar | undefined): Zone | null =>\n c?.timezone && c.session ? { timezone: c.timezone, session: c.session } : null;\n\n/** Timeframes and exchange calendars of a merge: given, 24x7, the chart's, else the UTC rule. */\nfunction setup(\n ct: number[],\n ot: number[],\n tf: string,\n chart: OtherSymbolChart,\n options: OtherSymbolOptions\n): { chartTf: string; otherTf: string; chartZone: Zone | null; otherZone: Zone | null } {\n const chartTf = timeframe.info(chart.timeframe).period;\n const otherTf = tf.trim() === '' ? chartTf : timeframe.info(tf).period;\n const chartZone = zoneOf(chart) ?? (tradesEveryDay(ct, chartTf) ? UTC_24X7 : null);\n const otherZone =\n zoneOf(options.other) ??\n (tradesEveryDay(ot, otherTf) ? UTC_24X7 : chartZone && onCalendar(ot, otherTf, chartZone) ? chartZone : null);\n return { chartTf, otherTf, chartZone, otherZone };\n}\n\n/**\n * PineScript `request.security` of another symbol: the index in `otherBars` of the bar shown on each chart bar, -1\n * for na (#179). `otherBars` are the bars of the other symbol on `tf` (\"\" for the chart timeframe, or a higher\n * or a lower one), with times in the unit of the chart bars. Rules in the module notes; the same rules hold for a\n * lower timeframe (#181): lookahead off shows the last lower bar that closes by the close of the chart bar, lookahead\n * on the last one that opened by its open. It also serves the chart symbol on a lower timeframe, and ticks (#214).\n */\nexport function securityOther(\n chartBars: ReadonlyArray<{ time: number }>,\n otherBars: ReadonlyArray<{ time: number }>,\n tf: string,\n chart: OtherSymbolChart,\n options: OtherSymbolOptions = {}\n): number[] {\n const n = chartBars.length;\n if (n === 0) return [];\n const unit = chart.timeUnit === 'ms' ? 1 : 1000;\n const ct = chartBars.map((b) => b.time * unit);\n const ot = otherBars.map((b) => b.time * unit);\n const { chartTf, otherTf, chartZone, otherZone } = setup(ct, ot, tf, chart, options);\n if (ot.length === 0) return new Array<number>(n).fill(-1);\n\n // by trading day when both timeframes are D / W / M; by open time with an intraday side (#181)\n const daily = timeframe.info(chartTf).isdwm && timeframe.info(otherTf).isdwm;\n // a lower timeframe keeps its rule on the open last bar: the last lower bar so far, not the first one (#184)\n const realtime =\n chart.lastBarConfirmed === false && !options.gaps && timeframe.in_seconds(otherTf) >= timeframe.in_seconds(chartTf);\n let on: number[] = [];\n if (options.lookahead || realtime) {\n if (daily) {\n const info = timeframe.info(otherTf);\n const starts = tradingDays(ot, otherZone).map((d) => (info.isweekly ? weekStart(d) : info.ismonthly ? monthStart(d) : d));\n on = latestAtOrBefore(starts, tradingDays(ct, chartZone));\n } else {\n on = latestAtOrBefore(ot, ct);\n }\n }\n const chartClose = closeTimes(ct, chartTf, chartZone);\n // ticks: the last tick bar that opened before the chart bar's close; on a tick chart, the bars that closed before\n // the next tick bar opened\n const before = (keys: number[]) => firstAtOrAfter(keys, chartClose).map((j) => j - 1);\n const index = options.lookahead\n ? on\n : timeframe.info(otherTf).isticks\n ? before(ot)\n : timeframe.info(chartTf).isticks\n ? before(closeTimes(ot, otherTf, otherZone))\n : latestAtOrBefore(closeTimes(ot, otherTf, otherZone), chartClose);\n // realtime updates of the open last bar: lookahead off shows the bar of lookahead on\n if (realtime) index[n - 1] = on[n - 1]!;\n if (!options.gaps) return index;\n return index.map((j, i) => (i === 0 || j !== index[i - 1] ? j : -1));\n}\n\n/**\n * PineScript `request.security_lower_tf` (#181): for each chart bar, the range `[from, to)` of the bars of\n * `otherBars` (a lower timeframe, the chart symbol or another one) that it contains: the bars whose close time is\n * after the open of the chart bar and at or before its close (a 13:00 hourly bar of a 24x7 symbol is in a 13:30 stock\n * day, which closes at 20:00); tick bars by their open time (#214). An empty range for a chart bar without such bars.\n *\n * As PineScript, at most the last {@link MAX_INTRABARS} (100,000) lower-timeframe bars are given out\n * (`options.maxIntrabars` changes it): the older chart bars get an empty range (#192).\n */\nexport function securityLowerTf(\n chartBars: ReadonlyArray<{ time: number }>,\n otherBars: ReadonlyArray<{ time: number }>,\n tf: string,\n chart: OtherSymbolChart,\n options: Pick<OtherSymbolOptions, 'other'> & { maxIntrabars?: number } = {}\n): Array<[number, number]> {\n const unit = chart.timeUnit === 'ms' ? 1 : 1000;\n const ct = chartBars.map((b) => b.time * unit);\n const ot = otherBars.map((b) => b.time * unit);\n const { chartTf, otherTf, chartZone, otherZone } = setup(ct, ot, tf, chart, options);\n const chartClose = closeTimes(ct, chartTf, chartZone);\n let ranges: Array<[number, number]>;\n if (timeframe.info(otherTf).isticks) {\n // tick bars by their open time: at or after the chart bar's open, before its close (#214)\n const from = firstAtOrAfter(ot, ct);\n const to = firstAtOrAfter(ot, chartClose);\n ranges = ct.map((_, i): [number, number] => [from[i]!, Math.max(from[i]!, to[i]!)]);\n } else {\n const oc = closeTimes(ot, otherTf, otherZone);\n const from = latestAtOrBefore(oc, ct);\n const to = latestAtOrBefore(oc, chartClose);\n ranges = ct.map((_, i): [number, number] => [from[i]! + 1, Math.max(from[i]! + 1, to[i]! + 1)]);\n }\n // the last `max` intrabars of the chart bars: the ones before are not given\n const max = options.maxIntrabars ?? MAX_INTRABARS;\n const end = ranges.reduce((m, [, t]) => Math.max(m, t), 0);\n const first = end - max;\n if (first <= 0) return ranges;\n return ranges.map(([f, t]) => (t <= first ? [f, f] : [Math.max(f, first), t]));\n}\n\n/** Lower-timeframe bars `request.security_lower_tf` gives out at most, as PineScript (the last ones). */\nexport const MAX_INTRABARS = 100_000;\n\n/**\n * {@link securityOther} with the values of an expression: `values` has one value per bar of the other symbol; the\n * result has one value per chart bar, NaN for na.\n */\nexport function securityOtherValues(\n chartBars: ReadonlyArray<{ time: number }>,\n otherBars: ReadonlyArray<{ time: number }>,\n tf: string,\n values: ArrayLike<number>,\n chart: OtherSymbolChart,\n options: OtherSymbolOptions = {}\n): number[] {\n return securityOther(chartBars, otherBars, tf, chart, options).map((j) => (j < 0 ? NaN : (values[j] ?? NaN)));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CA,gBAA2B;AAC3B,qBAA4F;AAG5F,MAAM,MAAM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QAAQ,gBAAgB;AACpC,QAAM,MAAM,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC;AACzD,QAAM,QAAQ,MAAM;AACpB,MAAI,SAAS,EAAG,QAAO;AACvB,SAAO,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,MAAO,KAAK,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,KAAK,GAAG,CAAC,CAAE;AAC/E;AAGO,MAAM,gBAAgB;AAMtB,SAAS,oBACd,WACA,WACA,IACA,QACA,OACA,UAA8B,CAAC,GACrB;AACV,SAAO,cAAc,WAAW,WAAW,IAAI,OAAO,OAAO,EAAE,IAAI,CAAC,MAAO,IAAI,IAAI,MAAO,OAAO,CAAC,KAAK,GAAK;AAC9G;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/str/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type { int, bool, float, simple_int, simple_string } from '../types/index
|
|
|
16
16
|
* @returns The number of characters in the string
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
* ```
|
|
19
|
+
* ```js
|
|
20
20
|
* str.length("Hello") // Returns: 5
|
|
21
21
|
* str.length("") // Returns: 0
|
|
22
22
|
* ```
|
|
@@ -59,7 +59,7 @@ export declare function length(str: simple_string): int;
|
|
|
59
59
|
* "NaNT" for `format.volume`), except `format.mintick`, which gives "Infinity" / "-Infinity"
|
|
60
60
|
*
|
|
61
61
|
* @example
|
|
62
|
-
* ```
|
|
62
|
+
* ```js
|
|
63
63
|
* str.tostring(123) // "123"
|
|
64
64
|
* str.tostring(1.5, "#.##") // "1.5"
|
|
65
65
|
* str.tostring(0.5, "#.00") // ".50"
|
|
@@ -81,7 +81,7 @@ export declare function tostring(value: any, format?: simple_string, mintick?: f
|
|
|
81
81
|
* (no-break space U+00A0, U+3000) give na
|
|
82
82
|
*
|
|
83
83
|
* @example
|
|
84
|
-
* ```
|
|
84
|
+
* ```js
|
|
85
85
|
* str.tonumber("123") // Returns: 123
|
|
86
86
|
* str.tonumber("45.67") // Returns: 45.67
|
|
87
87
|
* str.tonumber("abc") // Returns: null
|
|
@@ -105,7 +105,7 @@ export declare function tonumber(str: simple_string): float | null;
|
|
|
105
105
|
* - Indices beyond string length return empty string
|
|
106
106
|
*
|
|
107
107
|
* @example
|
|
108
|
-
* ```
|
|
108
|
+
* ```js
|
|
109
109
|
* str.substring("hello world", 0, 5) // Returns: "hello"
|
|
110
110
|
* str.substring("hello world", 6) // Returns: "world"
|
|
111
111
|
* str.substring("test", 1, 3) // Returns: "es"
|
|
@@ -119,7 +119,7 @@ export declare function substring(str: simple_string, begin: simple_int, end?: s
|
|
|
119
119
|
* @returns The uppercase string
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
122
|
-
* ```
|
|
122
|
+
* ```js
|
|
123
123
|
* str.upper("hello") // Returns: "HELLO"
|
|
124
124
|
* str.upper("Hello World") // Returns: "HELLO WORLD"
|
|
125
125
|
* str.upper("test123") // Returns: "TEST123"
|
|
@@ -133,7 +133,7 @@ export declare function upper(str: simple_string): string;
|
|
|
133
133
|
* @returns The lowercase string
|
|
134
134
|
*
|
|
135
135
|
* @example
|
|
136
|
-
* ```
|
|
136
|
+
* ```js
|
|
137
137
|
* str.lower("HELLO") // Returns: "hello"
|
|
138
138
|
* str.lower("Hello World") // Returns: "hello world"
|
|
139
139
|
* str.lower("TEST123") // Returns: "test123"
|
|
@@ -152,7 +152,7 @@ export declare function lower(str: simple_string): string;
|
|
|
152
152
|
* - Empty string is contained in any string
|
|
153
153
|
*
|
|
154
154
|
* @example
|
|
155
|
-
* ```
|
|
155
|
+
* ```js
|
|
156
156
|
* str.contains("hello world", "world") // Returns: true
|
|
157
157
|
* str.contains("hello world", "World") // Returns: false (case-sensitive)
|
|
158
158
|
* str.contains("test", "xyz") // Returns: false
|
|
@@ -172,7 +172,7 @@ export declare function contains(source: simple_string, str: simple_string): boo
|
|
|
172
172
|
* - Returns na (NaN) if substring is not found, as in PineScript
|
|
173
173
|
*
|
|
174
174
|
* @example
|
|
175
|
-
* ```
|
|
175
|
+
* ```js
|
|
176
176
|
* str.pos("hello world", "world") // Returns: 6
|
|
177
177
|
* str.pos("hello world", "o") // Returns: 4 (first occurrence)
|
|
178
178
|
* str.pos("hello", "xyz") // Returns: NaN (na)
|
|
@@ -197,7 +197,7 @@ export declare function pos(source: simple_string, str: simple_string): int;
|
|
|
197
197
|
* - fewer than N + 1 occurrences (or a negative N) leave the source unchanged
|
|
198
198
|
*
|
|
199
199
|
* @example
|
|
200
|
-
* ```
|
|
200
|
+
* ```js
|
|
201
201
|
* str.replace("hello world hello", "hello", "hi") // Returns: "hi world hello"
|
|
202
202
|
* str.replace("hello world hello", "hello", "hi", 1) // Returns: "hello world hi"
|
|
203
203
|
* str.replace("test", "xyz", "abc") // Returns: "test"
|
|
@@ -219,7 +219,7 @@ export declare function replace(source: simple_string, target: simple_string, re
|
|
|
219
219
|
* - This matches PineScript's `str.replace_all()` behavior
|
|
220
220
|
*
|
|
221
221
|
* @example
|
|
222
|
-
* ```
|
|
222
|
+
* ```js
|
|
223
223
|
* str.replace_all("hello world hello", "hello", "hi") // Returns: "hi world hi"
|
|
224
224
|
* str.replace_all("a-b-c", "-", "_") // Returns: "a_b_c"
|
|
225
225
|
* str.replace_all("test", "x", "y") // Returns: "test" (no match)
|
|
@@ -239,7 +239,7 @@ export declare function replace_all(source: simple_string, target: simple_string
|
|
|
239
239
|
* - Consecutive separators create empty strings in result
|
|
240
240
|
*
|
|
241
241
|
* @example
|
|
242
|
-
* ```
|
|
242
|
+
* ```js
|
|
243
243
|
* str.split("a,b,c", ",") // Returns: ["a", "b", "c"]
|
|
244
244
|
* str.split("hello", "") // Returns: ["h", "e", "l", "l", "o"]
|
|
245
245
|
* str.split("a,,b", ",") // Returns: ["a", "", "b"]
|
|
@@ -253,7 +253,7 @@ export declare function split(str: simple_string, separator: simple_string): str
|
|
|
253
253
|
* @returns The concatenated string
|
|
254
254
|
*
|
|
255
255
|
* @example
|
|
256
|
-
* ```
|
|
256
|
+
* ```js
|
|
257
257
|
* str.concat("hello", " ", "world") // Returns: "hello world"
|
|
258
258
|
* str.concat("a", "b", "c") // Returns: "abc"
|
|
259
259
|
* str.concat("test") // Returns: "test"
|
|
@@ -261,26 +261,28 @@ export declare function split(str: simple_string, separator: simple_string): str
|
|
|
261
261
|
*/
|
|
262
262
|
export declare function concat(...strings: simple_string[]): string;
|
|
263
263
|
/**
|
|
264
|
-
*
|
|
264
|
+
* Builds a text from a pattern and values: each `{0}`, `{1}`... is replaced by the argument at that position, e.g.
|
|
265
|
+
* `str.format("Close {0}, change {1,number,percent}", c.close, 0.025)`. Use it for labels and messages.
|
|
265
266
|
*
|
|
266
|
-
* @param
|
|
267
|
-
*
|
|
268
|
-
*
|
|
267
|
+
* @param pattern - The text with placeholders: `{0}` (a number shows as "#,##0.###"), `{1,number,#.##}` (number
|
|
268
|
+
* pattern), `{0,number,percent}`, `{0,number,integer}`, `{0,date,yyyy-MM-dd}` (a time in milliseconds); '...' in
|
|
269
|
+
* single quotes is kept as it is, '' is a quote
|
|
270
|
+
* @param args - The values of the placeholders, in order: numbers, texts, booleans, arrays
|
|
271
|
+
* @returns The text with the values in place
|
|
269
272
|
*
|
|
270
273
|
* @remarks
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* Dates are formatted in UTC here; PineScript uses the exchange time zone.
|
|
274
|
+
* - numbers in `{n}` use "#,##0.###" (1234.5678 gives "1,234.568"); number patterns round half to even on the
|
|
275
|
+
* exact value (16 decimals at most from 1e-3 up); an array gives "[a, b]"
|
|
276
|
+
* - a missing argument leaves `{n}` in the text
|
|
277
|
+
* - dates are written in the exchange time zone of the symbol in a script, in UTC when called outside a script
|
|
276
278
|
*
|
|
277
279
|
* @example
|
|
278
|
-
* ```
|
|
279
|
-
* str.format(
|
|
280
|
-
* str.format(
|
|
280
|
+
* ```js
|
|
281
|
+
* str.format("Close: {0,number,#.##}", 101.456) // Returns: "Close: 101.46"
|
|
282
|
+
* str.format("{0} and {1}", "a", 2) // Returns: "a and 2"
|
|
281
283
|
* ```
|
|
282
284
|
*/
|
|
283
|
-
export declare function format(
|
|
285
|
+
export declare function format(pattern: simple_string, ...args: any[]): string;
|
|
284
286
|
/**
|
|
285
287
|
* Checks if a string starts with a specific prefix.
|
|
286
288
|
*
|
|
@@ -293,7 +295,7 @@ export declare function format(formatStr: simple_string, ...args: any[]): string
|
|
|
293
295
|
* - Empty string prefix always returns true
|
|
294
296
|
*
|
|
295
297
|
* @example
|
|
296
|
-
* ```
|
|
298
|
+
* ```js
|
|
297
299
|
* str.startswith("hello world", "hello") // Returns: true
|
|
298
300
|
* str.startswith("hello world", "Hello") // Returns: false (case-sensitive)
|
|
299
301
|
* str.startswith("test", "testing") // Returns: false
|
|
@@ -312,7 +314,7 @@ export declare function startswith(source: simple_string, str: simple_string): b
|
|
|
312
314
|
* - Empty string suffix always returns true
|
|
313
315
|
*
|
|
314
316
|
* @example
|
|
315
|
-
* ```
|
|
317
|
+
* ```js
|
|
316
318
|
* str.endswith("hello world", "world") // Returns: true
|
|
317
319
|
* str.endswith("hello world", "World") // Returns: false (case-sensitive)
|
|
318
320
|
* str.endswith("testing", "test") // Returns: false
|
|
@@ -331,7 +333,7 @@ export declare function endswith(source: simple_string, str: simple_string): boo
|
|
|
331
333
|
* - Unicode characters may span multiple code units
|
|
332
334
|
*
|
|
333
335
|
* @example
|
|
334
|
-
* ```
|
|
336
|
+
* ```js
|
|
335
337
|
* str.charAt("hello", 0) // Returns: "h"
|
|
336
338
|
* str.charAt("hello", 4) // Returns: "o"
|
|
337
339
|
* str.charAt("hello", 10) // Returns: ""
|
|
@@ -349,7 +351,7 @@ export declare function charAt(str: simple_string, pos: simple_int): string;
|
|
|
349
351
|
* - Preserves internal whitespace
|
|
350
352
|
*
|
|
351
353
|
* @example
|
|
352
|
-
* ```
|
|
354
|
+
* ```js
|
|
353
355
|
* str.trim(" hello ") // Returns: "hello"
|
|
354
356
|
* str.trim(" hello world ") // Returns: "hello world"
|
|
355
357
|
* str.trim("\thello\n") // Returns: "hello"
|
|
@@ -367,7 +369,7 @@ export declare function trim(str: simple_string): string;
|
|
|
367
369
|
* - Preserves trailing and internal whitespace
|
|
368
370
|
*
|
|
369
371
|
* @example
|
|
370
|
-
* ```
|
|
372
|
+
* ```js
|
|
371
373
|
* str.trimLeft(" hello ") // Returns: "hello "
|
|
372
374
|
* str.trimLeft(" hello") // Returns: "hello"
|
|
373
375
|
* str.trimLeft("\thello") // Returns: "hello"
|
|
@@ -385,7 +387,7 @@ export declare function trimLeft(str: simple_string): string;
|
|
|
385
387
|
* - Preserves leading and internal whitespace
|
|
386
388
|
*
|
|
387
389
|
* @example
|
|
388
|
-
* ```
|
|
390
|
+
* ```js
|
|
389
391
|
* str.trimRight(" hello ") // Returns: " hello"
|
|
390
392
|
* str.trimRight("hello ") // Returns: "hello"
|
|
391
393
|
* str.trimRight("hello\t") // Returns: "hello"
|
|
@@ -404,48 +406,12 @@ export declare function trimRight(str: simple_string): string;
|
|
|
404
406
|
* - Uses JavaScript regex syntax
|
|
405
407
|
*
|
|
406
408
|
* @example
|
|
407
|
-
* ```
|
|
409
|
+
* ```js
|
|
408
410
|
* str.match("abc123def", "[0-9]+") // Returns: "123"
|
|
409
411
|
* str.match("abc", "[0-9]+") // Returns: null (na)
|
|
410
412
|
* ```
|
|
411
413
|
*/
|
|
412
414
|
export declare function match(source: simple_string, regex: simple_string): simple_string | null;
|
|
413
|
-
/**
|
|
414
|
-
* Formats a timestamp as a string according to the specified format.
|
|
415
|
-
*
|
|
416
|
-
* @param time - Unix timestamp in milliseconds
|
|
417
|
-
* @param format - Format string using PineScript format specifiers
|
|
418
|
-
* @returns Formatted date/time string
|
|
419
|
-
*
|
|
420
|
-
* @remarks
|
|
421
|
-
* Supported format specifiers (case-sensitive):
|
|
422
|
-
* - `yyyy` - 4-digit year (e.g., "2024")
|
|
423
|
-
* - `yy` - 2-digit year (e.g., "24")
|
|
424
|
-
* - `MMMM` - Full month name (e.g., "January")
|
|
425
|
-
* - `MMM` - Abbreviated month name (e.g., "Jan")
|
|
426
|
-
* - `MM` - 2-digit month (01-12)
|
|
427
|
-
* - `M` - Month (1-12)
|
|
428
|
-
* - `dd` - 2-digit day (01-31)
|
|
429
|
-
* - `d` - Day (1-31)
|
|
430
|
-
* - `HH` - 2-digit hour (00-23)
|
|
431
|
-
* - `H` - Hour (0-23)
|
|
432
|
-
* - `hh` - 2-digit hour (01-12)
|
|
433
|
-
* - `h` - Hour (1-12)
|
|
434
|
-
* - `mm` - 2-digit minute (00-59)
|
|
435
|
-
* - `m` - Minute (0-59)
|
|
436
|
-
* - `ss` - 2-digit second (00-59)
|
|
437
|
-
* - `s` - Second (0-59)
|
|
438
|
-
* - `a` - AM/PM
|
|
439
|
-
*
|
|
440
|
-
* @example
|
|
441
|
-
* ```typescript
|
|
442
|
-
* const timestamp = 1609459200000; // Jan 1, 2021 00:00:00 UTC
|
|
443
|
-
* str.format_time(timestamp, "dd MMM yyyy") // Returns: "01 Jan 2021"
|
|
444
|
-
* str.format_time(timestamp, "yyyy-MM-dd HH:mm:ss") // Returns: "2021-01-01 00:00:00"
|
|
445
|
-
* str.format_time(timestamp, "MMM d, yyyy") // Returns: "Jan 1, 2021"
|
|
446
|
-
* str.format_time(timestamp, "hh:mm a") // Returns: "12:00 AM"
|
|
447
|
-
* ```
|
|
448
|
-
*/
|
|
449
415
|
/**
|
|
450
416
|
* Constructs a new string containing the source string repeated N times with an optional separator.
|
|
451
417
|
*
|
|
@@ -455,7 +421,7 @@ export declare function match(source: simple_string, regex: simple_string): simp
|
|
|
455
421
|
* @returns The repeated string, or null (na) if source is na or count is 0 / negative / na, as in PineScript
|
|
456
422
|
*
|
|
457
423
|
* @example
|
|
458
|
-
* ```
|
|
424
|
+
* ```js
|
|
459
425
|
* str.repeat("ab", 3) // Returns: "ababab"
|
|
460
426
|
* str.repeat("?", 3, ",") // Returns: "?,?,?"
|
|
461
427
|
* str.repeat("hello", 0) // Returns: null (na)
|
|
@@ -464,17 +430,26 @@ export declare function match(source: simple_string, regex: simple_string): simp
|
|
|
464
430
|
*/
|
|
465
431
|
export declare function repeat(source: simple_string, count: simple_int, separator?: simple_string): string | null;
|
|
466
432
|
/**
|
|
467
|
-
*
|
|
433
|
+
* Writes a time as a date text, e.g. "2024-03-15 09:30". Use it for labels, tables and log messages.
|
|
468
434
|
*
|
|
469
|
-
* @param time -
|
|
470
|
-
* @param format -
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
* @
|
|
435
|
+
* @param time - The time in milliseconds since 1 January 1970 UTC, e.g. `time` on a bar or `timenow`
|
|
436
|
+
* @param format - Date pattern: `yyyy` year, `MM` month number, `MMM` month name, `dd` day, `EEE` weekday,
|
|
437
|
+
* `HH` hour (00-23), `hh` hour (01-12) with `a` (AM/PM), `mm` minutes, `ss` seconds, `SSS` milliseconds,
|
|
438
|
+
* `Z` / `z` time zone; 'text' in single quotes is kept as it is. Default: "yyyy-MM-dd'T'HH:mm:ssZ"
|
|
439
|
+
* @param timezone - Time zone of the text: a UTC offset ("UTC-5", "GMT+2") or a zone name ("America/New_York").
|
|
440
|
+
* Default in a script: the exchange time zone of the symbol; called outside a script: "Etc/UTC"
|
|
441
|
+
* @returns The date text
|
|
474
442
|
*
|
|
475
443
|
* @remarks
|
|
476
444
|
* Letters: y, M, d, E, u, D, w,
|
|
477
445
|
* H, k, K, h, a, m, s, S, Z, z; 'text' is literal text.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```js
|
|
449
|
+
* eachBar((c) => {
|
|
450
|
+
* if (c.i === c.n - 1) label.new(c.i, c.high, str.format_time(c.get(time), "yyyy-MM-dd HH:mm"));
|
|
451
|
+
* });
|
|
452
|
+
* ```
|
|
478
453
|
*/
|
|
479
454
|
export declare function format_time(time: simple_int, format?: simple_string, timezone?: simple_string): string;
|
|
480
455
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/str/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErF;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,GAAG,CAE9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,CAgDxG;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,KAAK,GAAG,IAAI,CASzD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,MAAM,CAGzF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAExE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa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gB,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAE1E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAExE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAElE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAE/C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEpD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,GAAG,IAAI,CAGvF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,GAAE,aAAkB,GAAG,MAAM,GAAG,IAAI,CAI7G;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,GAAE,aAAwC,EAAE,QAAQ,GAAE,aAAyB,GAAG,MAAM,CAE3I"}
|
package/dist/cjs/str/index.js
CHANGED
|
@@ -141,8 +141,8 @@ function split(str, separator) {
|
|
|
141
141
|
function concat(...strings) {
|
|
142
142
|
return strings.join("");
|
|
143
143
|
}
|
|
144
|
-
function format(
|
|
145
|
-
return (0, import_messageformat.formatMessage)(
|
|
144
|
+
function format(pattern, ...args) {
|
|
145
|
+
return (0, import_messageformat.formatMessage)(pattern, args, "Etc/UTC");
|
|
146
146
|
}
|
|
147
147
|
function startswith(source, str) {
|
|
148
148
|
return source.startsWith(str);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/str/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * String namespace\n * Mirrors PineScript's str.* functions for string manipulation and analysis.\n *\n * @remarks\n * All string functions in this namespace follow PineScript v6 API specifications.\n * String operations are case-sensitive unless otherwise specified.\n *\n * @version 6\n */\n\nimport { formatNumber, tickScale } from './numberformat.js';\nimport { formatMessage } from './messageformat.js';\nimport { formatDate } from './dateformat.js';\nimport type { int, bool, float, simple_int, simple_string } from '../types/index.js';\n\n/**\n * Returns the length of a string.\n *\n * @param str - The string to measure\n * @returns The number of characters in the string\n *\n * @example\n * ```typescript\n * str.length(\"Hello\") // Returns: 5\n * str.length(\"\") // Returns: 0\n * ```\n */\nexport function length(str: simple_string): int {\n return str.length;\n}\n\n/**\n * Converts a value to its string representation (PineScript `str.tostring`).\n *\n * @param value - The value to convert (number, boolean, string, etc.)\n * @param format - Optional number format: a pattern (\"#.##\", \"#,###.00\", \"0.00%\", \"0.00E0\", \"#.##;(#.##)\") or\n * `format.percent` (\"percent\"), `format.volume` (\"volume\"), `format.mintick` (\"mintick\"),\n * `format.price` / `format.inherit`\n * @param mintick - Tick size for `format.mintick` (PineScript `syminfo.mintick`, implicit there). Not part of the\n * PineScript signature: the core function cannot see the chart, so pass it, as for `math.round_to_mintick`\n * @param pricescale - Price scale of the symbol for `format.mintick` (PineScript `syminfo.pricescale`), needed for a\n * symbol priced in fractions (32 for a 1/32 tick). Default: 10^(decimals of `mintick`)\n * @returns String representation of the value\n *\n * @remarks\n * As in PineScript:\n * - without format, numbers show up to 10 decimals (\"0.3333333333\"): the digits of the JVM's binary to decimal\n * conversion, rounded half to even, a tie on the last converted digit decided by the conversion\n * (82325.10000000005 gives \"82325.1\", with the format \"#.##########\" \"82325.1000000001\"; 1791662400001 / 900000\n * gives \"1990736.000001111\"; 78195689105219552 keeps its 17 digits); 1e21 and more use \"1E21\"\n * - patterns round half away from zero on the shortest decimal form: 1.005 with \"#.##\" gives \"1.01\";\n * at most 16 decimals from 1e-3 up (0.0012345678901234567 with 20 '#' decimals gives \"0.0012345678901235\")\n * - \"pos;neg\" patterns: a negative number takes the text of the negative subpattern (\"#.##;(#.##)\": \"(3.5)\")\n * - \"#\" is an optional digit (\"1.5\" with \"#.##\"), \"0\" a required digit (\"1.50\" with \"0.00\"),\n * \",\" groups thousands, \"%\" multiplies by 100, 'text' is literal text\n * - `format.percent` shows 2 decimals and \"%\" without multiplying; `format.volume` uses K, M, B, T\n * - `format.price` and `format.inherit` give \"price1\" / \"inherit1\" in PineScript: they are patterns\n * without digit characters, and oakscriptjs does the same\n * - `format.mintick` shows floor(log10(pricescale)) decimals, zeros included (\"1.00\", \"0.40\" for tick 0.01), and\n * rounds in two steps, with mintick = minmove / pricescale: the double quotient `|x| / (1 / pricescale)` half away\n * from zero (140.355 / 0.01 = 14035.499999999998 gives \"140.35\", where `math.round_to_mintick` gives 140.36),\n * then `floor(units / minmove + 0.5)` ticks (tick 0.02: 0.005 gives \"0.02\", -0.01 gives \"0.00\"). With a\n * pricescale that is no power of 10 the tick value is then rounded half even to those decimals (1/32: 25.25 gives\n * \"25.2\", -0.02 gives \"-0.0\"). It throws without `mintick`\n * - na gives \"NaN\" (\"NaN%\" with `format.percent`); an infinity gives \"NaN\" too (\"NaN%\" for `format.percent`,\n * \"NaNT\" for `format.volume`), except `format.mintick`, which gives \"Infinity\" / \"-Infinity\"\n *\n * @example\n * ```typescript\n * str.tostring(123) // \"123\"\n * str.tostring(1.5, \"#.##\") // \"1.5\"\n * str.tostring(0.5, \"#.00\") // \".50\"\n * str.tostring(12345.678, format.volume) // \"12.346K\"\n * ```\n */\nexport function tostring(value: any, format?: simple_string, mintick?: float, pricescale?: float): string {\n // an array: \"[a, b]\", each element as a single value\n if (Array.isArray(value)) return '[' + value.map((v) => tostring(v, format, mintick, pricescale)).join(', ') + ']';\n if (typeof value !== 'number') return String(value);\n if (Number.isNaN(value)) return format === 'percent' ? 'NaN%' : 'NaN';\n if (!Number.isFinite(value)) {\n // the chart formatter has no infinity: NaN with the format's suffix\n if (format === 'mintick') return String(value);\n return format === 'percent' ? 'NaN%' : format === 'volume' ? 'NaNT' : 'NaN';\n }\n if (format === undefined || format === '') {\n if (Math.abs(value) >= 1e21 && Number.isFinite(value)) {\n return String(value).replace('e+', 'E').replace(/\\.0+E/, 'E');\n }\n // without a format: the digits of the JVM conversion, 10 decimals half to even (#171, #174)\n return formatNumber(value, '#.##########', 'halfEvenConverted');\n }\n switch (format) {\n case 'percent':\n return formatNumber(value, '0.00', 'halfUpShortest') + '%';\n case 'volume': {\n const abs = Math.abs(value);\n for (const [size, unit] of [[1e12, 'T'], [1e9, 'B'], [1e6, 'M'], [1e3, 'K']] as const) {\n if (abs >= size) return formatNumber(value / size, '#.###', 'halfUpShortest') + unit;\n }\n return formatNumber(value, '#', 'halfUpShortest');\n }\n case 'mintick': {\n if (mintick === undefined) {\n throw new Error('str.tostring(x, format.mintick) needs the tick size: pass it as str.tostring(x, format.mintick, syminfo.mintick)');\n }\n const [minmove, scale] = tickScale(mintick, pricescale);\n const decimals = Math.floor(Math.log10(scale) + 1e-9);\n const mask = decimals > 0 ? '0.' + '0'.repeat(decimals) : '0';\n if (!(minmove >= 1)) return formatNumber(value, mask, 'halfUpShortest');\n // 1. the double quotient |x| / (1 / pricescale), half away from zero (not math.round_to_mintick's exact decimal)\n const scaled = Math.abs(value) / (1 / scale);\n let units = Math.trunc(scaled);\n if (scaled - units >= 0.5) units++;\n // 2. to the tick, a half going up (minmove 2: -0.01 gives \"0.00\", 0.01 gives \"0.02\")\n const ticks = Math.floor((value < 0 ? -units : units) / minmove + 0.5);\n // 3. the tick value at the scale's decimals; a negative one keeps its sign when it prints as zero (\"-0.0\")\n const text = formatNumber((Math.abs(ticks) * minmove) / scale, mask, 'halfEvenExact');\n return ticks < 0 ? '-' + text : text;\n }\n default:\n return formatNumber(value, format, 'halfUpShortest');\n }\n}\n\n/**\n * Converts a string to a number (float).\n *\n * @param str - The string to convert\n * @returns The numeric value, or null (na) if conversion fails\n *\n * @remarks\n * As in PineScript:\n * - The whole text must be a number: a sign, digits and one optional \".\" (\"0.5\", \".5\", \"5.\", \"-12\"); \"12abc\" is na\n * - Scientific notation (\"1e3\"), \"Infinity\", \"NaN\", hexadecimal, \"1,000\" give na\n * - The characters U+0000 to U+0020 (space, tab, line feed...) around the number are ignored; other spaces\n * (no-break space U+00A0, U+3000) give na\n *\n * @example\n * ```typescript\n * str.tonumber(\"123\") // Returns: 123\n * str.tonumber(\"45.67\") // Returns: 45.67\n * str.tonumber(\"abc\") // Returns: null\n * str.tonumber(\"12abc\") // Returns: null\n * str.tonumber(\"1e3\") // Returns: null\n * ```\n */\nexport function tonumber(str: simple_string): float | null {\n // remove the characters U+0000..U+0020 at both ends\n let start = 0;\n let end = str.length;\n while (start < end && str.charCodeAt(start) <= 0x20) start++;\n while (end > start && str.charCodeAt(end - 1) <= 0x20) end--;\n const text = str.slice(start, end);\n if (!/^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)$/.test(text)) return null;\n return parseFloat(text);\n}\n\n/**\n * Extracts a substring from a string.\n *\n * @param str - The source string\n * @param begin - Starting index (0-based, inclusive)\n * @param end - Ending index (0-based, exclusive). If omitted, extracts to end of string\n * @returns The extracted substring\n *\n * @remarks\n * - An na `end` (NaN / null) is a runtime error in PineScript: it throws\n * - If begin > end, indices are swapped (JavaScript behavior)\n * - Negative indices are treated as 0\n * - Indices beyond string length return empty string\n *\n * @example\n * ```typescript\n * str.substring(\"hello world\", 0, 5) // Returns: \"hello\"\n * str.substring(\"hello world\", 6) // Returns: \"world\"\n * str.substring(\"test\", 1, 3) // Returns: \"es\"\n * ```\n */\nexport function substring(str: simple_string, begin: simple_int, end?: simple_int): string {\n if (end === null || Number.isNaN(end)) throw new Error('str.substring: the end position is na');\n return str.substring(begin, end);\n}\n\n/**\n * Converts all characters in a string to uppercase.\n *\n * @param str - The string to convert\n * @returns The uppercase string\n *\n * @example\n * ```typescript\n * str.upper(\"hello\") // Returns: \"HELLO\"\n * str.upper(\"Hello World\") // Returns: \"HELLO WORLD\"\n * str.upper(\"test123\") // Returns: \"TEST123\"\n * ```\n */\nexport function upper(str: simple_string): string {\n return str.toUpperCase();\n}\n\n/**\n * Converts all characters in a string to lowercase.\n *\n * @param str - The string to convert\n * @returns The lowercase string\n *\n * @example\n * ```typescript\n * str.lower(\"HELLO\") // Returns: \"hello\"\n * str.lower(\"Hello World\") // Returns: \"hello world\"\n * str.lower(\"TEST123\") // Returns: \"test123\"\n * ```\n */\nexport function lower(str: simple_string): string {\n return str.toLowerCase();\n}\n\n/**\n * Checks if a string contains a substring.\n *\n * @param source - The string to search in\n * @param str - The substring to search for\n * @returns True if source contains str, false otherwise\n *\n * @remarks\n * - Search is case-sensitive\n * - Empty string is contained in any string\n *\n * @example\n * ```typescript\n * str.contains(\"hello world\", \"world\") // Returns: true\n * str.contains(\"hello world\", \"World\") // Returns: false (case-sensitive)\n * str.contains(\"test\", \"xyz\") // Returns: false\n * ```\n */\nexport function contains(source: simple_string, str: simple_string): bool {\n return source.includes(str);\n}\n\n/**\n * Returns the position of the first occurrence of a substring.\n *\n * @param source - The string to search in\n * @param str - The substring to search for\n * @returns The 0-based index of the first occurrence, or na (NaN) if not found\n *\n * @remarks\n * - Search is case-sensitive\n * - Returns 0 for empty search string\n * - Returns na (NaN) if substring is not found, as in PineScript\n *\n * @example\n * ```typescript\n * str.pos(\"hello world\", \"world\") // Returns: 6\n * str.pos(\"hello world\", \"o\") // Returns: 4 (first occurrence)\n * str.pos(\"hello\", \"xyz\") // Returns: NaN (na)\n * ```\n */\nexport function pos(source: simple_string, str: simple_string): int {\n const index = source.indexOf(str);\n return index === -1 ? NaN : index;\n}\n\n/**\n * Replaces the Nth occurrence of a substring (PineScript `str.replace`).\n *\n * @param source - The source string\n * @param target - The substring to replace\n * @param replacement - The string to replace with\n * @param occurrence - 0-based occurrence to replace (default 0, the first one)\n * @returns The string with one occurrence replaced\n *\n * @remarks\n * PineScript rules:\n * - only the Nth occurrence is replaced; an na occurrence is 0 (`str.replace(\"aaa\", \"a\", \"-\", na)` is \"-aa\")\n * - occurrences overlap: \"aa\" occurs at 0 and 1 in \"aaa\" (`str.replace(\"aaa\", \"aa\", \"-\", 1)` is \"a-\")\n * - an empty target inserts the replacement at character N, at most at the end\n * (`str.replace(\"abc\", \"\", \"-\", 2)` is \"ab-c\")\n * - fewer than N + 1 occurrences (or a negative N) leave the source unchanged\n *\n * @example\n * ```typescript\n * str.replace(\"hello world hello\", \"hello\", \"hi\") // Returns: \"hi world hello\"\n * str.replace(\"hello world hello\", \"hello\", \"hi\", 1) // Returns: \"hello world hi\"\n * str.replace(\"test\", \"xyz\", \"abc\") // Returns: \"test\"\n * ```\n */\nexport function replace(source: simple_string, target: simple_string, replacement: simple_string, occurrence: simple_int = 0): string {\n const n = occurrence === null || Number.isNaN(occurrence) ? 0 : Math.trunc(occurrence);\n if (n < 0) return source;\n let index: number;\n if (target === '') {\n index = Math.min(n, source.length);\n } else {\n index = -1;\n for (let k = 0; k <= n; k++) {\n index = source.indexOf(target, index + 1);\n if (index === -1) return source;\n }\n }\n return source.slice(0, index) + replacement + source.slice(index + target.length);\n}\n\n/**\n * Replaces all occurrences of a target string with a replacement string.\n *\n * @param source - The source string\n * @param target - The substring to find\n * @param replacement - The replacement string\n * @returns String with all occurrences replaced\n *\n * @remarks\n * - Replaces all occurrences of the target string\n * - Case sensitive\n * - If target is empty string, returns original string\n * - This matches PineScript's `str.replace_all()` behavior\n *\n * @example\n * ```typescript\n * str.replace_all(\"hello world hello\", \"hello\", \"hi\") // Returns: \"hi world hi\"\n * str.replace_all(\"a-b-c\", \"-\", \"_\") // Returns: \"a_b_c\"\n * str.replace_all(\"test\", \"x\", \"y\") // Returns: \"test\" (no match)\n * ```\n */\nexport function replace_all(source: simple_string, target: simple_string, replacement: simple_string): string {\n return source.replaceAll(target, replacement);\n}\n\n/**\n * Splits a string into an array of substrings using a separator.\n *\n * @param str - The string to split\n * @param separator - The separator string\n * @returns Array of substrings\n *\n * @remarks\n * - Empty separator splits into individual characters; an empty string gives [\"\"] (also with \"\")\n * - If separator is not found, returns array with original string\n * - Consecutive separators create empty strings in result\n *\n * @example\n * ```typescript\n * str.split(\"a,b,c\", \",\") // Returns: [\"a\", \"b\", \"c\"]\n * str.split(\"hello\", \"\") // Returns: [\"h\", \"e\", \"l\", \"l\", \"o\"]\n * str.split(\"a,,b\", \",\") // Returns: [\"a\", \"\", \"b\"]\n * ```\n */\nexport function split(str: simple_string, separator: simple_string): string[] {\n // JavaScript gives [] for \"\".split(\"\"); PineScript gives [\"\"]\n return str === '' ? [''] : str.split(separator);\n}\n\n/**\n * Concatenates multiple strings into one.\n *\n * @param strings - Variable number of strings to concatenate\n * @returns The concatenated string\n *\n * @example\n * ```typescript\n * str.concat(\"hello\", \" \", \"world\") // Returns: \"hello world\"\n * str.concat(\"a\", \"b\", \"c\") // Returns: \"abc\"\n * str.concat(\"test\") // Returns: \"test\"\n * ```\n */\nexport function concat(...strings: simple_string[]): string {\n return strings.join('');\n}\n\n/**\n * Formats a string with placeholders (PineScript `str.format`, Java MessageFormat syntax).\n *\n * @param formatStr - Pattern with `{0}`, `{1,number,#.##}`, `{0,number,percent}`, `{0,date,yyyy-MM-dd}`...\n * @param args - Values for the placeholders\n * @returns Formatted string\n *\n * @remarks\n * As in PineScript: numbers in `{n}` use\n * \"#,##0.###\" (1234.5678 gives \"1,234.568\"); number patterns round half to even on the exact\n * value (16 decimals at most from 1e-3 up); an array gives \"[a, b]\"; `'...'` is literal text and `''` a quote;\n * a missing argument leaves `{n}` in the text.\n * Dates are formatted in UTC here; PineScript uses the exchange time zone.\n *\n * @example\n * ```typescript\n * str.format('Close: {0,number,#.##}', 101.456) // \"Close: 101.46\"\n * str.format('{0} and {1}', 'a', 2) // \"a and 2\"\n * ```\n */\nexport function format(formatStr: simple_string, ...args: any[]): string {\n return formatMessage(formatStr, args, 'Etc/UTC');\n}\n\n/**\n * Checks if a string starts with a specific prefix.\n *\n * @param source - The string to check\n * @param str - The prefix to look for\n * @returns True if source starts with str, false otherwise\n *\n * @remarks\n * - Search is case-sensitive\n * - Empty string prefix always returns true\n *\n * @example\n * ```typescript\n * str.startswith(\"hello world\", \"hello\") // Returns: true\n * str.startswith(\"hello world\", \"Hello\") // Returns: false (case-sensitive)\n * str.startswith(\"test\", \"testing\") // Returns: false\n * ```\n */\nexport function startswith(source: simple_string, str: simple_string): bool {\n return source.startsWith(str);\n}\n\n/**\n * Checks if a string ends with a specific suffix.\n *\n * @param source - The string to check\n * @param str - The suffix to look for\n * @returns True if source ends with str, false otherwise\n *\n * @remarks\n * - Search is case-sensitive\n * - Empty string suffix always returns true\n *\n * @example\n * ```typescript\n * str.endswith(\"hello world\", \"world\") // Returns: true\n * str.endswith(\"hello world\", \"World\") // Returns: false (case-sensitive)\n * str.endswith(\"testing\", \"test\") // Returns: false\n * ```\n */\nexport function endswith(source: simple_string, str: simple_string): bool {\n return source.endsWith(str);\n}\n\n/**\n * Returns the character at a specific position in a string.\n *\n * @param str - The source string\n * @param pos - The 0-based position\n * @returns The character at the position, or empty string if out of bounds\n *\n * @remarks\n * - Returns empty string for negative or out-of-bounds positions\n * - Unicode characters may span multiple code units\n *\n * @example\n * ```typescript\n * str.charAt(\"hello\", 0) // Returns: \"h\"\n * str.charAt(\"hello\", 4) // Returns: \"o\"\n * str.charAt(\"hello\", 10) // Returns: \"\"\n * ```\n */\nexport function charAt(str: simple_string, pos: simple_int): string {\n return str.charAt(pos);\n}\n\n/**\n * Removes whitespace from both ends of a string.\n *\n * @param str - The string to trim\n * @returns The trimmed string\n *\n * @remarks\n * - Removes spaces, tabs, newlines, and other whitespace characters\n * - Preserves internal whitespace\n *\n * @example\n * ```typescript\n * str.trim(\" hello \") // Returns: \"hello\"\n * str.trim(\" hello world \") // Returns: \"hello world\"\n * str.trim(\"\\thello\\n\") // Returns: \"hello\"\n * ```\n */\nexport function trim(str: simple_string): string {\n return str.trim();\n}\n\n/**\n * Removes whitespace from the left (start) of a string.\n *\n * @param str - The string to trim\n * @returns The trimmed string\n *\n * @remarks\n * - Only removes leading whitespace\n * - Preserves trailing and internal whitespace\n *\n * @example\n * ```typescript\n * str.trimLeft(\" hello \") // Returns: \"hello \"\n * str.trimLeft(\" hello\") // Returns: \"hello\"\n * str.trimLeft(\"\\thello\") // Returns: \"hello\"\n * ```\n */\nexport function trimLeft(str: simple_string): string {\n return str.trimStart();\n}\n\n/**\n * Removes whitespace from the right (end) of a string.\n *\n * @param str - The string to trim\n * @returns The trimmed string\n *\n * @remarks\n * - Only removes trailing whitespace\n * - Preserves leading and internal whitespace\n *\n * @example\n * ```typescript\n * str.trimRight(\" hello \") // Returns: \" hello\"\n * str.trimRight(\"hello \") // Returns: \"hello\"\n * str.trimRight(\"hello\\t\") // Returns: \"hello\"\n * ```\n */\nexport function trimRight(str: simple_string): string {\n return str.trimEnd();\n}\n\n/**\n * Returns the first substring of `source` that matches the `regex` (PineScript `str.match`).\n *\n * @param source - Source string\n * @param regex - Regular expression\n * @returns The first match (searched anywhere in the string), or na (null) when nothing matches or the match is empty\n *\n * @remarks\n * - As PineScript: \"Hello World!\" with \"o\" gives \"o\", with \"[a-z]+\" gives \"ello\"; no match gives na\n * - Uses JavaScript regex syntax\n *\n * @example\n * ```typescript\n * str.match(\"abc123def\", \"[0-9]+\") // Returns: \"123\"\n * str.match(\"abc\", \"[0-9]+\") // Returns: null (na)\n * ```\n */\nexport function match(source: simple_string, regex: simple_string): simple_string | null {\n const found = new RegExp(regex).exec(source);\n return found && found[0] !== '' ? found[0] : null;\n}\n\n/**\n * Formats a timestamp as a string according to the specified format.\n *\n * @param time - Unix timestamp in milliseconds\n * @param format - Format string using PineScript format specifiers\n * @returns Formatted date/time string\n *\n * @remarks\n * Supported format specifiers (case-sensitive):\n * - `yyyy` - 4-digit year (e.g., \"2024\")\n * - `yy` - 2-digit year (e.g., \"24\")\n * - `MMMM` - Full month name (e.g., \"January\")\n * - `MMM` - Abbreviated month name (e.g., \"Jan\")\n * - `MM` - 2-digit month (01-12)\n * - `M` - Month (1-12)\n * - `dd` - 2-digit day (01-31)\n * - `d` - Day (1-31)\n * - `HH` - 2-digit hour (00-23)\n * - `H` - Hour (0-23)\n * - `hh` - 2-digit hour (01-12)\n * - `h` - Hour (1-12)\n * - `mm` - 2-digit minute (00-59)\n * - `m` - Minute (0-59)\n * - `ss` - 2-digit second (00-59)\n * - `s` - Second (0-59)\n * - `a` - AM/PM\n *\n * @example\n * ```typescript\n * const timestamp = 1609459200000; // Jan 1, 2021 00:00:00 UTC\n * str.format_time(timestamp, \"dd MMM yyyy\") // Returns: \"01 Jan 2021\"\n * str.format_time(timestamp, \"yyyy-MM-dd HH:mm:ss\") // Returns: \"2021-01-01 00:00:00\"\n * str.format_time(timestamp, \"MMM d, yyyy\") // Returns: \"Jan 1, 2021\"\n * str.format_time(timestamp, \"hh:mm a\") // Returns: \"12:00 AM\"\n * ```\n */\n/**\n * Constructs a new string containing the source string repeated N times with an optional separator.\n *\n * @param source - The string to repeat\n * @param count - Number of times to repeat\n * @param separator - String to inject between repeated instances. Optional, defaults to empty string.\n * @returns The repeated string, or null (na) if source is na or count is 0 / negative / na, as in PineScript\n *\n * @example\n * ```typescript\n * str.repeat(\"ab\", 3) // Returns: \"ababab\"\n * str.repeat(\"?\", 3, \",\") // Returns: \"?,?,?\"\n * str.repeat(\"hello\", 0) // Returns: null (na)\n * str.repeat(\"x\", 1) // Returns: \"x\"\n * ```\n */\nexport function repeat(source: simple_string, count: simple_int, separator: simple_string = ''): string | null {\n if (source == null) return null;\n if (!(count > 0)) return null; // 0, negative or na: na\n return Array(count).fill(source).join(separator);\n}\n\n/**\n * Formats a UNIX time (ms) with a date pattern (PineScript `str.format_time`).\n *\n * @param time - UNIX time in milliseconds\n * @param format - Java SimpleDateFormat pattern, e.g. \"yyyy-MM-dd HH:mm:ss\", \"dd MMM yyyy\", \"hh:mm a\"\n * @param timezone - UTC/GMT offset (\"UTC-5\") or IANA name (\"America/New_York\"). PineScript's default is\n * the exchange time zone, which is not known here: the default is UTC\n * @returns Formatted date string\n *\n * @remarks\n * Letters: y, M, d, E, u, D, w,\n * H, k, K, h, a, m, s, S, Z, z; 'text' is literal text.\n */\nexport function format_time(time: simple_int, format: simple_string = \"yyyy-MM-dd'T'HH:mm:ssZ\", timezone: simple_string = 'Etc/UTC'): string {\n return formatDate(time, format, timezone);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,0BAAwC;AACxC,2BAA8B;AAC9B,wBAA2B;AAepB,SAAS,OAAO,KAAyB;AAC9C,SAAO,IAAI;AACb;AA8CO,SAAS,SAAS,OAAYA,SAAwB,SAAiB,YAA4B;AAExG,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,MAAM,IAAI,CAAC,MAAM,SAAS,GAAGA,SAAQ,SAAS,UAAU,CAAC,EAAE,KAAK,IAAI,IAAI;AAC/G,MAAI,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK;AAClD,MAAI,OAAO,MAAM,KAAK,EAAG,QAAOA,YAAW,YAAY,SAAS;AAChE,MAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAE3B,QAAIA,YAAW,UAAW,QAAO,OAAO,KAAK;AAC7C,WAAOA,YAAW,YAAY,SAASA,YAAW,WAAW,SAAS;AAAA,EACxE;AACA,MAAIA,YAAW,UAAaA,YAAW,IAAI;AACzC,QAAI,KAAK,IAAI,KAAK,KAAK,QAAQ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AAAA,IAC3B;AAAA,EACF;AACA,SAAO,OAAO,MAAM,GAAG,KAAK,IAAI,cAAc,OAAO,MAAM,QAAQ,OAAO,MAAM;AAClF;AAuBO,SAAS,YAAY,QAAuB,QAAuB,aAAoC;AAC5G,SAAO,OAAO,WAAW,QAAQ,WAAW;AAC9C;AAqBO,SAAS,MAAM,KAAoB,WAAoC;AAE5E,SAAO,QAAQ,KAAK,CAAC,EAAE,IAAI,IAAI,MAAM,SAAS;AAChD;AAeO,SAAS,UAAU,SAAkC;AAC1D,SAAO,QAAQ,KAAK,EAAE;AACxB;
|
|
4
|
+
"sourcesContent": ["/**\n * String namespace\n * Mirrors PineScript's str.* functions for string manipulation and analysis.\n *\n * @remarks\n * All string functions in this namespace follow PineScript v6 API specifications.\n * String operations are case-sensitive unless otherwise specified.\n *\n * @version 6\n */\n\nimport { formatNumber, tickScale } from './numberformat.js';\nimport { formatMessage } from './messageformat.js';\nimport { formatDate } from './dateformat.js';\nimport type { int, bool, float, simple_int, simple_string } from '../types/index.js';\n\n/**\n * Returns the length of a string.\n *\n * @param str - The string to measure\n * @returns The number of characters in the string\n *\n * @example\n * ```js\n * str.length(\"Hello\") // Returns: 5\n * str.length(\"\") // Returns: 0\n * ```\n */\nexport function length(str: simple_string): int {\n return str.length;\n}\n\n/**\n * Converts a value to its string representation (PineScript `str.tostring`).\n *\n * @param value - The value to convert (number, boolean, string, etc.)\n * @param format - Optional number format: a pattern (\"#.##\", \"#,###.00\", \"0.00%\", \"0.00E0\", \"#.##;(#.##)\") or\n * `format.percent` (\"percent\"), `format.volume` (\"volume\"), `format.mintick` (\"mintick\"),\n * `format.price` / `format.inherit`\n * @param mintick - Tick size for `format.mintick` (PineScript `syminfo.mintick`, implicit there). Not part of the\n * PineScript signature: the core function cannot see the chart, so pass it, as for `math.round_to_mintick`\n * @param pricescale - Price scale of the symbol for `format.mintick` (PineScript `syminfo.pricescale`), needed for a\n * symbol priced in fractions (32 for a 1/32 tick). Default: 10^(decimals of `mintick`)\n * @returns String representation of the value\n *\n * @remarks\n * As in PineScript:\n * - without format, numbers show up to 10 decimals (\"0.3333333333\"): the digits of the JVM's binary to decimal\n * conversion, rounded half to even, a tie on the last converted digit decided by the conversion\n * (82325.10000000005 gives \"82325.1\", with the format \"#.##########\" \"82325.1000000001\"; 1791662400001 / 900000\n * gives \"1990736.000001111\"; 78195689105219552 keeps its 17 digits); 1e21 and more use \"1E21\"\n * - patterns round half away from zero on the shortest decimal form: 1.005 with \"#.##\" gives \"1.01\";\n * at most 16 decimals from 1e-3 up (0.0012345678901234567 with 20 '#' decimals gives \"0.0012345678901235\")\n * - \"pos;neg\" patterns: a negative number takes the text of the negative subpattern (\"#.##;(#.##)\": \"(3.5)\")\n * - \"#\" is an optional digit (\"1.5\" with \"#.##\"), \"0\" a required digit (\"1.50\" with \"0.00\"),\n * \",\" groups thousands, \"%\" multiplies by 100, 'text' is literal text\n * - `format.percent` shows 2 decimals and \"%\" without multiplying; `format.volume` uses K, M, B, T\n * - `format.price` and `format.inherit` give \"price1\" / \"inherit1\" in PineScript: they are patterns\n * without digit characters, and oakscriptjs does the same\n * - `format.mintick` shows floor(log10(pricescale)) decimals, zeros included (\"1.00\", \"0.40\" for tick 0.01), and\n * rounds in two steps, with mintick = minmove / pricescale: the double quotient `|x| / (1 / pricescale)` half away\n * from zero (140.355 / 0.01 = 14035.499999999998 gives \"140.35\", where `math.round_to_mintick` gives 140.36),\n * then `floor(units / minmove + 0.5)` ticks (tick 0.02: 0.005 gives \"0.02\", -0.01 gives \"0.00\"). With a\n * pricescale that is no power of 10 the tick value is then rounded half even to those decimals (1/32: 25.25 gives\n * \"25.2\", -0.02 gives \"-0.0\"). It throws without `mintick`\n * - na gives \"NaN\" (\"NaN%\" with `format.percent`); an infinity gives \"NaN\" too (\"NaN%\" for `format.percent`,\n * \"NaNT\" for `format.volume`), except `format.mintick`, which gives \"Infinity\" / \"-Infinity\"\n *\n * @example\n * ```js\n * str.tostring(123) // \"123\"\n * str.tostring(1.5, \"#.##\") // \"1.5\"\n * str.tostring(0.5, \"#.00\") // \".50\"\n * str.tostring(12345.678, format.volume) // \"12.346K\"\n * ```\n */\nexport function tostring(value: any, format?: simple_string, mintick?: float, pricescale?: float): string {\n // an array: \"[a, b]\", each element as a single value\n if (Array.isArray(value)) return '[' + value.map((v) => tostring(v, format, mintick, pricescale)).join(', ') + ']';\n if (typeof value !== 'number') return String(value);\n if (Number.isNaN(value)) return format === 'percent' ? 'NaN%' : 'NaN';\n if (!Number.isFinite(value)) {\n // the chart formatter has no infinity: NaN with the format's suffix\n if (format === 'mintick') return String(value);\n return format === 'percent' ? 'NaN%' : format === 'volume' ? 'NaNT' : 'NaN';\n }\n if (format === undefined || format === '') {\n if (Math.abs(value) >= 1e21 && Number.isFinite(value)) {\n return String(value).replace('e+', 'E').replace(/\\.0+E/, 'E');\n }\n // without a format: the digits of the JVM conversion, 10 decimals half to even (#171, #174)\n return formatNumber(value, '#.##########', 'halfEvenConverted');\n }\n switch (format) {\n case 'percent':\n return formatNumber(value, '0.00', 'halfUpShortest') + '%';\n case 'volume': {\n const abs = Math.abs(value);\n for (const [size, unit] of [[1e12, 'T'], [1e9, 'B'], [1e6, 'M'], [1e3, 'K']] as const) {\n if (abs >= size) return formatNumber(value / size, '#.###', 'halfUpShortest') + unit;\n }\n return formatNumber(value, '#', 'halfUpShortest');\n }\n case 'mintick': {\n if (mintick === undefined) {\n throw new Error('str.tostring(x, format.mintick) needs the tick size: pass it as str.tostring(x, format.mintick, syminfo.mintick)');\n }\n const [minmove, scale] = tickScale(mintick, pricescale);\n const decimals = Math.floor(Math.log10(scale) + 1e-9);\n const mask = decimals > 0 ? '0.' + '0'.repeat(decimals) : '0';\n if (!(minmove >= 1)) return formatNumber(value, mask, 'halfUpShortest');\n // 1. the double quotient |x| / (1 / pricescale), half away from zero (not math.round_to_mintick's exact decimal)\n const scaled = Math.abs(value) / (1 / scale);\n let units = Math.trunc(scaled);\n if (scaled - units >= 0.5) units++;\n // 2. to the tick, a half going up (minmove 2: -0.01 gives \"0.00\", 0.01 gives \"0.02\")\n const ticks = Math.floor((value < 0 ? -units : units) / minmove + 0.5);\n // 3. the tick value at the scale's decimals; a negative one keeps its sign when it prints as zero (\"-0.0\")\n const text = formatNumber((Math.abs(ticks) * minmove) / scale, mask, 'halfEvenExact');\n return ticks < 0 ? '-' + text : text;\n }\n default:\n return formatNumber(value, format, 'halfUpShortest');\n }\n}\n\n/**\n * Converts a string to a number (float).\n *\n * @param str - The string to convert\n * @returns The numeric value, or null (na) if conversion fails\n *\n * @remarks\n * As in PineScript:\n * - The whole text must be a number: a sign, digits and one optional \".\" (\"0.5\", \".5\", \"5.\", \"-12\"); \"12abc\" is na\n * - Scientific notation (\"1e3\"), \"Infinity\", \"NaN\", hexadecimal, \"1,000\" give na\n * - The characters U+0000 to U+0020 (space, tab, line feed...) around the number are ignored; other spaces\n * (no-break space U+00A0, U+3000) give na\n *\n * @example\n * ```js\n * str.tonumber(\"123\") // Returns: 123\n * str.tonumber(\"45.67\") // Returns: 45.67\n * str.tonumber(\"abc\") // Returns: null\n * str.tonumber(\"12abc\") // Returns: null\n * str.tonumber(\"1e3\") // Returns: null\n * ```\n */\nexport function tonumber(str: simple_string): float | null {\n // remove the characters U+0000..U+0020 at both ends\n let start = 0;\n let end = str.length;\n while (start < end && str.charCodeAt(start) <= 0x20) start++;\n while (end > start && str.charCodeAt(end - 1) <= 0x20) end--;\n const text = str.slice(start, end);\n if (!/^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)$/.test(text)) return null;\n return parseFloat(text);\n}\n\n/**\n * Extracts a substring from a string.\n *\n * @param str - The source string\n * @param begin - Starting index (0-based, inclusive)\n * @param end - Ending index (0-based, exclusive). If omitted, extracts to end of string\n * @returns The extracted substring\n *\n * @remarks\n * - An na `end` (NaN / null) is a runtime error in PineScript: it throws\n * - If begin > end, indices are swapped (JavaScript behavior)\n * - Negative indices are treated as 0\n * - Indices beyond string length return empty string\n *\n * @example\n * ```js\n * str.substring(\"hello world\", 0, 5) // Returns: \"hello\"\n * str.substring(\"hello world\", 6) // Returns: \"world\"\n * str.substring(\"test\", 1, 3) // Returns: \"es\"\n * ```\n */\nexport function substring(str: simple_string, begin: simple_int, end?: simple_int): string {\n if (end === null || Number.isNaN(end)) throw new Error('str.substring: the end position is na');\n return str.substring(begin, end);\n}\n\n/**\n * Converts all characters in a string to uppercase.\n *\n * @param str - The string to convert\n * @returns The uppercase string\n *\n * @example\n * ```js\n * str.upper(\"hello\") // Returns: \"HELLO\"\n * str.upper(\"Hello World\") // Returns: \"HELLO WORLD\"\n * str.upper(\"test123\") // Returns: \"TEST123\"\n * ```\n */\nexport function upper(str: simple_string): string {\n return str.toUpperCase();\n}\n\n/**\n * Converts all characters in a string to lowercase.\n *\n * @param str - The string to convert\n * @returns The lowercase string\n *\n * @example\n * ```js\n * str.lower(\"HELLO\") // Returns: \"hello\"\n * str.lower(\"Hello World\") // Returns: \"hello world\"\n * str.lower(\"TEST123\") // Returns: \"test123\"\n * ```\n */\nexport function lower(str: simple_string): string {\n return str.toLowerCase();\n}\n\n/**\n * Checks if a string contains a substring.\n *\n * @param source - The string to search in\n * @param str - The substring to search for\n * @returns True if source contains str, false otherwise\n *\n * @remarks\n * - Search is case-sensitive\n * - Empty string is contained in any string\n *\n * @example\n * ```js\n * str.contains(\"hello world\", \"world\") // Returns: true\n * str.contains(\"hello world\", \"World\") // Returns: false (case-sensitive)\n * str.contains(\"test\", \"xyz\") // Returns: false\n * ```\n */\nexport function contains(source: simple_string, str: simple_string): bool {\n return source.includes(str);\n}\n\n/**\n * Returns the position of the first occurrence of a substring.\n *\n * @param source - The string to search in\n * @param str - The substring to search for\n * @returns The 0-based index of the first occurrence, or na (NaN) if not found\n *\n * @remarks\n * - Search is case-sensitive\n * - Returns 0 for empty search string\n * - Returns na (NaN) if substring is not found, as in PineScript\n *\n * @example\n * ```js\n * str.pos(\"hello world\", \"world\") // Returns: 6\n * str.pos(\"hello world\", \"o\") // Returns: 4 (first occurrence)\n * str.pos(\"hello\", \"xyz\") // Returns: NaN (na)\n * ```\n */\nexport function pos(source: simple_string, str: simple_string): int {\n const index = source.indexOf(str);\n return index === -1 ? NaN : index;\n}\n\n/**\n * Replaces the Nth occurrence of a substring (PineScript `str.replace`).\n *\n * @param source - The source string\n * @param target - The substring to replace\n * @param replacement - The string to replace with\n * @param occurrence - 0-based occurrence to replace (default 0, the first one)\n * @returns The string with one occurrence replaced\n *\n * @remarks\n * PineScript rules:\n * - only the Nth occurrence is replaced; an na occurrence is 0 (`str.replace(\"aaa\", \"a\", \"-\", na)` is \"-aa\")\n * - occurrences overlap: \"aa\" occurs at 0 and 1 in \"aaa\" (`str.replace(\"aaa\", \"aa\", \"-\", 1)` is \"a-\")\n * - an empty target inserts the replacement at character N, at most at the end\n * (`str.replace(\"abc\", \"\", \"-\", 2)` is \"ab-c\")\n * - fewer than N + 1 occurrences (or a negative N) leave the source unchanged\n *\n * @example\n * ```js\n * str.replace(\"hello world hello\", \"hello\", \"hi\") // Returns: \"hi world hello\"\n * str.replace(\"hello world hello\", \"hello\", \"hi\", 1) // Returns: \"hello world hi\"\n * str.replace(\"test\", \"xyz\", \"abc\") // Returns: \"test\"\n * ```\n */\nexport function replace(source: simple_string, target: simple_string, replacement: simple_string, occurrence: simple_int = 0): string {\n const n = occurrence === null || Number.isNaN(occurrence) ? 0 : Math.trunc(occurrence);\n if (n < 0) return source;\n let index: number;\n if (target === '') {\n index = Math.min(n, source.length);\n } else {\n index = -1;\n for (let k = 0; k <= n; k++) {\n index = source.indexOf(target, index + 1);\n if (index === -1) return source;\n }\n }\n return source.slice(0, index) + replacement + source.slice(index + target.length);\n}\n\n/**\n * Replaces all occurrences of a target string with a replacement string.\n *\n * @param source - The source string\n * @param target - The substring to find\n * @param replacement - The replacement string\n * @returns String with all occurrences replaced\n *\n * @remarks\n * - Replaces all occurrences of the target string\n * - Case sensitive\n * - If target is empty string, returns original string\n * - This matches PineScript's `str.replace_all()` behavior\n *\n * @example\n * ```js\n * str.replace_all(\"hello world hello\", \"hello\", \"hi\") // Returns: \"hi world hi\"\n * str.replace_all(\"a-b-c\", \"-\", \"_\") // Returns: \"a_b_c\"\n * str.replace_all(\"test\", \"x\", \"y\") // Returns: \"test\" (no match)\n * ```\n */\nexport function replace_all(source: simple_string, target: simple_string, replacement: simple_string): string {\n return source.replaceAll(target, replacement);\n}\n\n/**\n * Splits a string into an array of substrings using a separator.\n *\n * @param str - The string to split\n * @param separator - The separator string\n * @returns Array of substrings\n *\n * @remarks\n * - Empty separator splits into individual characters; an empty string gives [\"\"] (also with \"\")\n * - If separator is not found, returns array with original string\n * - Consecutive separators create empty strings in result\n *\n * @example\n * ```js\n * str.split(\"a,b,c\", \",\") // Returns: [\"a\", \"b\", \"c\"]\n * str.split(\"hello\", \"\") // Returns: [\"h\", \"e\", \"l\", \"l\", \"o\"]\n * str.split(\"a,,b\", \",\") // Returns: [\"a\", \"\", \"b\"]\n * ```\n */\nexport function split(str: simple_string, separator: simple_string): string[] {\n // JavaScript gives [] for \"\".split(\"\"); PineScript gives [\"\"]\n return str === '' ? [''] : str.split(separator);\n}\n\n/**\n * Concatenates multiple strings into one.\n *\n * @param strings - Variable number of strings to concatenate\n * @returns The concatenated string\n *\n * @example\n * ```js\n * str.concat(\"hello\", \" \", \"world\") // Returns: \"hello world\"\n * str.concat(\"a\", \"b\", \"c\") // Returns: \"abc\"\n * str.concat(\"test\") // Returns: \"test\"\n * ```\n */\nexport function concat(...strings: simple_string[]): string {\n return strings.join('');\n}\n\n/**\n * Builds a text from a pattern and values: each `{0}`, `{1}`... is replaced by the argument at that position, e.g.\n * `str.format(\"Close {0}, change {1,number,percent}\", c.close, 0.025)`. Use it for labels and messages.\n *\n * @param pattern - The text with placeholders: `{0}` (a number shows as \"#,##0.###\"), `{1,number,#.##}` (number\n * pattern), `{0,number,percent}`, `{0,number,integer}`, `{0,date,yyyy-MM-dd}` (a time in milliseconds); '...' in\n * single quotes is kept as it is, '' is a quote\n * @param args - The values of the placeholders, in order: numbers, texts, booleans, arrays\n * @returns The text with the values in place\n *\n * @remarks\n * - numbers in `{n}` use \"#,##0.###\" (1234.5678 gives \"1,234.568\"); number patterns round half to even on the\n * exact value (16 decimals at most from 1e-3 up); an array gives \"[a, b]\"\n * - a missing argument leaves `{n}` in the text\n * - dates are written in the exchange time zone of the symbol in a script, in UTC when called outside a script\n *\n * @example\n * ```js\n * str.format(\"Close: {0,number,#.##}\", 101.456) // Returns: \"Close: 101.46\"\n * str.format(\"{0} and {1}\", \"a\", 2) // Returns: \"a and 2\"\n * ```\n */\nexport function format(pattern: simple_string, ...args: any[]): string {\n return formatMessage(pattern, args, 'Etc/UTC');\n}\n\n/**\n * Checks if a string starts with a specific prefix.\n *\n * @param source - The string to check\n * @param str - The prefix to look for\n * @returns True if source starts with str, false otherwise\n *\n * @remarks\n * - Search is case-sensitive\n * - Empty string prefix always returns true\n *\n * @example\n * ```js\n * str.startswith(\"hello world\", \"hello\") // Returns: true\n * str.startswith(\"hello world\", \"Hello\") // Returns: false (case-sensitive)\n * str.startswith(\"test\", \"testing\") // Returns: false\n * ```\n */\nexport function startswith(source: simple_string, str: simple_string): bool {\n return source.startsWith(str);\n}\n\n/**\n * Checks if a string ends with a specific suffix.\n *\n * @param source - The string to check\n * @param str - The suffix to look for\n * @returns True if source ends with str, false otherwise\n *\n * @remarks\n * - Search is case-sensitive\n * - Empty string suffix always returns true\n *\n * @example\n * ```js\n * str.endswith(\"hello world\", \"world\") // Returns: true\n * str.endswith(\"hello world\", \"World\") // Returns: false (case-sensitive)\n * str.endswith(\"testing\", \"test\") // Returns: false\n * ```\n */\nexport function endswith(source: simple_string, str: simple_string): bool {\n return source.endsWith(str);\n}\n\n/**\n * Returns the character at a specific position in a string.\n *\n * @param str - The source string\n * @param pos - The 0-based position\n * @returns The character at the position, or empty string if out of bounds\n *\n * @remarks\n * - Returns empty string for negative or out-of-bounds positions\n * - Unicode characters may span multiple code units\n *\n * @example\n * ```js\n * str.charAt(\"hello\", 0) // Returns: \"h\"\n * str.charAt(\"hello\", 4) // Returns: \"o\"\n * str.charAt(\"hello\", 10) // Returns: \"\"\n * ```\n */\nexport function charAt(str: simple_string, pos: simple_int): string {\n return str.charAt(pos);\n}\n\n/**\n * Removes whitespace from both ends of a string.\n *\n * @param str - The string to trim\n * @returns The trimmed string\n *\n * @remarks\n * - Removes spaces, tabs, newlines, and other whitespace characters\n * - Preserves internal whitespace\n *\n * @example\n * ```js\n * str.trim(\" hello \") // Returns: \"hello\"\n * str.trim(\" hello world \") // Returns: \"hello world\"\n * str.trim(\"\\thello\\n\") // Returns: \"hello\"\n * ```\n */\nexport function trim(str: simple_string): string {\n return str.trim();\n}\n\n/**\n * Removes whitespace from the left (start) of a string.\n *\n * @param str - The string to trim\n * @returns The trimmed string\n *\n * @remarks\n * - Only removes leading whitespace\n * - Preserves trailing and internal whitespace\n *\n * @example\n * ```js\n * str.trimLeft(\" hello \") // Returns: \"hello \"\n * str.trimLeft(\" hello\") // Returns: \"hello\"\n * str.trimLeft(\"\\thello\") // Returns: \"hello\"\n * ```\n */\nexport function trimLeft(str: simple_string): string {\n return str.trimStart();\n}\n\n/**\n * Removes whitespace from the right (end) of a string.\n *\n * @param str - The string to trim\n * @returns The trimmed string\n *\n * @remarks\n * - Only removes trailing whitespace\n * - Preserves leading and internal whitespace\n *\n * @example\n * ```js\n * str.trimRight(\" hello \") // Returns: \" hello\"\n * str.trimRight(\"hello \") // Returns: \"hello\"\n * str.trimRight(\"hello\\t\") // Returns: \"hello\"\n * ```\n */\nexport function trimRight(str: simple_string): string {\n return str.trimEnd();\n}\n\n/**\n * Returns the first substring of `source` that matches the `regex` (PineScript `str.match`).\n *\n * @param source - Source string\n * @param regex - Regular expression\n * @returns The first match (searched anywhere in the string), or na (null) when nothing matches or the match is empty\n *\n * @remarks\n * - As PineScript: \"Hello World!\" with \"o\" gives \"o\", with \"[a-z]+\" gives \"ello\"; no match gives na\n * - Uses JavaScript regex syntax\n *\n * @example\n * ```js\n * str.match(\"abc123def\", \"[0-9]+\") // Returns: \"123\"\n * str.match(\"abc\", \"[0-9]+\") // Returns: null (na)\n * ```\n */\nexport function match(source: simple_string, regex: simple_string): simple_string | null {\n const found = new RegExp(regex).exec(source);\n return found && found[0] !== '' ? found[0] : null;\n}\n\n/**\n * Constructs a new string containing the source string repeated N times with an optional separator.\n *\n * @param source - The string to repeat\n * @param count - Number of times to repeat\n * @param separator - String to inject between repeated instances. Optional, defaults to empty string.\n * @returns The repeated string, or null (na) if source is na or count is 0 / negative / na, as in PineScript\n *\n * @example\n * ```js\n * str.repeat(\"ab\", 3) // Returns: \"ababab\"\n * str.repeat(\"?\", 3, \",\") // Returns: \"?,?,?\"\n * str.repeat(\"hello\", 0) // Returns: null (na)\n * str.repeat(\"x\", 1) // Returns: \"x\"\n * ```\n */\nexport function repeat(source: simple_string, count: simple_int, separator: simple_string = ''): string | null {\n if (source == null) return null;\n if (!(count > 0)) return null; // 0, negative or na: na\n return Array(count).fill(source).join(separator);\n}\n\n/**\n * Writes a time as a date text, e.g. \"2024-03-15 09:30\". Use it for labels, tables and log messages.\n *\n * @param time - The time in milliseconds since 1 January 1970 UTC, e.g. `time` on a bar or `timenow`\n * @param format - Date pattern: `yyyy` year, `MM` month number, `MMM` month name, `dd` day, `EEE` weekday,\n * `HH` hour (00-23), `hh` hour (01-12) with `a` (AM/PM), `mm` minutes, `ss` seconds, `SSS` milliseconds,\n * `Z` / `z` time zone; 'text' in single quotes is kept as it is. Default: \"yyyy-MM-dd'T'HH:mm:ssZ\"\n * @param timezone - Time zone of the text: a UTC offset (\"UTC-5\", \"GMT+2\") or a zone name (\"America/New_York\").\n * Default in a script: the exchange time zone of the symbol; called outside a script: \"Etc/UTC\"\n * @returns The date text\n *\n * @remarks\n * Letters: y, M, d, E, u, D, w,\n * H, k, K, h, a, m, s, S, Z, z; 'text' is literal text.\n *\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) label.new(c.i, c.high, str.format_time(c.get(time), \"yyyy-MM-dd HH:mm\"));\n * });\n * ```\n */\nexport function format_time(time: simple_int, format: simple_string = \"yyyy-MM-dd'T'HH:mm:ssZ\", timezone: simple_string = 'Etc/UTC'): string {\n return formatDate(time, format, timezone);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,0BAAwC;AACxC,2BAA8B;AAC9B,wBAA2B;AAepB,SAAS,OAAO,KAAyB;AAC9C,SAAO,IAAI;AACb;AA8CO,SAAS,SAAS,OAAYA,SAAwB,SAAiB,YAA4B;AAExG,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,MAAM,IAAI,CAAC,MAAM,SAAS,GAAGA,SAAQ,SAAS,UAAU,CAAC,EAAE,KAAK,IAAI,IAAI;AAC/G,MAAI,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK;AAClD,MAAI,OAAO,MAAM,KAAK,EAAG,QAAOA,YAAW,YAAY,SAAS;AAChE,MAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAE3B,QAAIA,YAAW,UAAW,QAAO,OAAO,KAAK;AAC7C,WAAOA,YAAW,YAAY,SAASA,YAAW,WAAW,SAAS;AAAA,EACxE;AACA,MAAIA,YAAW,UAAaA,YAAW,IAAI;AACzC,QAAI,KAAK,IAAI,KAAK,KAAK,QAAQ,OAAO,SAAS,KAAK,GAAG;AACrD,aAAO,OAAO,KAAK,EAAE,QAAQ,MAAM,GAAG,EAAE,QAAQ,SAAS,GAAG;AAAA,IAC9D;AAEA,eAAO,kCAAa,OAAO,gBAAgB,mBAAmB;AAAA,EAChE;AACA,UAAQA,SAAQ;AAAA,IACd,KAAK;AACH,iBAAO,kCAAa,OAAO,QAAQ,gBAAgB,IAAI;AAAA,IAC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