oakscriptjs 0.9.5 → 0.9.6
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/dist/cjs/array/index.d.ts +84 -27
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +235 -78
- package/dist/cjs/array/index.js.map +3 -3
- package/dist/cjs/callsite/index.d.ts +81 -2
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +62 -1
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts +7 -3
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +6 -1
- package/dist/cjs/color/index.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.map +1 -1
- package/dist/cjs/label/index.js +2 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +1 -0
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +76 -21
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js +155 -41
- package/dist/cjs/math/index.js.map +3 -3
- package/dist/cjs/matrix/index.d.ts.map +1 -1
- package/dist/cjs/matrix/index.js +42 -36
- package/dist/cjs/matrix/index.js.map +2 -2
- package/dist/cjs/runtime/series.d.ts +9 -0
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +16 -2
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/index.d.ts +15 -31
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +32 -0
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +15 -2
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/str/index.d.ts +50 -38
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +43 -15
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/str/messageformat.d.ts +2 -1
- package/dist/cjs/str/messageformat.d.ts.map +1 -1
- package/dist/cjs/str/messageformat.js +4 -1
- package/dist/cjs/str/messageformat.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts +4 -0
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +26 -4
- package/dist/cjs/str/numberformat.js.map +3 -3
- package/dist/cjs/ta/index.d.ts +86 -43
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +173 -267
- package/dist/cjs/ta/index.js.map +3 -3
- package/dist/cjs/ta/running-sum.d.ts +54 -2
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +132 -52
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta-series.d.ts +4 -4
- package/dist/cjs/ta-series.d.ts.map +1 -1
- package/dist/cjs/ta-series.js +4 -3
- package/dist/cjs/ta-series.js.map +2 -2
- package/dist/cjs/time/datestring.d.ts +1 -0
- package/dist/cjs/time/datestring.d.ts.map +1 -1
- package/dist/cjs/time/datestring.js +7 -0
- package/dist/cjs/time/datestring.js.map +2 -2
- package/dist/cjs/time/index.d.ts.map +1 -1
- package/dist/cjs/time/index.js +2 -1
- package/dist/cjs/time/index.js.map +2 -2
- package/dist/cjs/time/session.d.ts +28 -9
- package/dist/cjs/time/session.d.ts.map +1 -1
- package/dist/cjs/time/session.js +74 -28
- package/dist/cjs/time/session.js.map +2 -2
- package/dist/cjs/time/timezone.d.ts +5 -0
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +15 -1
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/esm/array/index.d.ts +84 -27
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +373 -111
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts +81 -2
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +145 -3
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/color/index.d.ts +7 -3
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +15 -3
- package/dist/esm/color/index.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.map +1 -1
- package/dist/esm/label/index.js +2 -1
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +3 -0
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +76 -21
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +227 -61
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/matrix/index.d.ts.map +1 -1
- package/dist/esm/matrix/index.js +57 -43
- package/dist/esm/matrix/index.js.map +1 -1
- package/dist/esm/runtime/series.d.ts +9 -0
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +18 -1
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/index.d.ts +15 -31
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +44 -1
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +22 -2
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/str/index.d.ts +50 -38
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +103 -52
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/str/messageformat.d.ts +2 -1
- package/dist/esm/str/messageformat.d.ts.map +1 -1
- package/dist/esm/str/messageformat.js +7 -2
- package/dist/esm/str/messageformat.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts +4 -0
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +38 -4
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts +86 -43
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +296 -348
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/running-sum.d.ts +54 -2
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +166 -71
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta-series.d.ts +4 -4
- package/dist/esm/ta-series.d.ts.map +1 -1
- package/dist/esm/ta-series.js +5 -4
- package/dist/esm/ta-series.js.map +1 -1
- package/dist/esm/time/datestring.d.ts +1 -0
- package/dist/esm/time/datestring.d.ts.map +1 -1
- package/dist/esm/time/datestring.js +12 -0
- package/dist/esm/time/datestring.js.map +1 -1
- package/dist/esm/time/index.d.ts.map +1 -1
- package/dist/esm/time/index.js +3 -1
- package/dist/esm/time/index.js.map +1 -1
- package/dist/esm/time/session.d.ts +28 -9
- package/dist/esm/time/session.d.ts.map +1 -1
- package/dist/esm/time/session.js +113 -42
- package/dist/esm/time/session.js.map +1 -1
- package/dist/esm/time/timezone.d.ts +5 -0
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +21 -1
- package/dist/esm/time/timezone.js.map +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +352 -127
- package/src/callsite/index.ts +147 -3
- package/src/color/index.ts +15 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +2 -1
- package/src/linefill/index.ts +2 -0
- package/src/math/index.ts +256 -74
- package/src/matrix/index.ts +52 -52
- package/src/runtime/series.ts +22 -1
- package/src/script/index.ts +53 -1
- package/src/session/calendar.ts +22 -2
- package/src/str/index.ts +95 -51
- package/src/str/messageformat.ts +7 -2
- package/src/str/numberformat.ts +39 -4
- package/src/ta/index.ts +306 -386
- package/src/ta/running-sum.ts +187 -74
- package/src/ta-series.ts +8 -7
- package/src/time/datestring.ts +10 -0
- package/src/time/index.ts +3 -1
- package/src/time/session.ts +97 -47
- package/src/time/timezone.ts +21 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/time/session.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n *
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * PineScript session strings (\"0930-1600\", \"0930-1600:23456\", \"1000-1100,1400-1500:23456\", \"0930-1600|1000-1300:7\",\n * \"24x7\").\n *\n * Grammar (measured on PineScript): `range[,range...][:days]`, several sections joined by \"|\".\n * - a range is exactly \"HHMM-HHMM\"; hours and minutes are minute counts taken modulo one day (\"0930-2500\" runs\n * 09:30 to 01:00, \"0960-1600\" 10:00 to 16:00); a start of 24:00 or later must open a run of at most a day\n * - days are digits 1 (Sunday) to 7 (Saturday), the day each run ends on\n * - a lone range without days runs every day; otherwise a section without days is the default section, which runs\n * on the weekdays (2-6) no other section names, and a later section naming a day replaces the earlier ones on that\n * day (\"1100-1400|1200-1300:7\": 11:00-14:00 Monday to Friday, 12:00-13:00 Saturday)\n * - a trailing \",\", \":\" or \"|\" ends its list (\"1100-1400,\" is \"1100-1400\" Monday to Friday)\n * - an end before the start is an overnight run that belongs to the day it ends; equal ends are 24 hours;\n * \"0000-0000\" and \"24x7\" are the whole day, every day\n * - a string that is empty or does not start with a digit (\"regular\", \"extended\") is the symbol's own session\n * - a malformed string (\"1100 -1400\", \"0930-16\", \":8\") is an error, as the PineScript runtime error\n */\n\nimport { zonedFields } from './timezone.js';\n\nconst MINUTES_PER_DAY = 1440;\nconst WEEKDAYS = [2, 3, 4, 5, 6];\nconst ALL_DAYS = [1, 2, 3, 4, 5, 6, 7];\n\n/** A run of a session: minutes after midnight (0-1439) and the days it ends on (1 = Sunday ... 7 = Saturday). */\nexport interface SessionRange {\n start: number;\n end: number;\n days: Set<number>;\n}\n\nfunction invalid(session: string): SyntaxError {\n return new SyntaxError(`Invalid session \"${session}\": expected \"HHMM-HHMM[,HHMM-HHMM...][:days][|...]\"`);\n}\n\nfunction parseRanges(text: string, session: string): Array<[number, number]> {\n if (!text) return [];\n const entries = text.split(',');\n if (entries.length > 1 && entries[entries.length - 1] === '') entries.pop();\n return entries.map((entry) => {\n if (!/^\\d{4}-\\d{4}$/.test(entry)) throw invalid(session);\n let start = Number(entry.slice(0, 2)) * 60 + Number(entry.slice(2, 4));\n let end = Number(entry.slice(5, 7)) * 60 + Number(entry.slice(7, 9));\n if (start >= MINUTES_PER_DAY) {\n const endOfRun = end || MINUTES_PER_DAY;\n if (!(start - MINUTES_PER_DAY < endOfRun && endOfRun <= start && start < 2 * MINUTES_PER_DAY)) throw invalid(session);\n }\n start %= MINUTES_PER_DAY;\n end %= MINUTES_PER_DAY;\n return [start, end];\n });\n}\n\nfunction parseDays(text: string, session: string): Set<number> {\n if (!/^[1-7]+$/.test(text)) throw invalid(session);\n return new Set([...text].map(Number));\n}\n\nconst parsed = new Map<string, SessionRange[] | null>();\n\n/**\n * Runs of a PineScript session string, or null for the symbol's own session (empty or not starting with a digit).\n * @throws SyntaxError when the string is malformed (a PineScript runtime error)\n */\nexport function parsePineSession(session: string): SessionRange[] | null {\n const cached = parsed.get(session);\n if (cached !== undefined) return cached;\n const spec = session.trim();\n let out: SessionRange[] | null;\n if (!spec || !/^\\d/.test(spec)) {\n out = null;\n } else if (spec === '24x7') {\n out = [{ start: 0, end: 0, days: new Set(ALL_DAYS) }];\n } else if (!/[:,|]/.test(spec)) {\n out = parseRanges(spec, session).map(([start, end]) => ({ start, end, days: new Set(ALL_DAYS) }));\n } else {\n const sections = spec.split('|');\n if (sections.length > 1 && sections[sections.length - 1] === '') sections.pop();\n const items = sections.map((section) => {\n const parts = section.split(':');\n if (parts.length > 2) throw invalid(session);\n const ranges = parseRanges(parts[0]!, session);\n const days = parts.length === 1 || parts[1] === '' ? null : parseDays(parts[1]!, session);\n return { ranges, days };\n });\n if (items.filter((it) => it.days === null).length > 1) throw invalid(session);\n // a later section naming a day replaces the earlier ones on that day; the default section takes the weekdays\n // no other section names\n const own: Set<number>[] = items.map(() => new Set<number>());\n const claimed = new Set<number>();\n for (let i = items.length - 1; i >= 0; i--) {\n const days = items[i]!.days;\n if (days === null) continue;\n for (const d of days) if (!claimed.has(d)) own[i]!.add(d);\n for (const d of days) claimed.add(d);\n }\n items.forEach((it, i) => {\n if (it.days === null) for (const d of WEEKDAYS) if (!claimed.has(d)) own[i]!.add(d);\n });\n out = items.flatMap((it, i) => (own[i]!.size ? it.ranges.map(([start, end]) => ({ start, end, days: own[i]! })) : []));\n }\n parsed.set(session, out);\n return out;\n}\n\n/**\n * True when `time` falls inside `session`, with the session hours read in `timezone`.\n * A run includes its start minute and excludes its end minute.\n * @throws Error for the symbol's own session (\"regular\", \"extended\", \"\"), which this function does not know: use\n * `time(timeframe, session)` in a script with the chart session\n */\nexport function inSession(time: number, session: string, timezone: string): boolean {\n if (Number.isNaN(time)) return false;\n const ranges = parsePineSession(session);\n if (ranges === null) throw new Error(`Session \"${session}\" is the symbol session: it needs the chart session (time(timeframe, session) in a script)`);\n const f = zonedFields(time, timezone);\n const minute = f.hour * 60 + f.minute;\n const nextDay = (f.dayOfWeek % 7) + 1;\n for (const { start, end, days } of ranges) {\n if (start < end || (start === 0 && end === 0)) {\n if (minute >= start && (minute < end || end === 0) && days.has(f.dayOfWeek)) return true;\n } else {\n // Overnight (24 hours when start === end): the part from `start` belongs to the next day.\n if (minute >= start && days.has(nextDay)) return true;\n if (minute < end && days.has(f.dayOfWeek)) return true;\n }\n }\n return false;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,sBAA4B;AAE5B,MAAM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one: string): ZonedFields
|
|
|
36
36
|
* resolve to the later instant, and wall-clock times that do not exist (start of
|
|
37
37
|
* daylight saving time) are shifted forward by the length of the gap.
|
|
38
38
|
*/
|
|
39
|
+
/**
|
|
40
|
+
* UNIX time (ms) of a UTC wall-clock date: Gregorian calendar from 1582-10-15, Julian calendar before it (as
|
|
41
|
+
* PineScript: 1582-10-05 is 1582-10-15). Out-of-range fields roll over like `Date.UTC`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function civilToUnix(year: number, month: number, day: number, hour?: number, minute?: number, second?: number): number;
|
|
39
44
|
export declare function zonedToUnix(timezone: string, year: number, month: number, day: number, hour?: number, minute?: number, second?: number): number;
|
|
40
45
|
//# sourceMappingURL=timezone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../../src/time/timezone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0GH,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAWvE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAU,EAChB,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,GACjB,MAAM,CAYR"}
|
|
1
|
+
{"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../../src/time/timezone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0GH,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAWvE;AAED;;;;;;;GAOG;AACH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,SAAI,EAAE,MAAM,SAAI,EAAE,MAAM,SAAI,GAAG,MAAM,CAc9G;AAED,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAU,EAChB,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,GACjB,MAAM,CAYR"}
|
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var timezone_exports = {};
|
|
20
20
|
__export(timezone_exports, {
|
|
21
|
+
civilToUnix: () => civilToUnix,
|
|
21
22
|
zoneOffset: () => zoneOffset,
|
|
22
23
|
zonedFields: () => zonedFields,
|
|
23
24
|
zonedToUnix: () => zonedToUnix
|
|
@@ -112,9 +113,22 @@ function zonedFields(time, timezone) {
|
|
|
112
113
|
dayOfWeek: local.getUTCDay() + 1
|
|
113
114
|
};
|
|
114
115
|
}
|
|
116
|
+
function civilToUnix(year, month, day, hour = 0, minute = 0, second = 0) {
|
|
117
|
+
const gregorian = Date.UTC(year, month - 1, day, hour, minute, second);
|
|
118
|
+
const d = new Date(Date.UTC(year, month - 1, 1));
|
|
119
|
+
const y = d.getUTCFullYear();
|
|
120
|
+
const m = d.getUTCMonth() + 1;
|
|
121
|
+
if (y > 1582 || y === 1582 && (m > 10 || m === 10 && day >= 15)) return gregorian;
|
|
122
|
+
const a = Math.floor((14 - m) / 12);
|
|
123
|
+
const yy = y + 4800 - a;
|
|
124
|
+
const mm = m + 12 * a - 3;
|
|
125
|
+
const jdn = 1 + Math.floor((153 * mm + 2) / 5) + 365 * yy + Math.floor(yy / 4) - 32083;
|
|
126
|
+
const days = jdn - 2440588 + (day - 1);
|
|
127
|
+
return days * MS_PER_DAY + Date.UTC(1970, 0, 1, hour, minute, second);
|
|
128
|
+
}
|
|
115
129
|
function zonedToUnix(timezone, year, month, day, hour = 0, minute = 0, second = 0) {
|
|
116
130
|
const zone = resolveZone(timezone);
|
|
117
|
-
const local =
|
|
131
|
+
const local = civilToUnix(year, month, day, hour, minute, second);
|
|
118
132
|
if (zone.kind === "fixed") return local - zone.offsetMs;
|
|
119
133
|
const before = offsetAt(zone, local - MS_PER_DAY);
|
|
120
134
|
const after = offsetAt(zone, local + MS_PER_DAY);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/time/timezone.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Time zone resolution for the calendar functions.\n *\n * PineScript accepts two time zone notations:\n * - UTC/GMT offset notation: \"UTC\", \"UTC-5\", \"UTC+05:30\", \"GMT+0530\", \"GMT+05:30:00\", up to \u00B118:00\n * - IANA time zone database names, case-sensitive: \"America/New_York\", \"Etc/UTC\", \"US/Eastern\", \"CET\"\n *\n * \"utc+2\", \"america/new_york\", \"UTC+5:3\", \"UTC+5:30:15\", \"GMT+18:01\", \"EST\", \"MST\" and \"HST\" are\n * errors in PineScript, and so here.\n *\n * Offsets of IANA zones (daylight saving time and historical changes included)\n * come from the host's `Intl.DateTimeFormat`, so no time zone data ships with the library.\n */\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_DAY = 86_400_000;\nconst MAX_OFFSET_SECONDS = 18 * 3600;\n\nconst OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\\d{1,2})(?::?(\\d{2})(?::?(\\d{2}))?)?)?$/;\n\n/** Time zone database names that PineScript rejects although `Intl` accepts them. */\nconst REJECTED_NAMES = new Set(['EST', 'MST', 'HST']);\n\nlet canonicalNames: Map<string, string> | undefined;\n\n/** False when `name` is a wrong-case spelling of a time zone name (`Intl` matches names case-insensitively). */\nfunction hasTimeZoneCase(name: string): boolean {\n if (name.split('/').some((segment) => !/^[A-Z]/.test(segment))) return false;\n canonicalNames ??= new Map(Intl.supportedValuesOf('timeZone').map((n) => [n.toLowerCase(), n]));\n const canonical = canonicalNames.get(name.toLowerCase());\n return canonical === undefined || canonical === name;\n}\n\ntype Zone =\n | { readonly kind: 'fixed'; readonly offsetMs: number }\n | {\n readonly kind: 'iana';\n readonly format: Intl.DateTimeFormat;\n /** Offset of each UTC hour (`floor(time / 1 h)`); null for an hour with an offset change inside */\n readonly hours: Map<number, number | null>;\n };\n\nconst MS_PER_HOUR = 3_600_000;\n/** Cached hours per zone before the cache restarts (about 11 years of hours) */\nconst MAX_CACHED_HOURS = 100_000;\n\nconst zones = new Map<string, Zone>();\n\nfunction resolveZone(timezone: string): Zone {\n let zone = zones.get(timezone);\n if (zone) return zone;\n\n const invalid = () =>\n new RangeError(\n `Invalid time zone \"${timezone}\": use UTC/GMT offset notation (\"UTC-5\", \"GMT+0530\") or an IANA name (\"America/New_York\")`\n );\n const m = OFFSET_NOTATION.exec(timezone);\n if (m) {\n const [, sign, h = '0', mi = '0', s] = m;\n const minutes = Number(mi);\n const seconds = s === undefined ? 0 : Number(s);\n if (minutes > 59 || seconds > 59 || (s !== undefined && h.length !== 2)) throw invalid();\n const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;\n if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();\n zone = { kind: 'fixed', offsetMs: (sign === '-' ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };\n } else {\n if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();\n let format: Intl.DateTimeFormat;\n try {\n format = new Intl.DateTimeFormat('en-US', {\n timeZone: timezone,\n hourCycle: 'h23',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n });\n } catch {\n throw invalid();\n }\n zone = { kind: 'iana', format, hours: new Map() };\n }\n zones.set(timezone, zone);\n return zone;\n}\n\n/**\n * Offset of the zone from UTC at instant `time`, in milliseconds (local = UTC + offset).\n * An offset change happens at most once in a UTC hour, so when the first and the last second of the hour have the\n * same offset, the whole hour has it: it is computed once and cached.\n */\nfunction offsetAt(zone: Zone, time: number): number {\n if (zone.kind === 'fixed') return zone.offsetMs;\n const hour = Math.floor(time / MS_PER_HOUR);\n let offset = zone.hours.get(hour);\n if (offset === undefined) {\n const first = formattedOffset(zone.format, hour * MS_PER_HOUR);\n const last = formattedOffset(zone.format, hour * MS_PER_HOUR + MS_PER_HOUR - MS_PER_SECOND);\n offset = first === last ? first : null;\n if (zone.hours.size >= MAX_CACHED_HOURS) zone.hours.clear();\n zone.hours.set(hour, offset);\n }\n return offset ?? formattedOffset(zone.format, time);\n}\n\n/** Offset of the zone at instant `time` (whole second), from the host's `Intl` time zone data. */\nfunction formattedOffset(format: Intl.DateTimeFormat, time: number): number {\n const wholeSecond = Math.floor(time / 1000) * 1000;\n const f: Record<string, number> = {};\n for (const part of format.formatToParts(wholeSecond)) {\n if (part.type !== 'literal') f[part.type] = Number(part.value);\n }\n const local = Date.UTC(f.year!, f.month! - 1, f.day!, f.hour!, f.minute!, f.second!);\n return local - wholeSecond;\n}\n\n/** Calendar fields of a UNIX time in a time zone. */\nexport interface ZonedFields {\n year: number;\n /** 1-12 */\n month: number;\n /** 1-31 */\n day: number;\n hour: number;\n minute: number;\n second: number;\n /** 1 = Sunday ... 7 = Saturday (PineScript dayofweek numbering) */\n dayOfWeek: number;\n}\n\n/** Offset of `timezone` from UTC at `time`, in milliseconds (local = UTC + offset). */\nexport function zoneOffset(time: number, timezone: string): number {\n return offsetAt(resolveZone(timezone), time);\n}\n\n/** Splits a UNIX time (ms) into calendar fields in `timezone`. */\nexport function zonedFields(time: number, timezone: string): ZonedFields {\n const local = new Date(time + offsetAt(resolveZone(timezone), time));\n return {\n year: local.getUTCFullYear(),\n month: local.getUTCMonth() + 1,\n day: local.getUTCDate(),\n hour: local.getUTCHours(),\n minute: local.getUTCMinutes(),\n second: local.getUTCSeconds(),\n dayOfWeek: local.getUTCDay() + 1,\n };\n}\n\n/**\n * Converts a wall-clock date and time in `timezone` to a UNIX time (ms).\n * Out-of-range fields roll over like `Date.UTC` (month 13 is January of the next year).\n *\n * As in PineScript: wall-clock times that occur twice (end of daylight saving time)\n * resolve to the later instant, and wall-clock times that do not exist (start of\n * daylight saving time) are shifted forward by the length of the gap.\n */\nexport function zonedToUnix(\n timezone: string,\n year: number,\n month: number,\n day: number,\n hour: number = 0,\n minute: number = 0,\n second: number = 0\n): number {\n const zone = resolveZone(timezone);\n const local =
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AACnB,MAAM,qBA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ACjB;AAiBO,SAAS,WAAW,MAAc,UAA0B;AACjE,SAAO,SAAS,YAAY,QAAQ,GAAG,IAAI;AAC7C;AAGO,SAAS,YAAY,MAAc,UAA+B;AACvE,QAAM,QAAQ,IAAI,KAAK,OAAO,SAAS,YAAY,QAAQ,GAAG,IAAI,CAAC;AACnE,SAAO;AAAA,IACL,MAAM,MAAM,eAAe;AAAA,IAC3B,OAAO,MAAM,YAAY,IAAI;AAAA,IAC7B,KAAK,MAAM,WAAW;AAAA,IACtB,MAAM,MAAM,YAAY;AAAA,IACxB,QAAQ,MAAM,cAAc;AAAA,IAC5B,QAAQ,MAAM,cAAc;AAAA,IAC5B,WAAW,MAAM,UAAU,IAAI;AAAA,EACjC;AACF;
|
|
4
|
+
"sourcesContent": ["/**\n * Time zone resolution for the calendar functions.\n *\n * PineScript accepts two time zone notations:\n * - UTC/GMT offset notation: \"UTC\", \"UTC-5\", \"UTC+05:30\", \"GMT+0530\", \"GMT+05:30:00\", up to \u00B118:00\n * - IANA time zone database names, case-sensitive: \"America/New_York\", \"Etc/UTC\", \"US/Eastern\", \"CET\"\n *\n * \"utc+2\", \"america/new_york\", \"UTC+5:3\", \"UTC+5:30:15\", \"GMT+18:01\", \"EST\", \"MST\" and \"HST\" are\n * errors in PineScript, and so here.\n *\n * Offsets of IANA zones (daylight saving time and historical changes included)\n * come from the host's `Intl.DateTimeFormat`, so no time zone data ships with the library.\n */\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_DAY = 86_400_000;\nconst MAX_OFFSET_SECONDS = 18 * 3600;\n\nconst OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\\d{1,2})(?::?(\\d{2})(?::?(\\d{2}))?)?)?$/;\n\n/** Time zone database names that PineScript rejects although `Intl` accepts them. */\nconst REJECTED_NAMES = new Set(['EST', 'MST', 'HST']);\n\nlet canonicalNames: Map<string, string> | undefined;\n\n/** False when `name` is a wrong-case spelling of a time zone name (`Intl` matches names case-insensitively). */\nfunction hasTimeZoneCase(name: string): boolean {\n if (name.split('/').some((segment) => !/^[A-Z]/.test(segment))) return false;\n canonicalNames ??= new Map(Intl.supportedValuesOf('timeZone').map((n) => [n.toLowerCase(), n]));\n const canonical = canonicalNames.get(name.toLowerCase());\n return canonical === undefined || canonical === name;\n}\n\ntype Zone =\n | { readonly kind: 'fixed'; readonly offsetMs: number }\n | {\n readonly kind: 'iana';\n readonly format: Intl.DateTimeFormat;\n /** Offset of each UTC hour (`floor(time / 1 h)`); null for an hour with an offset change inside */\n readonly hours: Map<number, number | null>;\n };\n\nconst MS_PER_HOUR = 3_600_000;\n/** Cached hours per zone before the cache restarts (about 11 years of hours) */\nconst MAX_CACHED_HOURS = 100_000;\n\nconst zones = new Map<string, Zone>();\n\nfunction resolveZone(timezone: string): Zone {\n let zone = zones.get(timezone);\n if (zone) return zone;\n\n const invalid = () =>\n new RangeError(\n `Invalid time zone \"${timezone}\": use UTC/GMT offset notation (\"UTC-5\", \"GMT+0530\") or an IANA name (\"America/New_York\")`\n );\n const m = OFFSET_NOTATION.exec(timezone);\n if (m) {\n const [, sign, h = '0', mi = '0', s] = m;\n const minutes = Number(mi);\n const seconds = s === undefined ? 0 : Number(s);\n if (minutes > 59 || seconds > 59 || (s !== undefined && h.length !== 2)) throw invalid();\n const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;\n if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();\n zone = { kind: 'fixed', offsetMs: (sign === '-' ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };\n } else {\n if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();\n let format: Intl.DateTimeFormat;\n try {\n format = new Intl.DateTimeFormat('en-US', {\n timeZone: timezone,\n hourCycle: 'h23',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n });\n } catch {\n throw invalid();\n }\n zone = { kind: 'iana', format, hours: new Map() };\n }\n zones.set(timezone, zone);\n return zone;\n}\n\n/**\n * Offset of the zone from UTC at instant `time`, in milliseconds (local = UTC + offset).\n * An offset change happens at most once in a UTC hour, so when the first and the last second of the hour have the\n * same offset, the whole hour has it: it is computed once and cached.\n */\nfunction offsetAt(zone: Zone, time: number): number {\n if (zone.kind === 'fixed') return zone.offsetMs;\n const hour = Math.floor(time / MS_PER_HOUR);\n let offset = zone.hours.get(hour);\n if (offset === undefined) {\n const first = formattedOffset(zone.format, hour * MS_PER_HOUR);\n const last = formattedOffset(zone.format, hour * MS_PER_HOUR + MS_PER_HOUR - MS_PER_SECOND);\n offset = first === last ? first : null;\n if (zone.hours.size >= MAX_CACHED_HOURS) zone.hours.clear();\n zone.hours.set(hour, offset);\n }\n return offset ?? formattedOffset(zone.format, time);\n}\n\n/** Offset of the zone at instant `time` (whole second), from the host's `Intl` time zone data. */\nfunction formattedOffset(format: Intl.DateTimeFormat, time: number): number {\n const wholeSecond = Math.floor(time / 1000) * 1000;\n const f: Record<string, number> = {};\n for (const part of format.formatToParts(wholeSecond)) {\n if (part.type !== 'literal') f[part.type] = Number(part.value);\n }\n const local = Date.UTC(f.year!, f.month! - 1, f.day!, f.hour!, f.minute!, f.second!);\n return local - wholeSecond;\n}\n\n/** Calendar fields of a UNIX time in a time zone. */\nexport interface ZonedFields {\n year: number;\n /** 1-12 */\n month: number;\n /** 1-31 */\n day: number;\n hour: number;\n minute: number;\n second: number;\n /** 1 = Sunday ... 7 = Saturday (PineScript dayofweek numbering) */\n dayOfWeek: number;\n}\n\n/** Offset of `timezone` from UTC at `time`, in milliseconds (local = UTC + offset). */\nexport function zoneOffset(time: number, timezone: string): number {\n return offsetAt(resolveZone(timezone), time);\n}\n\n/** Splits a UNIX time (ms) into calendar fields in `timezone`. */\nexport function zonedFields(time: number, timezone: string): ZonedFields {\n const local = new Date(time + offsetAt(resolveZone(timezone), time));\n return {\n year: local.getUTCFullYear(),\n month: local.getUTCMonth() + 1,\n day: local.getUTCDate(),\n hour: local.getUTCHours(),\n minute: local.getUTCMinutes(),\n second: local.getUTCSeconds(),\n dayOfWeek: local.getUTCDay() + 1,\n };\n}\n\n/**\n * Converts a wall-clock date and time in `timezone` to a UNIX time (ms).\n * Out-of-range fields roll over like `Date.UTC` (month 13 is January of the next year).\n *\n * As in PineScript: wall-clock times that occur twice (end of daylight saving time)\n * resolve to the later instant, and wall-clock times that do not exist (start of\n * daylight saving time) are shifted forward by the length of the gap.\n */\n/**\n * UNIX time (ms) of a UTC wall-clock date: Gregorian calendar from 1582-10-15, Julian calendar before it (as\n * PineScript: 1582-10-05 is 1582-10-15). Out-of-range fields roll over like `Date.UTC`.\n */\nexport function civilToUnix(year: number, month: number, day: number, hour = 0, minute = 0, second = 0): number {\n const gregorian = Date.UTC(year, month - 1, day, hour, minute, second);\n // normalized year / month / day of the Gregorian reading decides the calendar\n const d = new Date(Date.UTC(year, month - 1, 1));\n const y = d.getUTCFullYear();\n const m = d.getUTCMonth() + 1;\n if (y > 1582 || (y === 1582 && (m > 10 || (m === 10 && day >= 15)))) return gregorian;\n // Julian day number of y-m-1, then the day offset and the time of day\n const a = Math.floor((14 - m) / 12);\n const yy = y + 4800 - a;\n const mm = m + 12 * a - 3;\n const jdn = 1 + Math.floor((153 * mm + 2) / 5) + 365 * yy + Math.floor(yy / 4) - 32083;\n const days = jdn - 2440588 + (day - 1);\n return days * MS_PER_DAY + Date.UTC(1970, 0, 1, hour, minute, second);\n}\n\nexport function zonedToUnix(\n timezone: string,\n year: number,\n month: number,\n day: number,\n hour: number = 0,\n minute: number = 0,\n second: number = 0\n): number {\n const zone = resolveZone(timezone);\n const local = civilToUnix(year, month, day, hour, minute, second);\n if (zone.kind === 'fixed') return local - zone.offsetMs;\n\n // At most one offset transition happens within a day of `local`: the offsets\n // one day before and one day after are the two candidates.\n const before = offsetAt(zone, local - MS_PER_DAY);\n const after = offsetAt(zone, local + MS_PER_DAY);\n const candidates = [local - before, local - after].filter((t) => local - offsetAt(zone, t) === t);\n if (candidates.length) return Math.max(...candidates);\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W,MAAM;AACpC,SAAO,OAAO,aAAa,KAAK,IAAI,MAAM,GAAG,GAAG,MAAM,QAAQ,MAAM;AACtE;AAEO,SAAS,YACd,UACA,MACA,OACA,KACA,OAAe,GACf,SAAiB,GACjB,SAAiB,GACT;AACR,QAAM,OAAO,YAAY,QAAQ;AACjC,QAAM,QAAQ,YAAY,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM;AAChE,MAAI,KAAK,SAAS,QAAS,QAAO,QAAQ,KAAK;AAI/C,QAAM,SAAS,SAAS,MAAM,QAAQ,UAAU;AAChD,QAAM,QAAQ,SAAS,MAAM,QAAQ,UAAU;AAC/C,QAAM,aAAa,CAAC,QAAQ,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,MAAM,QAAQ,SAAS,MAAM,CAAC,MAAM,CAAC;AAChG,MAAI,WAAW,OAAQ,QAAO,KAAK,IAAI,GAAG,UAAU;AACpD,SAAO,QAAQ;AACjB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,11 +12,17 @@ export declare function new_array<T>(size?: simple_int, initial_value?: T): Pine
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function size<T>(id: PineArray<T>): int;
|
|
14
14
|
/**
|
|
15
|
-
* Returns the element at the specified index
|
|
15
|
+
* Returns the element at the specified index.
|
|
16
|
+
*
|
|
17
|
+
* PineScript rules: a negative index counts from the end (`get(a, -1)` is the last element); an index outside
|
|
18
|
+
* `-size .. size - 1` is a runtime error (throws); an `na` index gives `na`.
|
|
16
19
|
*/
|
|
17
20
|
export declare function get<T>(id: PineArray<T>, index: simple_int): T;
|
|
18
21
|
/**
|
|
19
|
-
* Sets the value of the element at the specified index
|
|
22
|
+
* Sets the value of the element at the specified index.
|
|
23
|
+
*
|
|
24
|
+
* PineScript rules: a negative index counts from the end; an index outside `-size .. size - 1` is a runtime error
|
|
25
|
+
* (throws); an `na` index does nothing.
|
|
20
26
|
*/
|
|
21
27
|
export declare function set<T>(id: PineArray<T>, index: simple_int, value: T): void;
|
|
22
28
|
/**
|
|
@@ -40,23 +46,35 @@ export declare function shift<T>(id: PineArray<T>): T;
|
|
|
40
46
|
*/
|
|
41
47
|
export declare function clear<T>(id: PineArray<T>): void;
|
|
42
48
|
/**
|
|
43
|
-
* Inserts a value at the specified index
|
|
49
|
+
* Inserts a value at the specified index.
|
|
50
|
+
*
|
|
51
|
+
* PineScript rules: a negative index counts from the end and `size` appends, so `-size .. size` is valid; any other
|
|
52
|
+
* index is a runtime error (throws); an `na` index appends.
|
|
44
53
|
*/
|
|
45
54
|
export declare function insert<T>(id: PineArray<T>, index: simple_int, value: T): void;
|
|
46
55
|
/**
|
|
47
|
-
* Removes the element at the specified index
|
|
56
|
+
* Removes the element at the specified index and returns it.
|
|
57
|
+
*
|
|
58
|
+
* PineScript rules: a negative index counts from the end; an index outside `-size .. size - 1` is a runtime error
|
|
59
|
+
* (throws); an `na` index removes nothing and gives `na`.
|
|
48
60
|
*/
|
|
49
61
|
export declare function remove<T>(id: PineArray<T>, index: simple_int): T;
|
|
50
62
|
/**
|
|
51
|
-
* Returns true if the array contains the value
|
|
63
|
+
* Returns true if the array contains the value.
|
|
64
|
+
*
|
|
65
|
+
* PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.
|
|
52
66
|
*/
|
|
53
67
|
export declare function includes<T>(id: PineArray<T>, value: T): bool;
|
|
54
68
|
/**
|
|
55
|
-
* Returns the index of the first occurrence of the value
|
|
69
|
+
* Returns the index of the first occurrence of the value, -1 when not found.
|
|
70
|
+
*
|
|
71
|
+
* PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.
|
|
56
72
|
*/
|
|
57
73
|
export declare function indexof<T>(id: PineArray<T>, value: T): int;
|
|
58
74
|
/**
|
|
59
|
-
* Returns the index of the last occurrence of the value
|
|
75
|
+
* Returns the index of the last occurrence of the value, -1 when not found.
|
|
76
|
+
*
|
|
77
|
+
* PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.
|
|
60
78
|
*/
|
|
61
79
|
export declare function lastindexof<T>(id: PineArray<T>, value: T): int;
|
|
62
80
|
/**
|
|
@@ -64,7 +82,7 @@ export declare function lastindexof<T>(id: PineArray<T>, value: T): int;
|
|
|
64
82
|
*/
|
|
65
83
|
export declare function copy<T>(id: PineArray<T>): PineArray<T>;
|
|
66
84
|
/**
|
|
67
|
-
*
|
|
85
|
+
* Appends the elements of `id2` to `id1` and returns `id1` (PineScript `array.concat` changes `id1`).
|
|
68
86
|
*/
|
|
69
87
|
export declare function concat<T>(id1: PineArray<T>, id2: PineArray<T>): PineArray<T>;
|
|
70
88
|
/**
|
|
@@ -76,15 +94,29 @@ export declare function join(id: PineArray<any>, separator?: string): string;
|
|
|
76
94
|
*/
|
|
77
95
|
export declare function reverse<T>(id: PineArray<T>): void;
|
|
78
96
|
/**
|
|
79
|
-
* Returns
|
|
97
|
+
* Returns the elements from `index_from` (included) to `index_to` (excluded, default: the size) as a live view of
|
|
98
|
+
* the array (PineScript `array.slice`).
|
|
99
|
+
*
|
|
100
|
+
* PineScript rules:
|
|
101
|
+
* - the slice shares the elements of the original array: a change of an element of the slice changes the original
|
|
102
|
+
* array, and adding / removing elements of the slice adds / removes them in the original array, inside the slice
|
|
103
|
+
* bounds (a push to the slice inserts at the end of the slice)
|
|
104
|
+
* - `index_from` must address an element (`0 .. size - 1`) and `index_to` may be `size`; other bounds, or
|
|
105
|
+
* `index_from > index_to`, are a runtime error (throws); an `na` bound means the start / the end of the array
|
|
80
106
|
*/
|
|
81
107
|
export declare function slice<T>(id: PineArray<T>, index_from: simple_int, index_to?: simple_int): PineArray<T>;
|
|
108
|
+
/** Sort order of array.sort / array.sort_indices (PineScript `order.ascending` / `order.descending`). */
|
|
109
|
+
export type SortOrder = 'asc' | 'desc' | 'ascending' | 'descending';
|
|
82
110
|
/**
|
|
83
|
-
* Sorts array
|
|
111
|
+
* Sorts the array in place.
|
|
112
|
+
*
|
|
113
|
+
* PineScript rules: `na` goes after the numbers in ascending order and before them in descending order (the
|
|
114
|
+
* ascending result reversed); in a string array `na` goes first in ascending order.
|
|
84
115
|
*/
|
|
85
|
-
export declare function sort<T>(id: PineArray<T>, order?:
|
|
116
|
+
export declare function sort<T>(id: PineArray<T>, order?: SortOrder): void;
|
|
86
117
|
/**
|
|
87
|
-
*
|
|
118
|
+
* Sum of the non-na elements (PineScript `array.sum(id)`), added from left to right; an array without values gives NaN.
|
|
119
|
+
* As PineScript, the running sum is set to 0 after a step when its absolute value is <= 1e-10.
|
|
88
120
|
*/
|
|
89
121
|
export declare function sum(id: PineArray<float>): float;
|
|
90
122
|
/**
|
|
@@ -93,30 +125,40 @@ export declare function sum(id: PineArray<float>): float;
|
|
|
93
125
|
export declare function avg(id: PineArray<float>): float;
|
|
94
126
|
/**
|
|
95
127
|
* The `nth` smallest value (0 = the smallest) of the non-na elements (PineScript `array.min(id, nth)`).
|
|
96
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* PineScript rules: an `nth` past the non-na values but inside the array size gives the greatest value; an `nth`
|
|
130
|
+
* outside `0 .. size - 1` is a runtime error (throws); an `na` nth counts as 0; an array without values gives NaN.
|
|
97
131
|
*/
|
|
98
132
|
export declare function min(id: PineArray<float>, nth?: simple_int): float;
|
|
99
133
|
/**
|
|
100
134
|
* The `nth` greatest value (0 = the greatest) of the non-na elements (PineScript `array.max(id, nth)`).
|
|
101
|
-
*
|
|
135
|
+
*
|
|
136
|
+
* PineScript rules: an `nth` past the non-na values but inside the array size gives the smallest value; an `nth`
|
|
137
|
+
* outside `0 .. size - 1` is a runtime error (throws); an `na` nth counts as 0; an array without values gives NaN.
|
|
102
138
|
*/
|
|
103
139
|
export declare function max(id: PineArray<float>, nth?: simple_int): float;
|
|
104
140
|
/**
|
|
105
|
-
*
|
|
141
|
+
* Median of the non-na elements (PineScript `array.median(id)`): the middle value, or the mean of the two middle
|
|
142
|
+
* values for an even count; an array without values gives NaN.
|
|
106
143
|
*/
|
|
107
144
|
export declare function median(id: PineArray<float>): float;
|
|
108
145
|
/**
|
|
109
|
-
*
|
|
146
|
+
* Most frequent non-na element (PineScript `array.mode(id)`), compared exactly.
|
|
147
|
+
*
|
|
148
|
+
* PineScript rules: with several values of the same frequency, the smallest one; an array without values gives NaN.
|
|
110
149
|
*/
|
|
111
150
|
export declare function mode(id: PineArray<float>): float;
|
|
112
151
|
/**
|
|
113
|
-
* Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`)
|
|
114
|
-
* `
|
|
152
|
+
* Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`): the square root of
|
|
153
|
+
* `array.variance(id, biased)`.
|
|
115
154
|
*/
|
|
116
155
|
export declare function stdev(id: PineArray<float>, biased?: bool): float;
|
|
117
156
|
/**
|
|
118
157
|
* Variance of the non-na elements (PineScript `array.variance(id, biased)`).
|
|
119
|
-
*
|
|
158
|
+
*
|
|
159
|
+
* PineScript rule (moment form): with `p` the sum of the values, `q` the sum of their squares, `n` the count and
|
|
160
|
+
* `m = p / n`: biased (default) `max(0, q / n - m * m)`, unbiased `max(0, q / (n - 1) - (p / (n - 1)) * m)`.
|
|
161
|
+
* One value gives 0 biased and NaN unbiased; an array without values gives NaN.
|
|
120
162
|
*/
|
|
121
163
|
export declare function variance(id: PineArray<float>, biased?: bool): float;
|
|
122
164
|
/**
|
|
@@ -524,6 +566,9 @@ export declare function binary_search_rightmost(id: PineArray<float>, val: float
|
|
|
524
566
|
* - Unbiased (false): divides by n-1 (sample covariance)
|
|
525
567
|
* - Returns NaN if arrays are empty or have different lengths
|
|
526
568
|
* - Formula: Cov(X,Y) = E[(X - μX)(Y - μY)]
|
|
569
|
+
*
|
|
570
|
+
* PineScript rules: a pair where either value is `na` is skipped and the count is the number of pairs kept; both
|
|
571
|
+
* means first, then the sum of the products from the first to the last pair. One pair gives 0 biased, NaN unbiased.
|
|
527
572
|
*/
|
|
528
573
|
export declare function covariance(id1: PineArray<float>, id2: PineArray<float>, biased?: bool): float;
|
|
529
574
|
/**
|
|
@@ -549,9 +594,10 @@ export declare function covariance(id1: PineArray<float>, id2: PineArray<float>,
|
|
|
549
594
|
* - Returns NaN if array is empty
|
|
550
595
|
*
|
|
551
596
|
* PineScript rules:
|
|
552
|
-
* - position in the sorted array: `percentage / 100
|
|
553
|
-
*
|
|
597
|
+
* - 1-based position in the sorted array: `size * percentage / 100 + 0.5` (snapped to an integer within 1e-9),
|
|
598
|
+
* clamped to the first / last value; between two values `lo * (1 - frac) + hi * frac`
|
|
554
599
|
* - `na` values are sorted after all numbers; with an `na` in the array, a position between two values gives `na`
|
|
600
|
+
* - an `na` percentage gives `na`; a percentage outside 0 .. 100 is a runtime error (throws)
|
|
555
601
|
*/
|
|
556
602
|
export declare function percentile_linear_interpolation(id: PineArray<float>, percentage: float): float;
|
|
557
603
|
/**
|
|
@@ -577,8 +623,9 @@ export declare function percentile_linear_interpolation(id: PineArray<float>, pe
|
|
|
577
623
|
* - Returns NaN if array is empty
|
|
578
624
|
*
|
|
579
625
|
* PineScript rules:
|
|
580
|
-
* - the value at rank `ceil(percentage / 100
|
|
626
|
+
* - the value at rank `ceil(percentage * size / 100)` (clamped to 1 .. size) of the sorted array
|
|
581
627
|
* - `na` values are sorted after all numbers (na when that rank holds an `na`)
|
|
628
|
+
* - an `na` percentage counts as 0; a percentage outside 0 .. 100 is a runtime error (throws)
|
|
582
629
|
*/
|
|
583
630
|
export declare function percentile_nearest_rank(id: PineArray<float>, percentage: float): float;
|
|
584
631
|
/**
|
|
@@ -596,13 +643,17 @@ export declare function percentile_nearest_rank(id: PineArray<float>, percentage
|
|
|
596
643
|
* ```typescript
|
|
597
644
|
* const arr = [1, 2, 3, 4, 5];
|
|
598
645
|
* const rank = array.percentrank(arr, 2); // Value at index 2 is 3
|
|
599
|
-
* // Returns:
|
|
646
|
+
* // Returns: 50 ((3 - 1) * 100 / (5 - 1))
|
|
600
647
|
* ```
|
|
601
648
|
*
|
|
602
649
|
* @remarks
|
|
603
|
-
* - Returns percentage of elements <= the value at given index
|
|
604
650
|
* - Range: 0 to 100
|
|
605
|
-
*
|
|
651
|
+
*
|
|
652
|
+
* PineScript rules:
|
|
653
|
+
* - `(count - 1) * 100 / (size - 1)`, with `count` the number of non-na elements <= the element (exact
|
|
654
|
+
* comparison, no 1e-10 tolerance); `na` elements count in the size
|
|
655
|
+
* - an `na` element, a one-element array or an empty array gives NaN
|
|
656
|
+
* - an `na` index counts as 0; an index outside `0 .. size - 1` is a runtime error (throws)
|
|
606
657
|
*/
|
|
607
658
|
export declare function percentrank(id: PineArray<float>, index: int): float;
|
|
608
659
|
/**
|
|
@@ -630,8 +681,10 @@ export declare function percentrank(id: PineArray<float>, index: int): float;
|
|
|
630
681
|
* - Original array is not modified
|
|
631
682
|
* - Returns indices that would sort the array
|
|
632
683
|
* - Useful for maintaining correspondence with other arrays
|
|
684
|
+
* - PineScript rule: the indices of `na` elements go where `array.sort` puts them (after the numbers in ascending
|
|
685
|
+
* order, in their original order: `sort_indices([na, na, 5, 1])` is `[3, 2, 0, 1]`)
|
|
633
686
|
*/
|
|
634
|
-
export declare function sort_indices(id: PineArray<
|
|
687
|
+
export declare function sort_indices<T>(id: PineArray<T>, order?: SortOrder): PineArray<int>;
|
|
635
688
|
/**
|
|
636
689
|
* Standardize
|
|
637
690
|
*
|
|
@@ -652,8 +705,12 @@ export declare function sort_indices(id: PineArray<float>, order?: 'asc' | 'desc
|
|
|
652
705
|
* @remarks
|
|
653
706
|
* - Formula: z = (x - μ) / σ
|
|
654
707
|
* - Result has mean of 0 and standard deviation of 1
|
|
655
|
-
* - Returns array of NaN if standard deviation is 0
|
|
656
708
|
* - Useful for comparing values on different scales
|
|
709
|
+
*
|
|
710
|
+
* PineScript rules:
|
|
711
|
+
* - μ and σ are the population mean and standard deviation of the non-na elements, as `array.variance` (moment
|
|
712
|
+
* form); `na` elements stay `na`
|
|
713
|
+
* - when σ is 0 (all values equal) every non-na element gives 1
|
|
657
714
|
*/
|
|
658
715
|
export declare function standardize(id: PineArray<float>): PineArray<float>;
|
|
659
716
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEpH;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAE,UAAc,EAAE,aAAa,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAMlF;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,CAE7C;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEpH;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAE,UAAc,EAAE,aAAa,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAMlF;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,CAE7C;AAyBD;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,GAAG,CAAC,CAG7D;AAED;;;;;GAKG;AACH,wBAAgB,G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