Skip to content

Commit

Permalink
feat(new tool): CSS <> XPath converter
Browse files Browse the repository at this point in the history
Convert CSS Selectors from/to XPath expressions
  • Loading branch information
sharevb committed Aug 23, 2024
1 parent 318fb6e commit 9204abe
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/tools/css-xpath-converter/css-xpath-converter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script setup lang="ts">
import xPathToCss from 'xpath-to-css';

Check failure on line 2 in src/tools/css-xpath-converter/css-xpath-converter.vue

View workflow job for this annotation

GitHub Actions / ci

Cannot find module 'xpath-to-css' or its corresponding type declarations.
import cssToXpath from 'csstoxpath';

Check failure on line 3 in src/tools/css-xpath-converter/css-xpath-converter.vue

View workflow job for this annotation

GitHub Actions / ci

Cannot find module 'csstoxpath' or its corresponding type declarations.
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const cssInput = ref('');
const xpathOutput = computed(
() => {
try {
return cssToXpath(cssInput.value);
}
catch (e: any) {
return e.toString();
}
},
);
const xpathInput = ref('');
const cssOutput = computed(
() => {
try {
return xPathToCss(xpathInput.value);
}
catch (e: any) {
return e.toString();
}
},
);
</script>

<template>
<div max-w-600>
<c-card title="CSS to XPath">
<c-input-text
v-model:value="cssInput"
placeholder="Put your CSS selector here..."
label="CSS selector to convert"
raw-text
mb-5
/>

<n-divider />

<TextareaCopyable
label="XPath expression"
:value="xpathOutput"
readonly
mb-5
/>
</c-card>

<c-card title="XPath to CSS" mt-5>
<c-input-text
v-model:value="xpathInput"
placeholder="Put your XPath expression here..."
label="XPath expression to convert"
raw-text
mb-5
/>

<n-divider />

<TextareaCopyable
label="CSS Selector"
:value="cssOutput"
readonly
mb-5
/>
</c-card>
</div>
</template>
12 changes: 12 additions & 0 deletions src/tools/css-xpath-converter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'Css XPath Converter',
path: '/css-xpath-converter',
description: 'Convert CSS selector to/from XPath expression',
keywords: ['css', 'xpath', 'converter'],
component: () => import('./css-xpath-converter.vue'),
icon: Braces,
createdAt: new Date('2024-08-15'),
});
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 emailNormalizer } from './email-normalizer';
import { tool as cssXpathConverter } from './css-xpath-converter';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -154,6 +155,7 @@ export const toolsByCategory: ToolCategory[] = [
xmlFormatter,
yamlViewer,
emailNormalizer,
cssXpathConverter,
],
},
{
Expand Down

0 comments on commit 9204abe

Please sign in to comment.