Compare commits

..
Author SHA1 Message Date
ShareVB c640b40710 feat(Barcode Generator): use bwip-js to add more barcode types
Including Datamatrix, fix #1343
2025-01-26 19:34:51 +01:00
ShareVB 15f6c91d95 fix: deps 2024-07-14 23:35:46 +02:00
ShareVB acc00298ad fix: update queryParams 2024-07-14 23:25:04 +02:00
ShareVB c66103e9b8 Merge remote-tracking branch 'origin/main' into feat/barcodes 2024-07-14 23:24:21 +02:00
sharevb fef1993ab8 feat(new tools): Barcode Reader and Generator
Fix #437 and #805
2024-05-19 23:41:27 +02:00
35 changed files with 742 additions and 1441 deletions

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

+1 -5
View File
@@ -1,8 +1,4 @@
<picture>
<source srcset="./.github/logo-dark.png" media="(prefers-color-scheme: light)">
<source srcset="./.github/logo-white.png" media="(prefers-color-scheme: dark)">
<img src="./.github/logo-dark.png" alt="logo">
</picture>
![logo](.github/logo.png)
Useful tools for developer and people working in IT. [Have a look !](https://it-tools.tech).
+7 -14
View File
@@ -13,6 +13,8 @@ declare module '@vue/runtime-core' {
About: typeof import('./src/pages/About.vue')['default']
App: typeof import('./src/App.vue')['default']
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
BarcodeGenerator: typeof import('./src/tools/barcode-generator/barcode-generator.vue')['default']
BarcodeReader: typeof import('./src/tools/barcode-reader/barcode-reader.vue')['default']
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
@@ -72,7 +74,6 @@ declare module '@vue/runtime-core' {
DockerRunToDockerComposeConverter: typeof import('./src/tools/docker-run-to-docker-compose-converter/docker-run-to-docker-compose-converter.vue')['default']
DynamicValues: typeof import('./src/tools/benchmark-builder/dynamic-values.vue')['default']
Editor: typeof import('./src/tools/html-wysiwyg-editor/editor/editor.vue')['default']
EmailNormalizer: typeof import('./src/tools/email-normalizer/email-normalizer.vue')['default']
EmojiCard: typeof import('./src/tools/emoji-picker/emoji-card.vue')['default']
EmojiGrid: typeof import('./src/tools/emoji-picker/emoji-grid.vue')['default']
EmojiPicker: typeof import('./src/tools/emoji-picker/emoji-picker.vue')['default']
@@ -108,11 +109,9 @@ declare module '@vue/runtime-core' {
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default']
JsonEditor: typeof import('./src/tools/json-editor/json-editor.vue')['default']
JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default']
JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default']
JsonToToml: typeof import('./src/tools/json-to-toml/json-to-toml.vue')['default']
JsonToXml: typeof import('./src/tools/json-to-xml/json-to-xml.vue')['default']
JsonToYaml: typeof import('./src/tools/json-to-yaml-converter/json-to-yaml.vue')['default']
JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default']
JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default']
@@ -122,7 +121,6 @@ declare module '@vue/runtime-core' {
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
MacAddressGenerator: typeof import('./src/tools/mac-address-generator/mac-address-generator.vue')['default']
MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default']
MarkdownToHtml: typeof import('./src/tools/markdown-to-html/markdown-to-html.vue')['default']
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']
MenuBar: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar.vue')['default']
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
@@ -133,22 +131,21 @@ declare module '@vue/runtime-core' {
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NForm: typeof import('naive-ui')['NForm']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NGi: typeof import('naive-ui')['NGi']
NGrid: typeof import('naive-ui')['NGrid']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSlider: typeof import('naive-ui')['NSlider']
NSpin: typeof import('naive-ui')['NSpin']
NSwitch: typeof import('naive-ui')['NSwitch']
NTable: typeof import('naive-ui')['NTable']
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']
@@ -158,9 +155,6 @@ declare module '@vue/runtime-core' {
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
RegexMemo: typeof import('./src/tools/regex-memo/regex-memo.vue')['default']
'RegexMemo.content': typeof import('./src/tools/regex-memo/regex-memo.content.md')['default']
RegexTester: typeof import('./src/tools/regex-tester/regex-tester.vue')['default']
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
@@ -193,7 +187,6 @@ declare module '@vue/runtime-core' {
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
WifiQrCodeGenerator: typeof import('./src/tools/wifi-qr-code-generator/wifi-qr-code-generator.vue')['default']
XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default']
XmlToJson: typeof import('./src/tools/xml-to-json/xml-to-json.vue')['default']
YamlToJson: typeof import('./src/tools/yaml-to-json-converter/yaml-to-json.vue')['default']
YamlToToml: typeof import('./src/tools/yaml-to-toml/yaml-to-toml.vue')['default']
YamlViewer: typeof import('./src/tools/yaml-viewer/yaml-viewer.vue')['default']
+5 -10
View File
@@ -35,21 +35,22 @@
"release": "node ./scripts/release.mjs"
},
"dependencies": {
"@chenfengyuan/vue-barcode": "^2.0.2",
"@it-tools/bip39": "^0.0.4",
"@it-tools/oggen": "^1.3.0",
"@regexper/render": "^1.0.0",
"@sindresorhus/slugify": "^2.2.1",
"@tiptap/pm": "2.1.6",
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/figlet": "^1.5.8",
"@types/markdown-it": "^13.0.7",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
"@vueuse/core": "^10.3.0",
"@vueuse/head": "^1.0.0",
"@vueuse/router": "^10.0.0",
"@zxing/library": "^0.21.0",
"bcryptjs": "^2.4.3",
"bwip-js": "^4.5.1",
"change-case": "^4.1.2",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
@@ -59,7 +60,6 @@
"crypto-js": "^4.1.1",
"date-fns": "^2.29.3",
"dompurify": "^3.0.6",
"email-normalizer": "^1.0.0",
"emojilib": "^3.0.10",
"figlet": "^1.7.0",
"figue": "^1.2.0",
@@ -67,13 +67,12 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"js-base64": "^3.7.6",
"json-editor-vue": "^0.16.0",
"js-base64": "^3.7.7",
"jsbarcode": "^3.11.6",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21",
"markdown-it": "^14.0.0",
"marked": "^10.0.0",
"mathjs": "^11.9.1",
"mime-types": "^2.1.35",
@@ -86,21 +85,17 @@
"pinia": "^2.0.34",
"plausible-tracker": "^0.3.8",
"qrcode": "^1.5.1",
"randexp": "^0.5.3",
"sql-formatter": "^13.0.0",
"ua-parser-js": "^1.0.35",
"ulid": "^2.3.0",
"unicode-emoji-json": "^0.4.0",
"unplugin-auto-import": "^0.16.4",
"uuid": "^9.0.0",
"vanilla-jsoneditor": "^0.23.8",
"vue": "^3.3.4",
"vue-i18n": "^9.9.1",
"vue-router": "^4.1.6",
"vue-shadow-dom": "^4.2.0",
"vue-tsc": "^1.8.1",
"xml-formatter": "^3.3.2",
"xml-js": "^1.6.11",
"yaml": "^2.2.1"
},
"devDependencies": {
+305 -544
View File
File diff suppressed because it is too large. Load diff
-2
View File
@@ -7,7 +7,6 @@ import sqlHljs from 'highlight.js/lib/languages/sql';
import xmlHljs from 'highlight.js/lib/languages/xml';
import yamlHljs from 'highlight.js/lib/languages/yaml';
import iniHljs from 'highlight.js/lib/languages/ini';
import markdownHljs from 'highlight.js/lib/languages/markdown';
import { useCopy } from '@/composable/copy';
const props = withDefaults(
@@ -31,7 +30,6 @@ hljs.registerLanguage('html', xmlHljs);
hljs.registerLanguage('xml', xmlHljs);
hljs.registerLanguage('yaml', yamlHljs);
hljs.registerLanguage('toml', iniHljs);
hljs.registerLanguage('markdown', markdownHljs);
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
+1 -18
View File
@@ -3,11 +3,9 @@ import _ from 'lodash';
import { type Ref, reactive, watch } from 'vue';
type ValidatorReturnType = unknown;
type GetErrorMessageReturnType = string;
export interface UseValidationRule<T> {
validator: (value: T) => ValidatorReturnType
getErrorMessage?: (value: T) => GetErrorMessageReturnType
message: string
}
@@ -26,15 +24,6 @@ export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
}
}
export function getErrorMessageOrThrown(cb: () => GetErrorMessageReturnType): string {
try {
return cb() || '';
}
catch (e: any) {
return e.toString();
}
}
export interface ValidationAttrs {
feedback: string
validationStatus: string | undefined
@@ -72,13 +61,7 @@ export function useValidation<T>({
for (const rule of get(rules)) {
if (isFalsyOrHasThrown(() => rule.validator(source.value))) {
if (rule.getErrorMessage) {
const getErrorMessage = rule.getErrorMessage;
state.message = rule.message.replace('{0}', getErrorMessageOrThrown(() => getErrorMessage(source.value)));
}
else {
state.message = rule.message;
}
state.message = rule.message;
state.status = 'error';
}
}
-2
View File
@@ -3,7 +3,6 @@ import { createPinia } from 'pinia';
import { createHead } from '@vueuse/head';
import { registerSW } from 'virtual:pwa-register';
import shadow from 'vue-shadow-dom';
import { plausible } from './plugins/plausible.plugin';
import 'virtual:uno.css';
@@ -24,6 +23,5 @@ app.use(i18nPlugin);
app.use(router);
app.use(naive);
app.use(plausible);
app.use(shadow);
app.mount('#app');
@@ -0,0 +1,127 @@
<script setup lang="ts">
import bwipjs, { type RenderOptions } from 'bwip-js/browser';
import { Base64 } from 'js-base64';
import formats from './barcode.formats.json';
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const foreground = useQueryParamOrStorage({ name: 'fg', storageName: 'barcode-gen:fg', defaultValue: '#000000' });
const background = useQueryParamOrStorage({ name: 'bg', storageName: 'barcode-gen:bg', defaultValue: '#FFFFFF' });
const scale = useQueryParamOrStorage({ name: 'scale', storageName: 'barcode-gen:scale', defaultValue: 2 });
const height = useQueryParamOrStorage({ name: 'height', storageName: 'barcode-gen:height', defaultValue: 25 });
const margin = useQueryParamOrStorage({ name: 'margin', storageName: 'barcode-gen:margin', defaultValue: 10 });
const format = useQueryParamOrStorage({ name: 'format', storageName: 'barcode-gen:format', defaultValue: 'code128' });
const displayValue = useQueryParamOrStorage({ name: 'display', storageName: 'barcode-gen:display', defaultValue: true });
const value = ref('123456789');
const barcodeCanvas = ref<HTMLCanvasElement>();
const options = computed<RenderOptions>(() => ({
barcolor: foreground.value,
textcolor: foreground.value,
backgroundcolor: background.value,
scale: scale.value,
height: height.value,
padding: margin.value,
bcid: format.value === 'auto' ? 'code128' : format.value,
includetext: displayValue.value,
text: value.value,
textxalign: 'center',
}));
const error = ref('');
watchEffect(() => {
if (!barcodeCanvas.value) {
return;
}
try {
bwipjs.toCanvas(barcodeCanvas.value, options.value);
}
catch (e: any) {
error.value = e.toString();
}
});
const barcodePNG = computed(() => {
return barcodeCanvas.value?.toDataURL('image/png') || '';
});
const barcodeSVG = computed(() => {
try {
return Base64.encode(bwipjs.toSVG(options.value));
}
catch (e: any) {
return '';
}
});
const { download: downloadPNG } = useDownloadFileFromBase64({ source: barcodePNG, filename: 'barcode.png' });
const { download: downloadSVG } = useDownloadFileFromBase64({ source: barcodeSVG, filename: 'barcode.svg' });
</script>
<template>
<c-card>
<n-grid x-gap="12" y-gap="12" cols="1 600:3">
<n-gi span="2">
<c-input-text
v-model:value="value"
label-position="left"
label-width="130px"
label-align="right"
label="Text:"
multiline
rows="1"
autosize
placeholder="Your barcode..."
mb-6
/>
<n-form label-width="130" label-placement="left">
<c-select
v-model:value="format"
label="Format:"
label-position="left"
label-width="130px"
label-align="right"
:options="formats"
searchable
mb-4
/>
<n-form-item label="Foreground color:">
<n-color-picker v-model:value="foreground" :modes="['hex']" :show-alpha="false" />
</n-form-item>
<n-form-item label="Background color:">
<n-color-picker v-model:value="background" :modes="['hex']" :show-alpha="false" />
</n-form-item>
<n-form-item label="Scale:">
<n-input-number v-model:value="scale" :min="0" />
</n-form-item>
<n-form-item label="Height (mm):">
<n-input-number v-model:value="height" :min="0" />
</n-form-item>
<n-form-item label="Margin:">
<n-input-number v-model:value="margin" :min="0" />
</n-form-item>
<n-form-item label="Display text:">
<n-checkbox v-model:checked="displayValue" />
</n-form-item>
</n-form>
</n-gi>
<n-gi>
<div flex flex-col items-center gap-3>
<c-alert v-if="error">
{{ error }}
</c-alert>
<canvas ref="barcodeCanvas" />
<div flex justify-center>
<c-button mr-2 @click="downloadPNG">
Download PNG barcode
</c-button>
<c-button @click="downloadSVG">
Download SVG barcode
</c-button>
</div>
</div>
</n-gi>
</n-grid>
</c-card>
</template>
@@ -0,0 +1,112 @@
[
{ "value": "auspost", "label": "AusPost 4 State Customer Code" },
{ "value": "azteccode", "label": "Aztec Code" },
{ "value": "azteccodecompact", "label": "Compact Aztec Code" },
{ "value": "aztecrune", "label": "Aztec Runes" },
{ "value": "bc412", "label": "BC412" },
{ "value": "channelcode", "label": "Channel Code" },
{ "value": "codablockf", "label": "Codablock F" },
{ "value": "code11", "label": "Code 11" },
{ "value": "code128", "label": "Code 128" },
{ "value": "code16k", "label": "Code 16K" },
{ "value": "code2of5", "label": "Code 25" },
{ "value": "code32", "label": "Italian Pharmacode" },
{ "value": "code39", "label": "Code 39" },
{ "value": "code39ext", "label": "Code 39 Extended" },
{ "value": "code49", "label": "Code 49" },
{ "value": "code93", "label": "Code 93" },
{ "value": "code93ext", "label": "Code 93 Extended" },
{ "value": "codeone", "label": "Code One" },
{ "value": "coop2of5", "label": "COOP 2 of 5" },
{ "value": "daft", "label": "Custom 4 state symbology" },
{ "value": "databarexpanded", "label": "GS1 DataBar Expanded" },
{ "value": "databarexpandedcomposite", "label": "GS1 DataBar Expanded Composite" },
{ "value": "databarexpandedstacked", "label": "GS1 DataBar Expanded Stacked" },
{ "value": "databarexpandedstackedcomposite", "label": "GS1 DataBar Expanded Stacked Composite" },
{ "value": "databarlimited", "label": "GS1 DataBar Limited" },
{ "value": "databarlimitedcomposite", "label": "GS1 DataBar Limited Composite" },
{ "value": "databaromni", "label": "GS1 DataBar Omnidirectional" },
{ "value": "databaromnicomposite", "label": "GS1 DataBar Omnidirectional Composite" },
{ "value": "databarstacked", "label": "GS1 DataBar Stacked" },
{ "value": "databarstackedcomposite", "label": "GS1 DataBar Stacked Composite" },
{ "value": "databarstackedomni", "label": "GS1 DataBar Stacked Omnidirectional" },
{ "value": "databarstackedomnicomposite", "label": "GS1 DataBar Stacked Omnidirectional Composite" },
{ "value": "databartruncated", "label": "GS1 DataBar Truncated" },
{ "value": "databartruncatedcomposite", "label": "GS1 DataBar Truncated Composite" },
{ "value": "datalogic2of5", "label": "Datalogic 2 of 5" },
{ "value": "datamatrix", "label": "Data Matrix" },
{ "value": "datamatrixrectangular", "label": "Data Matrix Rectangular" },
{ "value": "datamatrixrectangularextension", "label": "Data Matrix Rectangular Extension" },
{ "value": "dotcode", "label": "DotCode" },
{ "value": "ean13", "label": "EAN-13" },
{ "value": "ean13composite", "label": "EAN-13 Composite" },
{ "value": "ean14", "label": "GS1-14" },
{ "value": "ean2", "label": "EAN-2 (2 digit addon)" },
{ "value": "ean5", "label": "EAN-5 (5 digit addon)" },
{ "value": "ean8", "label": "EAN-8" },
{ "value": "ean8composite", "label": "EAN-8 Composite" },
{ "value": "flattermarken", "label": "Flattermarken" },
{ "value": "gs1-128", "label": "GS1-128" },
{ "value": "gs1-128composite", "label": "GS1-128 Composite" },
{ "value": "gs1-cc", "label": "GS1 Composite 2D Component" },
{ "value": "gs1datamatrix", "label": "GS1 Data Matrix" },
{ "value": "gs1datamatrixrectangular", "label": "GS1 Data Matrix Rectangular" },
{ "value": "gs1dldatamatrix", "label": "GS1 Digital Link Data Matrix" },
{ "value": "gs1dlqrcode", "label": "GS1 Digital Link QR Code" },
{ "value": "gs1dotcode", "label": "GS1 DotCode" },
{ "value": "gs1northamericancoupon", "label": "GS1 North American Coupon" },
{ "value": "gs1qrcode", "label": "GS1 QR Code" },
{ "value": "hanxin", "label": "Han Xin Code" },
{ "value": "hibcazteccode", "label": "HIBC Aztec Code" },
{ "value": "hibccodablockf", "label": "HIBC Codablock F" },
{ "value": "hibccode128", "label": "HIBC Code 128" },
{ "value": "hibccode39", "label": "HIBC Code 39" },
{ "value": "hibcdatamatrix", "label": "HIBC Data Matrix" },
{ "value": "hibcdatamatrixrectangular", "label": "HIBC Data Matrix Rectangular" },
{ "value": "hibcmicropdf417", "label": "HIBC MicroPDF417" },
{ "value": "hibcpdf417", "label": "HIBC PDF417" },
{ "value": "hibcqrcode", "label": "HIBC QR Code" },
{ "value": "iata2of5", "label": "IATA 2 of 5" },
{ "value": "identcode", "label": "Deutsche Post Identcode" },
{ "value": "industrial2of5", "label": "Industrial 2 of 5" },
{ "value": "interleaved2of5", "label": "Interleaved 2 of 5 (ITF)" },
{ "value": "isbn", "label": "ISBN" },
{ "value": "ismn", "label": "ISMN" },
{ "value": "issn", "label": "ISSN" },
{ "value": "itf14", "label": "ITF-14" },
{ "value": "japanpost", "label": "Japan Post 4 State Customer Code" },
{ "value": "kix", "label": "Royal Dutch TPG Post KIX" },
{ "value": "leitcode", "label": "Deutsche Post Leitcode" },
{ "value": "mailmark", "label": "Royal Mail Mailmark" },
{ "value": "mands", "label": "Marks & Spencer" },
{ "value": "matrix2of5", "label": "Matrix 2 of 5" },
{ "value": "maxicode", "label": "MaxiCode" },
{ "value": "micropdf417", "label": "MicroPDF417" },
{ "value": "microqrcode", "label": "Micro QR Code" },
{ "value": "msi", "label": "MSI Modified Plessey" },
{ "value": "onecode", "label": "USPS Intelligent Mail" },
{ "value": "pdf417", "label": "PDF417" },
{ "value": "pdf417compact", "label": "Compact PDF417" },
{ "value": "pharmacode", "label": "Pharmaceutical Binary Code" },
{ "value": "pharmacode2", "label": "Two-track Pharmacode" },
{ "value": "planet", "label": "USPS PLANET" },
{ "value": "plessey", "label": "Plessey UK" },
{ "value": "posicode", "label": "PosiCode" },
{ "value": "postnet", "label": "USPS POSTNET" },
{ "value": "pzn", "label": "Pharmazentralnummer (PZN)" },
{ "value": "qrcode", "label": "QR Code" },
{ "value": "rationalizedCodabar", "label": "Codabar" },
{ "value": "raw", "label": "Custom 1D symbology" },
{ "value": "rectangularmicroqrcode", "label": "Rectangular Micro QR Code" },
{ "value": "royalmail", "label": "Royal Mail 4 State Customer Code" },
{ "value": "sscc18", "label": "SSCC-18" },
{ "value": "swissqrcode", "label": "Swiss QR Code" },
{ "value": "symbol", "label": "Miscellaneous symbols" },
{ "value": "telepen", "label": "Telepen" },
{ "value": "telepennumeric", "label": "Telepen Numeric" },
{ "value": "ultracode", "label": "Ultracode" },
{ "value": "upca", "label": "UPC-A" },
{ "value": "upcacomposite", "label": "UPC-A Composite" },
{ "value": "upce", "label": "UPC-E" },
{ "value": "upcecomposite", "label": "UPC-E Composite" }
]
+82
View File
@@ -0,0 +1,82 @@
declare module 'bwip-js/browser' {
export interface BwippOptions {
includecheck?: boolean | undefined;
includecheckintext?: boolean | undefined;
parse?: boolean | undefined;
parsefnc?: boolean | undefined;
height?: number | undefined;
width?: number | undefined;
inkspread?: number | undefined;
inkspreadh?: number | undefined;
inkspreadv?: number | undefined;
dotty?: boolean | undefined;
binarytext?: boolean | undefined; // really a bwip-js option but better positioned here
includetext?: boolean | undefined;
textfont?: string | undefined;
textsize?: number | undefined;
textgaps?: number | undefined;
alttext?: string | undefined;
textxalign?: 'offleft' | 'left' | 'center' | 'right' | 'offright' | 'justify' | undefined;
textyalign?: 'below' | 'center' | 'above' | undefined;
textxoffset?: number | undefined;
textyoffset?: number | undefined;
showborder?: boolean | undefined;
borderwidth?: number | undefined;
borderleft?: number | undefined;
borderright?: number | undefined;
bordertop?: number | undefined;
boraderbottom?: number | undefined;
barcolor?: string | undefined;
backgroundcolor?: string | undefined;
bordercolor?: string | undefined;
textcolor?: string | undefined;
addontextxoffset?: number | undefined;
addontextyoffset?: number | undefined;
addontextfont?: string | undefined;
addontextsize?: number | undefined;
guardwhitespace?: boolean | undefined;
guardwidth?: number | undefined;
guardheight?: number | undefined;
guardleftpos?: number | undefined;
guardrightpos?: number | undefined;
guardleftypos?: number | undefined;
guardrightypos?: number | undefined;
}
export interface RenderOptions extends BwippOptions {
bcid: string;
text: string;
scaleX?: number | undefined;
scaleY?: number | undefined;
scale?: number | undefined;
rotate?: 'N' | 'R' | 'L' | 'I' | undefined;
paddingwidth?: number | undefined;
paddingheight?: number | undefined;
paddingleft?: number | undefined;
paddingright?: number | undefined;
paddingtop?: number | undefined;
paddingbottom?: number | undefined;
monochrome?: boolean | undefined;
sizelimit?: number | undefined;
}
export const BWIPP_VERSION: string;
export const BWIPJS_VERSION: string;
export function toSVG(opts: RenderOptions): string;
export function toCanvas(canvas: string | HTMLCanvasElement, opts: RenderOptions): HTMLCanvasElement;
}
+12
View File
@@ -0,0 +1,12 @@
import { Barcode } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Barcode Generator',
path: '/barcode-generator',
description: 'Barcode generator',
keywords: ['barcode', 'generator'],
component: () => import('./barcode-generator.vue'),
icon: Barcode,
createdAt: new Date('2024-04-20'),
});
@@ -0,0 +1,66 @@
<script setup lang="ts">
import { BarcodeFormat, BrowserMultiFormatReader } from '@zxing/library';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const imageBase64 = ref('');
const barCode = computedAsync(async () => {
if (imageBase64.value === '') {
return { text: '', format: '', error: '' };
}
try {
const barcodeReader = new BrowserMultiFormatReader();
const result = (await barcodeReader.decodeFromImageUrl(imageBase64.value));
return { text: result.getText(), format: BarcodeFormat[result.getBarcodeFormat()], error: '' };
}
catch (e: any) {
return { error: e.toString(), text: '', format: '' };
}
});
function blobToBase64(blob: Blob) {
if (blob === null) {
return Promise.resolve('');
}
return new Promise<string>((resolve, _reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);
reader.readAsDataURL(blob);
});
}
async function onUpload(file: File) {
if (file) {
imageBase64.value = await blobToBase64(file);
}
}
</script>
<template>
<div>
<c-file-upload
title="Drag and drop a BarCode here, or click to select a file"
:paste-image="true"
mb-3
@file-upload="onUpload"
/>
<div v-if="barCode?.text">
<n-divider />
<h3>Decoded <span v-if="barCode?.format">({{ barCode?.format }})</span></h3>
<TextareaCopyable
:value="barCode?.text"
:word-wrap="true"
/>
</div>
<c-alert v-if="barCode?.error">
{{ barCode?.error }}
</c-alert>
</div>
</template>
<style lang="less" scoped>
::v-deep(.n-upload-trigger) {
width: 100%;
}
</style>
+12
View File
@@ -0,0 +1,12 @@
import { Barcode } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Barcode Reader',
path: '/barcode-reader',
description: 'Barcode reader',
keywords: ['barcode', 'reader'],
component: () => import('./barcode-reader.vue'),
icon: Barcode,
createdAt: new Date('2024-04-20'),
});
@@ -1,65 +0,0 @@
<script setup lang="ts">
import { normalizeEmail } from 'email-normalizer';
import { withDefaultOnError } from '@/utils/defaults';
import { useCopy } from '@/composable/copy';
const emails = ref('');
const normalizedEmails = computed(() => {
if (!emails.value) {
return '';
}
return emails.value
.split('\n')
.map((email) => {
return withDefaultOnError(() => normalizeEmail({ email }), `Unable to parse email: ${email}`);
})
.join('\n');
});
const { copy } = useCopy({ source: normalizedEmails, text: 'Normalized emails copied to the clipboard', createToast: true });
</script>
<template>
<div>
<div class="mb-2">
Raw emails to normalize:
</div>
<c-input-text
v-model:value="emails"
placeholder="Put your emails here (one per line)..."
rows="3"
multiline
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
autofocus
monospace
/>
<div class="mb-2 mt-4">
Normalized emails:
</div>
<c-input-text
:value="normalizedEmails"
placeholder="Normalized emails will appear here..."
rows="3"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
multiline
readonly
monospace
/>
<div class="mt-4 flex justify-center gap-2">
<c-button @click="emails = ''">
Clear emails
</c-button>
<c-button :disabled="!normalizedEmails" @click="copy()">
Copy normalized emails
</c-button>
</div>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { Mail } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Email normalizer',
path: '/email-normalizer',
description: 'Normalize email addresses to a standard format for easier comparison. Useful for deduplication and data cleaning.',
keywords: ['email', 'normalizer'],
component: () => import('./email-normalizer.vue'),
icon: Mail,
createdAt: new Date('2024-08-15'),
});
+10 -15
View File
@@ -1,18 +1,11 @@
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 jsonEditor } from './json-editor';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as xmlToJson } from './xml-to-json';
import { tool as jsonToXml } from './json-to-xml';
import { tool as regexTester } from './regex-tester';
import { tool as regexMemo } from './regex-memo';
import { tool as markdownToHtml } from './markdown-to-html';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -88,6 +81,8 @@ import { tool as uuidGenerator } from './uuid-generator';
import { tool as macAddressLookup } from './mac-address-lookup';
import { tool as xmlFormatter } from './xml-formatter';
import { tool as yamlViewer } from './yaml-viewer';
import { tool as barcodeReader } from './barcode-reader';
import { tool as barcodeGenerator } from './barcode-generator';
export const toolsByCategory: ToolCategory[] = [
{
@@ -114,9 +109,6 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
xmlToJson,
jsonToXml,
markdownToHtml,
],
},
{
@@ -142,7 +134,14 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Images and videos',
components: [qrCodeGenerator, wifiQrCodeGenerator, svgPlaceholderGenerator, cameraRecorder],
components: [
qrCodeGenerator,
wifiQrCodeGenerator,
svgPlaceholderGenerator,
cameraRecorder,
barcodeReader,
barcodeGenerator,
],
},
{
name: 'Development',
@@ -158,10 +157,6 @@ export const toolsByCategory: ToolCategory[] = [
dockerRunToDockerComposeConverter,
xmlFormatter,
yamlViewer,
jsonEditor,
emailNormalizer,
regexTester,
regexMemo,
],
},
{
-12
View File
@@ -1,12 +0,0 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'JSON Editor',
path: '/json-editor',
description: 'Edit JSON content',
keywords: ['json', 'editor'],
component: () => import('./json-editor.vue'),
icon: Braces,
createdAt: new Date('2024-05-11'),
});
-54
View File
@@ -1,54 +0,0 @@
<script setup lang="ts">
import JsonEditorVue from 'json-editor-vue';
import { type AfterSelection, type InsideSelection, type JSONEditorSelection, type KeySelection, type MultiSelection, type ValueSelection, isAfterSelection, isInsideSelection, isKeySelection, isMultiSelection, isValueSelection, stringifyJSONPath } from 'vanilla-jsoneditor';
import 'vanilla-jsoneditor/themes/jse-theme-dark.css';
import { useStyleStore } from '@/stores/style.store';
const styleStore = useStyleStore();
const jsonText = ref('{ "a": { "array": [1, 2, 3] } }');
const jsonPath = ref('');
function updateJsonPath(selection: JSONEditorSelection) {
if (isAfterSelection (selection)) {
jsonPath.value = `$.${stringifyJSONPath((selection as AfterSelection).path)}`;
}
else if (isInsideSelection (selection)) {
jsonPath.value = `$.${stringifyJSONPath((selection as InsideSelection).path)}`;
}
else if (isKeySelection (selection)) {
jsonPath.value = `$.${stringifyJSONPath((selection as KeySelection).path)}`;
}
else if (isValueSelection (selection)) {
jsonPath.value = `$.${stringifyJSONPath((selection as ValueSelection).path)}`;
}
else if (isMultiSelection (selection)) {
jsonPath.value = `$.${stringifyJSONPath((selection as MultiSelection).focusPath)}`;
}
else {
jsonPath.value = 'No available in this mode';
}
}
</script>
<template>
<div>
<JsonEditorVue
v-model="jsonText"
mode="text"
:class="styleStore.isDarkTheme ? 'jse-theme-dark' : ''"
:on-select="updateJsonPath"
mb-2
/>
<n-form-item label="Current Selected Node JSONPath:">
<textarea-copyable :value="jsonPath" />
</n-form-item>
<n-divider />
<n-form-item label="Your edited JSON:">
<textarea-copyable :value="jsonText" language="json" />
</n-form-item>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'JSON to XML',
path: '/json-to-xml',
description: 'Convert JSON to XML',
keywords: ['json', 'xml'],
component: () => import('./json-to-xml.vue'),
icon: Braces,
createdAt: new Date('2024-08-09'),
});
-32
View File
@@ -1,32 +0,0 @@
<script setup lang="ts">
import convert from 'xml-js';
import JSON5 from 'json5';
import { withDefaultOnError } from '@/utils/defaults';
import type { UseValidationRule } from '@/composable/validation';
const defaultValue = '{"a":{"_attributes":{"x":"1.234","y":"It\'s"}}}';
function transformer(value: string) {
return withDefaultOnError(() => {
return convert.js2xml(JSON5.parse(value), { compact: true });
}, '');
}
const rules: UseValidationRule<string>[] = [
{
validator: (v: string) => v === '' || JSON5.parse(v),
message: 'Provided JSON is not valid.',
},
];
</script>
<template>
<format-transformer
input-label="Your JSON content"
:input-default="defaultValue"
input-placeholder="Paste your JSON content here..."
output-label="Converted XML"
output-language="xml"
:transformer="transformer"
:input-validation-rules="rules"
/>
</template>
@@ -2,7 +2,6 @@
import { generateLoremIpsum } from './lorem-ipsum-generator.service';
import { useCopy } from '@/composable/copy';
import { randIntFromInterval } from '@/utils/random';
import { computedRefreshable } from '@/composable/computedRefreshable';
const paragraphs = ref(1);
const sentences = ref([3, 8]);
@@ -10,7 +9,7 @@ const words = ref([8, 15]);
const startWithLoremIpsum = ref(true);
const asHTML = ref(false);
const [loremIpsumText, refreshLoremIpsum] = computedRefreshable(() =>
const loremIpsumText = computed(() =>
generateLoremIpsum({
paragraphCount: paragraphs.value,
asHTML: asHTML.value,
@@ -19,7 +18,6 @@ const [loremIpsumText, refreshLoremIpsum] = computedRefreshable(() =>
startWithLoremIpsum: startWithLoremIpsum.value,
}),
);
const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to the clipboard' });
</script>
@@ -43,13 +41,10 @@ const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to
<c-input-text :value="loremIpsumText" multiline placeholder="Your lorem ipsum..." readonly mt-5 rows="5" />
<div mt-5 flex justify-center gap-3>
<div mt-5 flex justify-center>
<c-button autofocus @click="copy()">
Copy
</c-button>
<c-button @click="refreshLoremIpsum">
Refresh
</c-button>
</div>
</c-card>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { Markdown } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Markdown to HTML',
path: '/markdown-to-html',
description: 'Convert Markdown to Html and allow to print (as PDF)',
keywords: ['markdown', 'html', 'converter', 'pdf'],
component: () => import('./markdown-to-html.vue'),
icon: Markdown,
createdAt: new Date('2024-08-25'),
});
@@ -1,44 +0,0 @@
<script setup lang="ts">
import markdownit from 'markdown-it';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const inputMarkdown = ref('');
const outputHtml = computed(() => {
const md = markdownit();
return md.render(inputMarkdown.value);
});
function printHtml() {
const w = window.open();
if (w === null) {
return;
}
w.document.body.innerHTML = outputHtml.value;
w.print();
}
</script>
<template>
<div>
<c-input-text
v-model:value="inputMarkdown"
multiline raw-text
placeholder="Your Markdown content..."
rows="8"
autofocus
label="Your Markdown to convert:"
/>
<n-divider />
<n-form-item label="Output HTML:">
<TextareaCopyable :value="outputHtml" :word-wrap="true" language="html" />
</n-form-item>
<div flex justify-center>
<n-button @click="printHtml">
Print as PDF
</n-button>
</div>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { BrandJavascript } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Regex cheatsheet',
path: '/regex-memo',
description: 'Javascript Regex/Regular Expression cheatsheet',
keywords: ['regex', 'regular', 'expression', 'javascript', 'memo', 'cheatsheet'],
component: () => import('./regex-memo.vue'),
icon: BrandJavascript,
createdAt: new Date('2024-09-20'),
});
-121
View File
@@ -1,121 +0,0 @@
### Normal characters
Expression | Description
:--|:--
`.` or `[^\n\r]` | any character *excluding* a newline or carriage return
`[A-Za-z]` | alphabet
`[a-z]` | lowercase alphabet
`[A-Z]` | uppercase alphabet
`\d` or `[0-9]` | digit
`\D` or `[^0-9]` | non-digit
`_` | underscore
`\w` or `[A-Za-z0-9_]` | alphabet, digit or underscore
`\W` or `[^A-Za-z0-9_]` | inverse of `\w`
`\S` | inverse of `\s`
### Whitespace characters
Expression | Description
:--|:--
` ` | space
`\t` | tab
`\n` | newline
`\r` | carriage return
`\s` | space, tab, newline or carriage return
### Character set
Expression | Description
:--|:--
`[xyz]` | either `x`, `y` or `z`
`[^xyz]` | neither `x`, `y` nor `z`
`[1-3]` | either `1`, `2` or `3`
`[^1-3]` | neither `1`, `2` nor `3`
- Think of a character set as an `OR` operation on the single characters that are enclosed between the square brackets.
- Use `^` after the opening `[` to “negate” the character set.
- Within a character set, `.` means a literal period.
### Characters that require escaping
#### Outside a character set
Expression | Description
:--|:--
`\.` | period
`\^` | caret
`\$` | dollar sign
`\|` | pipe
`\\` | back slash
`\/` | forward slash
`\(` | opening bracket
`\)` | closing bracket
`\[` | opening square bracket
`\]` | closing square bracket
`\{` | opening curly bracket
`\}` | closing curly bracket
#### Inside a character set
Expression | Description
:--|:--
`\\` | back slash
`\]` | closing square bracket
- A `^` must be escaped only if it occurs immediately after the opening `[` of the character set.
- A `-` must be escaped only if it occurs between two alphabets or two digits.
### Quantifiers
Expression | Description
:--|:--
`{2}` | exactly 2
`{2,}` | at least 2
`{2,7}` | at least 2 but no more than 7
`*` | 0 or more
`+` | 1 or more
`?` | exactly 0 or 1
- The quantifier goes *after* the expression to be quantified.
### Boundaries
Expression | Description
:--|:--
`^` | start of string
`$` | end of string
`\b` | word boundary
- How word boundary matching works:
- At the beginning of the string if the first character is `\w`.
- Between two adjacent characters within the string, if the first character is `\w` and the second character is `\W`.
- At the end of the string if the last character is `\w`.
### Matching
Expression | Description
:--|:--
`foo\|bar` | match either `foo` or `bar`
`foo(?=bar)` | match `foo` if it’s before `bar`
`foo(?!bar)` | match `foo` if it’s *not* before `bar`
`(?<=bar)foo` | match `foo` if it’s after `bar`
`(?<!bar)foo` | match `foo` if it’s *not* after `bar`
### Grouping and capturing
Expression | Description
:--|:--
`(foo)` | capturing group; match and capture `foo`
`(?:foo)` | non-capturing group; match `foo` but *without* capturing `foo`
`(foo)bar\1` | `\1` is a backreference to the 1st capturing group; match `foobarfoo`
- Capturing groups are only relevant in the following methods:
- `string.match(regexp)`
- `string.matchAll(regexp)`
- `string.replace(regexp, callback)`
- `\N` is a backreference to the `Nth` capturing group. Capturing groups are numbered starting from 1.
## References and tools
- [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
- [RegExplained](https://leaverou.github.io/regexplained/)
-32
View File
@@ -1,32 +0,0 @@
<script setup lang="ts">
import { useThemeVars } from 'naive-ui';
import Memo from './regex-memo.content.md';
const themeVars = useThemeVars();
</script>
<template>
<div>
<Memo />
</div>
</template>
<style lang="less" scoped>
::v-deep(pre) {
margin: 0;
padding: 15px 22px;
background-color: v-bind('themeVars.cardColor');
border-radius: 4px;
overflow: auto;
}
::v-deep(table) {
border-collapse: collapse;
}
::v-deep(table), ::v-deep(td), ::v-deep(th) {
border: 1px solid v-bind('themeVars.textColor1');
padding: 5px;
}
::v-deep(a) {
color: v-bind('themeVars.textColor1');
}
</style>
-12
View File
@@ -1,12 +0,0 @@
import { Language } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Regex Tester',
path: '/regex-tester',
description: 'Regex Tester',
keywords: ['regex', 'tester', 'sample', 'expression'],
component: () => import('./regex-tester.vue'),
icon: Language,
createdAt: new Date('2024-09-20'),
});
@@ -1,106 +0,0 @@
import { describe, expect, it } from 'vitest';
import { matchRegex } from './regex-tester.service';
const regexesData = [
{
regex: '',
text: '',
flags: '',
result: [],
},
{
regex: '.*',
text: '',
flags: '',
result: [],
},
{
regex: '',
text: 'aaa',
flags: '',
result: [],
},
{
regex: 'a',
text: 'baaa',
flags: '',
result: [
{
captures: [],
groups: [],
index: 1,
value: 'a',
},
],
},
{
regex: '(.)(?<g>r)',
text: 'azertyr',
flags: 'g',
result: [
{
captures: [
{
end: 3,
name: '1',
start: 2,
value: 'e',
},
{
end: 4,
name: '2',
start: 3,
value: 'r',
},
],
groups: [
{
end: 4,
name: 'g',
start: 3,
value: 'r',
},
],
index: 2,
value: 'er',
},
{
captures: [
{
end: 6,
name: '1',
start: 5,
value: 'y',
},
{
end: 7,
name: '2',
start: 6,
value: 'r',
},
],
groups: [
{
end: 7,
name: 'g',
start: 6,
value: 'r',
},
],
index: 5,
value: 'yr',
},
],
},
];
describe('regex-tester', () => {
for (const reg of regexesData) {
const { regex, text, flags, result: expected_result } = reg;
it(`Should matchRegex("${regex}","${text}","${flags}") return correct result`, async () => {
const result = matchRegex(regex, text, `${flags}d`);
expect(result).to.deep.equal(expected_result);
});
}
});
@@ -1,61 +0,0 @@
interface RegExpGroupIndices {
[name: string]: [number, number]
}
interface RegExpIndices extends Array<[number, number]> {
groups: RegExpGroupIndices
}
interface RegExpExecArrayWithIndices extends RegExpExecArray {
indices: RegExpIndices
}
interface GroupCapture {
name: string
value: string
start: number
end: number
};
export function matchRegex(regex: string, text: string, flags: string) {
// if (regex === '' || text === '') {
// return [];
// }
let lastIndex = -1;
const re = new RegExp(regex, flags);
const results = [];
let match = re.exec(text) as RegExpExecArrayWithIndices;
while (match !== null) {
if (re.lastIndex === lastIndex || match[0] === '') {
break;
}
const indices = match.indices;
const captures: Array<GroupCapture> = [];
Object.entries(match).forEach(([captureName, captureValue]) => {
if (captureName !== '0' && captureName.match(/\d+/)) {
captures.push({
name: captureName,
value: captureValue,
start: indices[Number(captureName)][0],
end: indices[Number(captureName)][1],
});
}
});
const groups: Array<GroupCapture> = [];
Object.entries(match.groups || {}).forEach(([groupName, groupValue]) => {
groups.push({
name: groupName,
value: groupValue,
start: indices.groups[groupName][0],
end: indices.groups[groupName][1],
});
});
results.push({
index: match.index,
value: match[0],
captures,
groups,
});
lastIndex = re.lastIndex;
match = re.exec(text) as RegExpExecArrayWithIndices;
}
return results;
}
-193
View File
@@ -1,193 +0,0 @@
<script setup lang="ts">
import RandExp from 'randexp';
import { render } from '@regexper/render';
import type { ShadowRootExpose } from 'vue-shadow-dom';
import { matchRegex } from './regex-tester.service';
import { useValidation } from '@/composable/validation';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const regex = useQueryParamOrStorage({ name: 'regex', storageName: 'regex-tester:regex', defaultValue: '' });
const text = ref('');
const global = ref(true);
const ignoreCase = ref(false);
const multiline = ref(false);
const dotAll = ref(true);
const unicode = ref(true);
const unicodeSets = ref(false);
const visualizerSVG = ref<ShadowRootExpose>();
const regexValidation = useValidation({
source: regex,
rules: [
{
message: 'Invalid regex: {0}',
validator: value => new RegExp(value),
getErrorMessage: (value) => {
const _ = new RegExp(value);
return '';
},
},
],
});
const results = computed(() => {
let flags = 'd';
if (global.value) {
flags += 'g';
}
if (ignoreCase.value) {
flags += 'i';
}
if (multiline.value) {
flags += 'm';
}
if (dotAll.value) {
flags += 's';
}
if (unicode.value) {
flags += 'u';
}
else if (unicodeSets.value) {
flags += 'v';
}
try {
return matchRegex(regex.value, text.value, flags);
}
catch (_) {
return [];
}
});
const sample = computed(() => {
try {
const randexp = new RandExp(new RegExp(regex.value.replace(/\(\?\<[^\>]*\>/g, '(?:')));
return randexp.gen();
}
catch (_) {
return '';
}
});
watchEffect(
async () => {
const regexValue = regex.value;
// shadow root is required:
// @regexper/render append a <defs><style> that broke svg transparency of icons in the whole site
const visualizer = visualizerSVG.value?.shadow_root;
if (visualizer) {
while (visualizer.lastChild) {
visualizer.removeChild(visualizer.lastChild);
}
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
try {
await render(regexValue, svg);
}
catch (_) {
}
visualizer.appendChild(svg);
}
},
);
</script>
<template>
<div max-w-600px>
<c-card title="Regex" mb-1>
<c-input-text
v-model:value="regex"
label="Regex to test:"
placeholder="Put the regex to test"
multiline
rows="3"
:validation="regexValidation"
/>
<router-link target="_blank" to="/regex-memo" mb-1 mt-1>
See Regular Expression Cheatsheet
</router-link>
<n-space>
<n-checkbox v-model:checked="global">
<span title="Global search">Global search. (<code>g</code>)</span>
</n-checkbox>
<n-checkbox v-model:checked="ignoreCase">
<span title="Case-insensitive search">Case-insensitive search. (<code>i</code>)</span>
</n-checkbox>
<n-checkbox v-model:checked="multiline">
<span title="Allows ^ and $ to match next to newline characters.">Multiline(<code>m</code>)</span>
</n-checkbox>
<n-checkbox v-model:checked="dotAll">
<span title="Allows . to match newline characters.">Singleline(<code>s</code>)</span>
</n-checkbox>
<n-checkbox v-model:checked="unicode">
<span title="Unicode; treat a pattern as a sequence of Unicode code points.">Unicode(<code>u</code>)</span>
</n-checkbox>
<n-checkbox v-model:checked="unicodeSets">
<span title="An upgrade to the u mode with more Unicode features.">Unicode Sets (<code>v</code>)</span>
</n-checkbox>
</n-space>
<n-divider />
<c-input-text
v-model:value="text"
label="Text to match:"
placeholder="Put the text to match"
multiline
rows="5"
/>
</c-card>
<c-card title="Matches" mb-1 mt-3>
<n-table v-if="results?.length > 0">
<thead>
<tr>
<th scope="col">
Index in text
</th>
<th scope="col">
Value
</th>
<th scope="col">
Captures
</th>
<th scope="col">
Groups
</th>
</tr>
</thead>
<tbody>
<tr v-for="match of results" :key="match.index">
<td>{{ match.index }}</td>
<td>{{ match.value }}</td>
<td>
<ul>
<li v-for="capture in match.captures" :key="capture.name">
"{{ capture.name }}" = {{ capture.value }} [{{ capture.start }} - {{ capture.end }}]
</li>
</ul>
</td>
<td>
<ul>
<li v-for="group in match.groups" :key="group.name">
"{{ group.name }}" = {{ group.value }} [{{ group.start }} - {{ group.end }}]
</li>
</ul>
</td>
</tr>
</tbody>
</n-table>
<c-alert v-else>
No match
</c-alert>
</c-card>
<c-card title="Sample matching text" mt-3>
<pre style="white-space: pre-wrap; word-break: break-all;">{{ sample }}</pre>
</c-card>
<c-card title="Regex Diagram" style="overflow-x: scroll;" mt-3>
<shadow-root ref="visualizerSVG">
&#xa0;
</shadow-root>
</c-card>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'XML to JSON',
path: '/xml-to-json',
description: 'Convert XML to JSON',
keywords: ['xml', 'json'],
component: () => import('./xml-to-json.vue'),
icon: Braces,
createdAt: new Date('2024-08-09'),
});
-32
View File
@@ -1,32 +0,0 @@
<script setup lang="ts">
import convert from 'xml-js';
import { isValidXML } from '../xml-formatter/xml-formatter.service';
import { withDefaultOnError } from '@/utils/defaults';
import type { UseValidationRule } from '@/composable/validation';
const defaultValue = '<a x="1.234" y="It\'s"/>';
function transformer(value: string) {
return withDefaultOnError(() => {
return JSON.stringify(convert.xml2js(value, { compact: true }), null, 2);
}, '');
}
const rules: UseValidationRule<string>[] = [
{
validator: isValidXML,
message: 'Provided XML is not valid.',
},
];
</script>
<template>
<format-transformer
input-label="Your XML content"
:input-default="defaultValue"
input-placeholder="Paste your XML content here..."
output-label="Converted JSON"
output-language="json"
:transformer="transformer"
:input-validation-rules="rules"
/>
</template>