mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-23 14:21:04 +03:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2664b78bbb | ||
|
|
6fadc83c4b | ||
|
|
0e73e5885c |
No files matched your search
Vendored
+5
-5
@@ -141,10 +141,11 @@ declare module '@vue/runtime-core' {
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NRadio: typeof import('naive-ui')['NRadio']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NStatistic: typeof import('naive-ui')['NStatistic']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||
@@ -162,11 +163,10 @@ declare module '@vue/runtime-core' {
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
|
||||
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
|
||||
SlaCalculator: typeof import('./src/tools/sla-calculator/sla-calculator.vue')['default']
|
||||
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
|
||||
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
|
||||
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
|
||||
StacktracePrettier: typeof import('./src/tools/stacktrace-prettier/stacktrace-prettier.vue')['default']
|
||||
StringObfuscator: typeof import('./src/tools/string-obfuscator/string-obfuscator.vue')['default']
|
||||
SvgPlaceholderGenerator: typeof import('./src/tools/svg-placeholder-generator/svg-placeholder-generator.vue')['default']
|
||||
TemperatureConverter: typeof import('./src/tools/temperature-converter/temperature-converter.vue')['default']
|
||||
|
||||
+4
-5
@@ -42,6 +42,7 @@
|
||||
"@tiptap/pm": "2.1.6",
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/big.js": "^6.2.2",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -50,6 +51,7 @@
|
||||
"@vueuse/head": "^1.0.0",
|
||||
"@vueuse/router": "^10.0.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"big.js": "^6.2.2",
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
@@ -58,7 +60,6 @@
|
||||
"cronstrue": "^2.26.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"date-fns": "^2.29.3",
|
||||
"dom-to-image-more": "^3.4.5",
|
||||
"dompurify": "^3.0.6",
|
||||
"email-normalizer": "^1.0.0",
|
||||
"emojilib": "^3.0.10",
|
||||
@@ -68,10 +69,8 @@
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
"javastack.js": "^1.0.2",
|
||||
"js-base64": "^3.7.6",
|
||||
"json5": "^2.2.3",
|
||||
"jsstack.js": "^2.0.0",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
"lodash": "^4.17.21",
|
||||
@@ -82,13 +81,13 @@
|
||||
"monaco-editor": "^0.43.0",
|
||||
"naive-ui": "^2.35.0",
|
||||
"netmask": "^2.0.2",
|
||||
"netstack.js": "^2.0.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"oui-data": "^1.0.10",
|
||||
"parse-duration": "^1.1.0",
|
||||
"pdf-signature-reader": "^1.4.2",
|
||||
"pinia": "^2.0.34",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"pythonstack.js": "^1.0.2",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"qrcode": "^1.5.1",
|
||||
"randexp": "^0.5.3",
|
||||
"sql-formatter": "^13.0.0",
|
||||
|
||||
Generated
+55
-658
File diff suppressed because it is too large.
Load diff
+7
-3
@@ -1,8 +1,8 @@
|
||||
import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as slaCalculator } from './sla-calculator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as stacktracePrettier } from './stacktrace-prettier';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -161,7 +161,6 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
emailNormalizer,
|
||||
regexTester,
|
||||
regexMemo,
|
||||
stacktracePrettier,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -174,7 +173,12 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Measurement',
|
||||
components: [chronometer, temperatureConverter, benchmarkBuilder],
|
||||
components: [
|
||||
chronometer,
|
||||
temperatureConverter,
|
||||
benchmarkBuilder,
|
||||
slaCalculator,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Text',
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Clock } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'SLA calculator',
|
||||
path: '/sla-calculator',
|
||||
description: 'Service Level Agreement Calcultator',
|
||||
keywords: ['sla', 'service', 'level', 'agreement', 'calculator'],
|
||||
component: () => import('./sla-calculator.vue'),
|
||||
icon: Clock,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { downTimeToSLA, slaToDowntimes } from './sla-calculator.service';
|
||||
|
||||
describe('sla-calculator', () => {
|
||||
describe('downTimeToSLA', () => {
|
||||
it('compute correct values', () => {
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 100,
|
||||
mondayHours: 16,
|
||||
tuesdayHours: 6,
|
||||
wednesdayHours: 4,
|
||||
thursdayHours: 24,
|
||||
fridayHours: 21,
|
||||
saturdayHours: 16,
|
||||
sundayHours: 13,
|
||||
})).to.deep.eq({
|
||||
slaForDay: null,
|
||||
slaForMonth: 99.99361155031703,
|
||||
slaForQuarter: 99.99787051677234,
|
||||
slaForWeek: 99.97222222222223,
|
||||
slaForYear: 99.99946762919309,
|
||||
});
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 86400 / 10000,
|
||||
})).to.deep.eq({
|
||||
slaForDay: 99.99,
|
||||
slaForMonth: 99.99967145115916,
|
||||
slaForQuarter: 99.99989048371972,
|
||||
slaForWeek: 99.99857142857142,
|
||||
slaForYear: 99.99997262092992,
|
||||
});
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 86400 / 2,
|
||||
})).to.deep.eq({
|
||||
slaForDay: 50,
|
||||
slaForMonth: 98.35725579580689,
|
||||
slaForQuarter: 99.45241859860229,
|
||||
slaForWeek: 92.85714285714286,
|
||||
slaForYear: 99.86310464965058,
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('slaToDowntimes', () => {
|
||||
it('compute correct values', () => {
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99,
|
||||
mondayHours: 9,
|
||||
tuesdayHours: 24,
|
||||
wednesdayHours: 10,
|
||||
thursdayHours: 8,
|
||||
fridayHours: 3,
|
||||
saturdayHours: 24,
|
||||
sundayHours: 4,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: null,
|
||||
secondsPerMonth: 12835.665,
|
||||
secondsPerQuarter: 38506.995,
|
||||
secondsPerWeek: 2952,
|
||||
secondsPerYear: 154027.98,
|
||||
});
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99.99,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: 8.64,
|
||||
secondsPerMonth: 262.9746,
|
||||
secondsPerQuarter: 788.9238,
|
||||
secondsPerWeek: 60.48,
|
||||
secondsPerYear: 3155.6952,
|
||||
});
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: 864,
|
||||
secondsPerMonth: 26297.46,
|
||||
secondsPerQuarter: 78892.38,
|
||||
secondsPerWeek: 6048,
|
||||
secondsPerYear: 315569.52,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import Big from 'big.js';
|
||||
|
||||
const hoursDay = Big('24');
|
||||
const daysWeek = Big('7');
|
||||
const monthsYear = Big('12');
|
||||
const daysYear = Big('365.2425');
|
||||
const weeksYear = daysYear.div(daysWeek);
|
||||
const daysMonth = daysYear.div(monthsYear);
|
||||
const weeksMonth = daysMonth.div(daysWeek);
|
||||
|
||||
interface DaysHours {
|
||||
mondayHours?: number
|
||||
tuesdayHours?: number
|
||||
wednesdayHours?: number
|
||||
thursdayHours?: number
|
||||
fridayHours?: number
|
||||
saturdayHours?: number
|
||||
sundayHours?: number
|
||||
}
|
||||
|
||||
function prepareDurations({
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: DaysHours) {
|
||||
const durHoursWeek = Big(mondayHours).plus(tuesdayHours).plus(wednesdayHours).plus(thursdayHours).plus(fridayHours).plus(saturdayHours).plus(sundayHours);
|
||||
const durSecondsWeek = durHoursWeek.mul('3600');
|
||||
const durSecondsDay = durSecondsWeek.div(daysWeek);
|
||||
const durSecondsMonth = durSecondsWeek.mul(weeksMonth);
|
||||
const durSecondsQuarter = durSecondsMonth.mul('3');
|
||||
const durSecondsYear = durSecondsWeek.mul(weeksYear);
|
||||
const fullWeekHours = daysWeek.mul(hoursDay);
|
||||
|
||||
return {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
};
|
||||
}
|
||||
|
||||
export function downTimeToSLA({
|
||||
downTimeSeconds,
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: {
|
||||
downTimeSeconds: number
|
||||
} & DaysHours) {
|
||||
const {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
} = prepareDurations({
|
||||
mondayHours, tuesdayHours, wednesdayHours, thursdayHours, fridayHours, saturdayHours, sundayHours,
|
||||
});
|
||||
|
||||
const one = Big('1');
|
||||
const hundred = Big('100');
|
||||
const downTimeSecondsBig = Big(downTimeSeconds);
|
||||
|
||||
return {
|
||||
slaForDay: fullWeekHours.eq(durHoursWeek) ? one.minus(downTimeSecondsBig.div(durSecondsDay)).mul(hundred).toNumber() : null,
|
||||
slaForWeek: one.minus(downTimeSecondsBig.div(durSecondsWeek)).mul(hundred).toNumber(),
|
||||
slaForMonth: one.minus(downTimeSecondsBig.div(durSecondsMonth)).mul(hundred).toNumber(),
|
||||
slaForQuarter: one.minus(downTimeSecondsBig.div(durSecondsQuarter)).mul(hundred).toNumber(),
|
||||
slaForYear: one.minus(downTimeSecondsBig.div(durSecondsYear)).mul(hundred).toNumber(),
|
||||
};
|
||||
}
|
||||
|
||||
export function slaToDowntimes({
|
||||
targetSLA,
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: {
|
||||
targetSLA: number
|
||||
mondayHours?: number
|
||||
tuesdayHours?: number
|
||||
wednesdayHours?: number
|
||||
thursdayHours?: number
|
||||
fridayHours?: number
|
||||
saturdayHours?: number
|
||||
sundayHours?: number
|
||||
}) {
|
||||
const {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
} = prepareDurations({
|
||||
mondayHours, tuesdayHours, wednesdayHours, thursdayHours, fridayHours, saturdayHours, sundayHours,
|
||||
});
|
||||
|
||||
const allowedDowntime = Big('1').minus(Big(targetSLA).div('100'));
|
||||
|
||||
return {
|
||||
secondsPerDay: fullWeekHours.eq(durHoursWeek) ? allowedDowntime.mul(durSecondsDay).toNumber() : null,
|
||||
secondsPerWeek: allowedDowntime.mul(durSecondsWeek).toNumber(),
|
||||
secondsPerMonth: allowedDowntime.mul(durSecondsMonth).toNumber(),
|
||||
secondsPerQuarter: allowedDowntime.mul(durSecondsQuarter).toNumber(),
|
||||
secondsPerYear: allowedDowntime.mul(durSecondsYear).toNumber(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<script setup lang="ts">
|
||||
import prettyMilliseconds from 'pretty-ms';
|
||||
import parse from 'parse-duration';
|
||||
import { downTimeToSLA, slaToDowntimes } from './sla-calculator.service';
|
||||
import { useQueryParam, useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
function prettySeconds(seconds: number | null) {
|
||||
if (!seconds) {
|
||||
return '';
|
||||
}
|
||||
return prettyMilliseconds(seconds * 1000);
|
||||
}
|
||||
|
||||
const daysHours = useQueryParamOrStorage<{
|
||||
mon?: number
|
||||
tue?: number
|
||||
wed?: number
|
||||
thu?: number
|
||||
fri?: number
|
||||
sat?: number
|
||||
sun?: number
|
||||
}>({
|
||||
name: 'days',
|
||||
storageName: 'sla:days',
|
||||
defaultValue: {
|
||||
mon: 24,
|
||||
tue: 24,
|
||||
wed: 24,
|
||||
thu: 24,
|
||||
fri: 24,
|
||||
sat: 24,
|
||||
sun: 24,
|
||||
},
|
||||
});
|
||||
const inputSLA = useQueryParam({ name: 'sla', defaultValue: 99.99 });
|
||||
const outputDownTimes = computed(() => {
|
||||
const weekdaysHours = daysHours.value;
|
||||
const downtimesSeconds = slaToDowntimes({
|
||||
targetSLA: inputSLA.value,
|
||||
mondayHours: weekdaysHours.mon,
|
||||
tuesdayHours: weekdaysHours.tue,
|
||||
wednesdayHours: weekdaysHours.wed,
|
||||
thursdayHours: weekdaysHours.thu,
|
||||
fridayHours: weekdaysHours.fri,
|
||||
saturdayHours: weekdaysHours.sat,
|
||||
sundayHours: weekdaysHours.sun,
|
||||
});
|
||||
return {
|
||||
durationPerDay: prettySeconds(downtimesSeconds.secondsPerDay),
|
||||
durationPerMonth: prettySeconds(downtimesSeconds.secondsPerMonth),
|
||||
durationPerQuarter: prettySeconds(downtimesSeconds.secondsPerQuarter),
|
||||
durationPerWeek: prettySeconds(downtimesSeconds.secondsPerWeek),
|
||||
durationPerYear: prettySeconds(downtimesSeconds.secondsPerYear),
|
||||
};
|
||||
});
|
||||
|
||||
const inputDuration = useQueryParam({ name: 'dur', defaultValue: '1s' });
|
||||
const inputDurationValidation = useValidation({
|
||||
source: inputDuration,
|
||||
rules: [
|
||||
{
|
||||
message: 'Invalid duration',
|
||||
validator: value => parse(value),
|
||||
},
|
||||
],
|
||||
});
|
||||
const inputDurationSeconds = computed(() => {
|
||||
if (!inputDurationValidation.isValid) {
|
||||
return 0;
|
||||
}
|
||||
return parse(inputDuration.value, 's') || 0;
|
||||
});
|
||||
const outputSLAs = computed(() => {
|
||||
const weekdaysHours = daysHours.value;
|
||||
const slas = downTimeToSLA({
|
||||
downTimeSeconds: inputDurationSeconds.value,
|
||||
mondayHours: weekdaysHours.mon,
|
||||
tuesdayHours: weekdaysHours.tue,
|
||||
wednesdayHours: weekdaysHours.wed,
|
||||
thursdayHours: weekdaysHours.thu,
|
||||
fridayHours: weekdaysHours.fri,
|
||||
saturdayHours: weekdaysHours.sat,
|
||||
sundayHours: weekdaysHours.sun,
|
||||
});
|
||||
return {
|
||||
slaForDay: slas.slaForDay?.toPrecision(6),
|
||||
slaForWeek: slas.slaForWeek.toPrecision(6),
|
||||
slaForMonth: slas.slaForMonth.toPrecision(6),
|
||||
slaForQuarter: slas.slaForQuarter.toPrecision(6),
|
||||
slaForYear: slas.slaForYear.toPrecision(6),
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="SLA to downtimes" mb-2>
|
||||
<n-form-item label="Agreed SLA" label-placement="left">
|
||||
<n-input-number v-model:value="inputSLA" :min="0" :max="100" />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item v-if="outputDownTimes.durationPerDay" label="Daily downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerDay" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Weekly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerWeek" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Monthly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerMonth" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Quarterly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerQuarter" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Yearly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerYear" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Downtime to SLA" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="inputDuration"
|
||||
label="Downtime duration"
|
||||
label-position="left"
|
||||
placeholder="Put downtime duration here..."
|
||||
:validation="inputDurationValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item v-if="outputSLAs.slaForDay" label="Daily SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForDay" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Weekly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForWeek" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Monthly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForMonth" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Quarterly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForQuarter" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Yearly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForYear" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Weekdays hours">
|
||||
<div flex flex-wrap gap-1>
|
||||
<n-form-item label="Monday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.mon" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Tuesday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.tue" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Wednesday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.wed" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Thursday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.thu" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Friday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.fri" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div flex flex-wrap gap-1>
|
||||
<n-form-item label="Saturday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.sat" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Sunday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.sun" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,3 +0,0 @@
|
||||
declare module "dom-to-image-more" {
|
||||
export function toPng(el: HTMLElement | undefined, options?: { bgcolor: string }) : Promise<string>;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Stack } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Stacktrace prettier',
|
||||
path: '/stacktrace-prettier',
|
||||
description: 'Highlight .Net and JS stacktraces',
|
||||
keywords: ['stacktrace', 'prettier', 'highlighter'],
|
||||
component: () => import('./stacktrace-prettier.vue'),
|
||||
icon: Stack,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
declare module "javastack.js" {
|
||||
export default function javastack(selector: string, options: { prettyprint: boolean }) : void;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
declare module "jsstack.js" {
|
||||
export default function jsstack(selector: string) : void;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
declare module "netstack.js" {
|
||||
export default class netstack {
|
||||
constructor(el: HTMLElement | undefined, options: { prettyprint: boolean })
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
declare module "pythonstack.js" {
|
||||
export default function pythonstack(selector: string, options: { prettyprint: boolean }) : void;
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import JSStack from 'jsstack.js';
|
||||
import JavaStack from 'javastack.js';
|
||||
import PythonStack from 'pythonstack.js';
|
||||
import NetStack from 'netstack.js';
|
||||
import domtoimage from 'dom-to-image-more';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
const stackType = useQueryParamOrStorage<'net' | 'js' | 'java' | 'python'>({ name: 'type', storageName: 'stackfmt:type', defaultValue: 'net' });
|
||||
const stackTrace = ref('');
|
||||
const formatedStackTrace = ref<HTMLElement>();
|
||||
|
||||
const stackTraceText = ref('');
|
||||
watchEffect(() => {
|
||||
if (!formatedStackTrace.value) {
|
||||
return;
|
||||
}
|
||||
let cleanedStackTrace;
|
||||
try {
|
||||
cleanedStackTrace = JSON.parse(stackTrace.value);
|
||||
}
|
||||
catch (_) {
|
||||
cleanedStackTrace = stackTrace.value.replace(/(\\r)?\\n/g, '\n').replace(/(?:^['"])|(?:['"]$)/, '');
|
||||
};
|
||||
try {
|
||||
if (stackType.value === 'js') {
|
||||
formatedStackTrace.value.textContent = cleanedStackTrace;
|
||||
JSStack('.stacktrace');
|
||||
}
|
||||
else if (stackType.value === 'java') {
|
||||
formatedStackTrace.value.textContent = cleanedStackTrace;
|
||||
JavaStack('.stacktrace', { prettyprint: true });
|
||||
}
|
||||
else if (stackType.value === 'python') {
|
||||
formatedStackTrace.value.textContent = cleanedStackTrace;
|
||||
PythonStack('.stacktrace', { prettyprint: true });
|
||||
}
|
||||
else if (stackType.value === 'net') {
|
||||
formatedStackTrace.value.innerText = cleanedStackTrace;
|
||||
const _ = new NetStack(formatedStackTrace.value, { prettyprint: true });
|
||||
}
|
||||
stackTraceText.value = formatedStackTrace.value.innerText;
|
||||
}
|
||||
catch {}
|
||||
});
|
||||
|
||||
const stackTraceMarkdown = computed(() => {
|
||||
let lang;
|
||||
if (stackType.value === 'net') {
|
||||
lang = 'csharp';
|
||||
}
|
||||
else if (stackType.value === 'js') {
|
||||
lang = 'javascript';
|
||||
}
|
||||
else if (stackType.value === 'java') {
|
||||
lang = 'java';
|
||||
}
|
||||
else if (stackType.value === 'python') {
|
||||
lang = 'python';
|
||||
}
|
||||
return `\`\`\`${lang}\n${formatedStackTrace.value?.innerText}\n\`\`\``;
|
||||
});
|
||||
|
||||
const { copy: copyText } = useCopy({ source: stackTraceText, text: 'Formatted stacktrace copied to the clipboard' });
|
||||
const { copy: copyMarkdown } = useCopy({ source: stackTraceMarkdown, text: 'Markdown Formatted stacktrace copied to the clipboard' });
|
||||
|
||||
async function downloadAsPNG() {
|
||||
const dataUrl = await domtoimage.toPng(formatedStackTrace.value, { bgcolor: styleStore.isDarkTheme ? '#333' : '#fff' });
|
||||
const link = document.createElement('a');
|
||||
link.download = 'stacktrace.png';
|
||||
link.href = dataUrl;
|
||||
link.click();
|
||||
}
|
||||
|
||||
const wrap = ref(true);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div max-w-600px>
|
||||
<n-radio-group v-model:value="stackType" name="radiogroup" mb-2 flex justify-center>
|
||||
<n-space>
|
||||
<n-radio
|
||||
value="net"
|
||||
label=".Net"
|
||||
/>
|
||||
<n-radio
|
||||
value="js"
|
||||
label="Javascript"
|
||||
/>
|
||||
<n-radio
|
||||
value="python"
|
||||
label="Python"
|
||||
/>
|
||||
<n-radio
|
||||
value="java"
|
||||
label="Java"
|
||||
/>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
|
||||
<div mb-2 flex justify-center>
|
||||
<n-checkbox v-model:checked="wrap">
|
||||
Wrap lines?
|
||||
</n-checkbox>
|
||||
</div>
|
||||
<c-input-text
|
||||
v-model:value="stackTrace"
|
||||
label="Stacktrace"
|
||||
placeholder="Paste your stacktrace here.."
|
||||
multiline
|
||||
rows="5"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<pre ref="formatedStackTrace" class="stacktrace" :style="{ padding: '20px', whiteSpace: wrap ? 'pre-wrap' : 'pre', overflowX: 'auto', wordBreak: 'break-all' }" />
|
||||
|
||||
<div v-if="stackTraceText" flex justify-center gap-1>
|
||||
<c-button @click="copyText()">
|
||||
Copy Formatted (Text)
|
||||
</c-button>
|
||||
<c-button @click="copyMarkdown()">
|
||||
Copy Formatted (Markdown)
|
||||
</c-button>
|
||||
<c-button @click="downloadAsPNG()">
|
||||
Download as PNG
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.stacktrace) {
|
||||
pre, code {background-color:#333 !important; color: #fff !important;}
|
||||
.st-type {color: #0a8472; font-weight: bolder;}
|
||||
.st-method {color: #70c9ba; font-weight: bolder;}
|
||||
.st-frame-params {color: #ffffff; font-weight: normal;}
|
||||
.st-param-type {color: #0a8472;}
|
||||
.st-param-name {color: #ffffff;}
|
||||
.st-file {color:#f8b068;}
|
||||
.st-line {color:#ff4f68;}
|
||||
.st-methodName {color: #70c9ba;font-weight: bolder;}
|
||||
.st-column {color: #f8b068;}
|
||||
.st-lineNumber {color: #ff4f68;}
|
||||
.st-fileName {color: #85dbff;}
|
||||
.st-intro {color: #0044dd;}
|
||||
.st-exception {color: #e40000;}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user