Skip to content

Commit 44a8e37

Browse files
KianNHmaheshwarip
authored andcommitted
[Docs Site] Remove mathjs dependency (#17235)
1 parent 77c1940 commit 44a8e37

File tree

3 files changed

+50
-120
lines changed

3 files changed

+50
-120
lines changed

package-lock.json

Lines changed: 0 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"littlefoot": "^4.1.1",
4747
"lz-string": "^1.5.0",
4848
"marked": "^14.1.1",
49-
"mathjs": "^13.1.1",
5049
"mermaid": "^11.1.1",
5150
"node-html-parser": "^6.1.13",
5251
"patch-package": "^8.0.0",
@@ -57,10 +56,10 @@
5756
"react-textarea-autosize": "^8.5.3",
5857
"redirects-in-workers": "^0.0.5",
5958
"rehype-autolink-headings": "^7.1.0",
59+
"rehype-external-links": "^3.0.0",
6060
"rehype-mermaid": "^2.1.0",
6161
"rehype-slug": "^6.0.0",
6262
"rehype-title-figure": "^0.1.2",
63-
"rehype-external-links": "^3.0.0",
6463
"sharp": "^0.33.5",
6564
"solarflare-theme": "^0.0.2",
6665
"starlight-image-zoom": "^0.8.0",

src/components/TunnelCalculator.astro

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -122,73 +122,81 @@ const metrics = Object.entries({
122122
</sup>
123123

124124
<script>
125-
import { evaluate, round } from "mathjs";
125+
function getValueOfInputById(id: string) {
126+
const element = document.querySelector<HTMLInputElement>(id);
127+
128+
if (!element)
129+
throw new Error(`[TunnelCalculator] Unable to find element with ${id}.`);
130+
131+
return Number(element.value);
132+
}
126133

127134
function calculate() {
128-
const non_dns_udp_req_per_sec = document.querySelector<HTMLInputElement>(
135+
const non_dns_udp_req_per_sec = getValueOfInputById(
129136
"#non_dns_udp_req_per_sec",
130-
)?.value;
131-
const avg_non_dns_udp_session_timeout =
132-
document.querySelector<HTMLInputElement>(
133-
"#avg_non_dns_udp_session_timeout",
134-
)?.value;
135-
const private_dns_req_per_sec = document.querySelector<HTMLInputElement>(
137+
);
138+
const avg_non_dns_udp_session_timeout = getValueOfInputById(
139+
"#avg_non_dns_udp_session_timeout",
140+
);
141+
const private_dns_req_per_sec = getValueOfInputById(
136142
"#private_dns_req_per_sec",
137-
)?.value;
138-
const dns_udp_timeout_in_sec = document.querySelector<HTMLInputElement>(
139-
"#dns_udp_timeout_in_sec",
140-
)?.value;
141-
const tcp_per_sec =
142-
document.querySelector<HTMLInputElement>("#tcp_per_sec")?.value;
143-
const available_ports_per_host = document.querySelector<HTMLInputElement>(
144-
"#available_ports_per_host",
145-
)?.value;
146-
const cloudflared_replicas = document.querySelector<HTMLInputElement>(
147-
"#cloudflared_replicas",
148-
)?.value;
149-
150-
// const percent_capacity_per_replica = (((non_dns_udp_req_per_sec * avg_non_dns_udp_session_timeout) + (private_dns_req_per_sec * dns_udp_timeout_in_sec) + tcp_per_sec) / available_ports_per_host) * 100;
151-
const percent_capacity_per_replica = evaluate(
152-
`(((${non_dns_udp_req_per_sec} * ${avg_non_dns_udp_session_timeout}) + (${private_dns_req_per_sec} * ${dns_udp_timeout_in_sec}) + ${tcp_per_sec}) / ${available_ports_per_host}) * 100`,
153143
);
154-
const percent_capacity_across_all_replicas = evaluate(
155-
`((${non_dns_udp_req_per_sec} * ${avg_non_dns_udp_session_timeout} +
156-
${private_dns_req_per_sec} * ${dns_udp_timeout_in_sec} +
157-
${tcp_per_sec}) /
158-
(${available_ports_per_host} * ${cloudflared_replicas})) *
159-
100`,
144+
const tcp_per_sec = getValueOfInputById("#tcp_per_sec");
145+
const dns_udp_timeout_in_sec = getValueOfInputById(
146+
"#dns_udp_timeout_in_sec",
160147
);
161-
const max_dns_request_per_min = evaluate(
162-
`((${available_ports_per_host} * ${cloudflared_replicas}) /
163-
${dns_udp_timeout_in_sec}) *
164-
60`,
148+
const available_ports_per_host = getValueOfInputById(
149+
"#available_ports_per_host",
165150
);
151+
const cloudflared_replicas = getValueOfInputById("#cloudflared_replicas");
152+
153+
const percent_capacity_per_replica =
154+
((non_dns_udp_req_per_sec * avg_non_dns_udp_session_timeout +
155+
private_dns_req_per_sec * dns_udp_timeout_in_sec +
156+
tcp_per_sec) /
157+
available_ports_per_host) *
158+
100;
159+
160+
const percent_capacity_across_all_replicas =
161+
((non_dns_udp_req_per_sec * avg_non_dns_udp_session_timeout +
162+
private_dns_req_per_sec * dns_udp_timeout_in_sec +
163+
tcp_per_sec) /
164+
(available_ports_per_host * cloudflared_replicas)) *
165+
100;
166+
167+
const max_dns_request_per_min =
168+
((available_ports_per_host * cloudflared_replicas) /
169+
dns_udp_timeout_in_sec) *
170+
60;
166171

167172
const perceptCapacityPerReplicaInput =
168173
document.querySelector<HTMLInputElement>("#percent_capacity_per_replica");
174+
169175
if (perceptCapacityPerReplicaInput) {
170-
perceptCapacityPerReplicaInput.value = round(
171-
percent_capacity_per_replica,
172-
2,
176+
perceptCapacityPerReplicaInput.value = String(
177+
percent_capacity_per_replica.toFixed(2),
173178
);
174179
}
175180

176181
const percentCapacityAcrossAllReplicasInput =
177182
document.querySelector<HTMLInputElement>(
178183
"#percent_capacity_across_all_replicas",
179184
);
185+
180186
if (percentCapacityAcrossAllReplicasInput) {
181-
percentCapacityAcrossAllReplicasInput.value = round(
182-
percent_capacity_across_all_replicas,
183-
2,
187+
percentCapacityAcrossAllReplicasInput.value = String(
188+
percent_capacity_across_all_replicas.toFixed(2),
184189
);
185190
}
186191

187192
const maxDnsRequestPerMinInput = document.querySelector<HTMLInputElement>(
188193
"#max_dns_request_per_min",
189194
);
195+
190196
if (maxDnsRequestPerMinInput) {
191-
maxDnsRequestPerMinInput.value = round(max_dns_request_per_min, 2);
197+
maxDnsRequestPerMinInput.value = String(
198+
max_dns_request_per_min.toFixed(2),
199+
);
192200
}
193201
}
194202

0 commit comments

Comments
 (0)