mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 08:46:15 -04:00
feat(new-tool): math evaluator
This commit is contained in:
parent
8fb0e6af9c
commit
433ba2a3e5
3 changed files with 83 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { LockOpen } from '@vicons/tabler';
|
import { LockOpen } from '@vicons/tabler';
|
||||||
import type { ToolCategory } from './tool';
|
import type { ToolCategory } from './tool';
|
||||||
|
|
||||||
|
import { tool as mathEvaluator } from './math-evaluator';
|
||||||
import { tool as jsonViewer } from './json-viewer';
|
import { tool as jsonViewer } from './json-viewer';
|
||||||
import { tool as htmlEntities } from './html-entities';
|
import { tool as htmlEntities } from './html-entities';
|
||||||
import { tool as urlParser } from './url-parser';
|
import { tool as urlParser } from './url-parser';
|
||||||
|
@ -53,6 +54,11 @@ export const toolsByCategory: ToolCategory[] = [
|
||||||
icon: LockOpen,
|
icon: LockOpen,
|
||||||
components: [gitMemo, randomPortGenerator, crontabGenerator, jsonViewer],
|
components: [gitMemo, randomPortGenerator, crontabGenerator, jsonViewer],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Math',
|
||||||
|
icon: LockOpen,
|
||||||
|
components: [mathEvaluator],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Text',
|
name: 'Text',
|
||||||
icon: LockOpen,
|
icon: LockOpen,
|
||||||
|
|
39
src/tools/math-evaluator/index.ts
Normal file
39
src/tools/math-evaluator/index.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import { Math } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Math evaluator',
|
||||||
|
path: '/math-evaluator',
|
||||||
|
description: `Evaluate math expression, like a calculator on steroid (you can use function like sqrt, cos, sin, abs, ...)`,
|
||||||
|
keywords: [
|
||||||
|
'math',
|
||||||
|
'evaluator',
|
||||||
|
'acos',
|
||||||
|
'acosh',
|
||||||
|
'acot',
|
||||||
|
'acoth',
|
||||||
|
'acsc',
|
||||||
|
'acsch',
|
||||||
|
'asec',
|
||||||
|
'asech',
|
||||||
|
'asin',
|
||||||
|
'asinh',
|
||||||
|
'atan',
|
||||||
|
'atan2',
|
||||||
|
'atanh',
|
||||||
|
'cos',
|
||||||
|
'cosh',
|
||||||
|
'cot',
|
||||||
|
'coth',
|
||||||
|
'csc',
|
||||||
|
'csch',
|
||||||
|
'sec',
|
||||||
|
'sech',
|
||||||
|
'sin',
|
||||||
|
'sinh',
|
||||||
|
'tan',
|
||||||
|
'tanh',
|
||||||
|
],
|
||||||
|
component: () => import('./math-evaluator.vue'),
|
||||||
|
icon: Math,
|
||||||
|
});
|
38
src/tools/math-evaluator/math-evaluator.vue
Normal file
38
src/tools/math-evaluator/math-evaluator.vue
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<n-input
|
||||||
|
v-model:value="expression"
|
||||||
|
rows="1"
|
||||||
|
type="textarea"
|
||||||
|
placeholder="Your math expression (ex: 2*sqrt(6) )..."
|
||||||
|
size="large"
|
||||||
|
autocomplete="off"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="off"
|
||||||
|
spellcheck="false"
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<n-card v-if="result !== ''" title="Result ">
|
||||||
|
{{ result }}
|
||||||
|
</n-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { evaluate } from 'mathjs';
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
const expression = ref('');
|
||||||
|
|
||||||
|
const result = computed(() => {
|
||||||
|
try {
|
||||||
|
return evaluate(expression.value) ?? '';
|
||||||
|
} catch (_) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped></style>
|
Loading…
Add table
Add a link
Reference in a new issue