mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 23:00:19 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebfae5e81c |
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 |
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
@@ -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>
|
|
||||||
|
|
||||||
Useful tools for developer and people working in IT. [Have a look !](https://it-tools.tech).
|
Useful tools for developer and people working in IT. [Have a look !](https://it-tools.tech).
|
||||||
|
|
||||||
|
|||||||
Vendored
+4
-11
@@ -72,7 +72,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']
|
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']
|
DynamicValues: typeof import('./src/tools/benchmark-builder/dynamic-values.vue')['default']
|
||||||
Editor: typeof import('./src/tools/html-wysiwyg-editor/editor/editor.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']
|
EmojiCard: typeof import('./src/tools/emoji-picker/emoji-card.vue')['default']
|
||||||
EmojiGrid: typeof import('./src/tools/emoji-picker/emoji-grid.vue')['default']
|
EmojiGrid: typeof import('./src/tools/emoji-picker/emoji-grid.vue')['default']
|
||||||
EmojiPicker: typeof import('./src/tools/emoji-picker/emoji-picker.vue')['default']
|
EmojiPicker: typeof import('./src/tools/emoji-picker/emoji-picker.vue')['default']
|
||||||
@@ -110,8 +109,8 @@ declare module '@vue/runtime-core' {
|
|||||||
JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default']
|
JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default']
|
||||||
JsonMinify: typeof import('./src/tools/json-minify/json-minify.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']
|
JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default']
|
||||||
|
JsonToPhpArray: typeof import('./src/tools/json-to-php-array/json-to-php-array.vue')['default']
|
||||||
JsonToToml: typeof import('./src/tools/json-to-toml/json-to-toml.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']
|
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']
|
JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default']
|
||||||
JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default']
|
JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default']
|
||||||
@@ -121,7 +120,6 @@ declare module '@vue/runtime-core' {
|
|||||||
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
|
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']
|
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']
|
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']
|
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']
|
||||||
MenuBar: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar.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']
|
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
|
||||||
@@ -130,10 +128,9 @@ declare module '@vue/runtime-core' {
|
|||||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
NCode: typeof import('naive-ui')['NCode']
|
||||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
NH1: typeof import('naive-ui')['NH1']
|
NH1: typeof import('naive-ui')['NH1']
|
||||||
NH3: typeof import('naive-ui')['NH3']
|
NH3: typeof import('naive-ui')['NH3']
|
||||||
@@ -141,8 +138,7 @@ declare module '@vue/runtime-core' {
|
|||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NSpace: typeof import('naive-ui')['NSpace']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
NTable: typeof import('naive-ui')['NTable']
|
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
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']
|
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']
|
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||||
@@ -150,11 +146,9 @@ declare module '@vue/runtime-core' {
|
|||||||
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
||||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||||
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
||||||
|
PhpArrayToJson: typeof import('./src/tools/php-array-to-json/php-array-to-json.vue')['default']
|
||||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.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']
|
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']
|
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']
|
RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
@@ -187,7 +181,6 @@ declare module '@vue/runtime-core' {
|
|||||||
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
|
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']
|
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']
|
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']
|
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']
|
YamlToToml: typeof import('./src/tools/yaml-to-toml/yaml-to-toml.vue')['default']
|
||||||
YamlViewer: typeof import('./src/tools/yaml-viewer/yaml-viewer.vue')['default']
|
YamlViewer: typeof import('./src/tools/yaml-viewer/yaml-viewer.vue')['default']
|
||||||
|
|||||||
+3
-11
@@ -37,13 +37,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@it-tools/bip39": "^0.0.4",
|
"@it-tools/bip39": "^0.0.4",
|
||||||
"@it-tools/oggen": "^1.3.0",
|
"@it-tools/oggen": "^1.3.0",
|
||||||
"@regexper/render": "^1.0.0",
|
|
||||||
"@sindresorhus/slugify": "^2.2.1",
|
"@sindresorhus/slugify": "^2.2.1",
|
||||||
"@tiptap/pm": "2.1.6",
|
"@tiptap/pm": "2.1.6",
|
||||||
"@tiptap/starter-kit": "2.1.6",
|
"@tiptap/starter-kit": "2.1.6",
|
||||||
"@tiptap/vue-3": "2.0.3",
|
"@tiptap/vue-3": "2.0.3",
|
||||||
"@types/figlet": "^1.5.8",
|
"@types/figlet": "^1.5.8",
|
||||||
"@types/markdown-it": "^13.0.7",
|
|
||||||
"@vicons/material": "^0.12.0",
|
"@vicons/material": "^0.12.0",
|
||||||
"@vicons/tabler": "^0.12.0",
|
"@vicons/tabler": "^0.12.0",
|
||||||
"@vueuse/core": "^10.3.0",
|
"@vueuse/core": "^10.3.0",
|
||||||
@@ -59,7 +57,6 @@
|
|||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"date-fns": "^2.29.3",
|
"date-fns": "^2.29.3",
|
||||||
"dompurify": "^3.0.6",
|
"dompurify": "^3.0.6",
|
||||||
"email-normalizer": "^1.0.0",
|
|
||||||
"emojilib": "^3.0.10",
|
"emojilib": "^3.0.10",
|
||||||
"figlet": "^1.7.0",
|
"figlet": "^1.7.0",
|
||||||
"figue": "^1.2.0",
|
"figue": "^1.2.0",
|
||||||
@@ -67,13 +64,11 @@
|
|||||||
"highlight.js": "^11.7.0",
|
"highlight.js": "^11.7.0",
|
||||||
"iarna-toml-esm": "^3.0.5",
|
"iarna-toml-esm": "^3.0.5",
|
||||||
"ibantools": "^4.3.3",
|
"ibantools": "^4.3.3",
|
||||||
"js-base64": "^3.7.6",
|
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
|
"jsonar-mod": "^1.9.0",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"korean-unpacker": "^1.0.3",
|
|
||||||
"libphonenumber-js": "^1.10.28",
|
"libphonenumber-js": "^1.10.28",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"markdown-it": "^14.0.0",
|
|
||||||
"marked": "^10.0.0",
|
"marked": "^10.0.0",
|
||||||
"mathjs": "^11.9.1",
|
"mathjs": "^11.9.1",
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
@@ -86,20 +81,18 @@
|
|||||||
"pinia": "^2.0.34",
|
"pinia": "^2.0.34",
|
||||||
"plausible-tracker": "^0.3.8",
|
"plausible-tracker": "^0.3.8",
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"randexp": "^0.5.3",
|
|
||||||
"sql-formatter": "^13.0.0",
|
"sql-formatter": "^13.0.0",
|
||||||
"ua-parser-js": "^1.0.35",
|
"ua-parser-js": "^1.0.35",
|
||||||
"ulid": "^2.3.0",
|
"ulid": "^2.3.0",
|
||||||
"unicode-emoji-json": "^0.4.0",
|
"unicode-emoji-json": "^0.4.0",
|
||||||
"unplugin-auto-import": "^0.16.4",
|
"unplugin-auto-import": "^0.16.4",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^9.0.0",
|
||||||
|
"vite-plugin-node-polyfills": "^0.21.0",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.3.4",
|
||||||
"vue-i18n": "^9.9.1",
|
"vue-i18n": "^9.9.1",
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
"vue-shadow-dom": "^4.2.0",
|
|
||||||
"vue-tsc": "^1.8.1",
|
"vue-tsc": "^1.8.1",
|
||||||
"xml-formatter": "^3.3.2",
|
"xml-formatter": "^3.3.2",
|
||||||
"xml-js": "^1.6.11",
|
|
||||||
"yaml": "^2.2.1"
|
"yaml": "^2.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -146,6 +139,5 @@
|
|||||||
"vitest": "^0.34.0",
|
"vitest": "^0.34.0",
|
||||||
"workbox-window": "^7.0.0",
|
"workbox-window": "^7.0.0",
|
||||||
"zx": "^7.2.1"
|
"zx": "^7.2.1"
|
||||||
},
|
}
|
||||||
"packageManager": "pnpm@8.15.3"
|
|
||||||
}
|
}
|
||||||
Generated
+662
-213
File diff suppressed because it is too large.
Load diff
@@ -48,7 +48,7 @@ const output = computed(() => transformer.value(input.value));
|
|||||||
monospace
|
monospace
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div overflow-auto>
|
<div>
|
||||||
<div mb-5px>
|
<div mb-5px>
|
||||||
{{ outputLabel }}
|
{{ outputLabel }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import sqlHljs from 'highlight.js/lib/languages/sql';
|
|||||||
import xmlHljs from 'highlight.js/lib/languages/xml';
|
import xmlHljs from 'highlight.js/lib/languages/xml';
|
||||||
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
||||||
import iniHljs from 'highlight.js/lib/languages/ini';
|
import iniHljs from 'highlight.js/lib/languages/ini';
|
||||||
import markdownHljs from 'highlight.js/lib/languages/markdown';
|
|
||||||
import { useCopy } from '@/composable/copy';
|
import { useCopy } from '@/composable/copy';
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
@@ -31,7 +30,6 @@ hljs.registerLanguage('html', xmlHljs);
|
|||||||
hljs.registerLanguage('xml', xmlHljs);
|
hljs.registerLanguage('xml', xmlHljs);
|
||||||
hljs.registerLanguage('yaml', yamlHljs);
|
hljs.registerLanguage('yaml', yamlHljs);
|
||||||
hljs.registerLanguage('toml', iniHljs);
|
hljs.registerLanguage('toml', iniHljs);
|
||||||
hljs.registerLanguage('markdown', markdownHljs);
|
|
||||||
|
|
||||||
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
|
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
|
||||||
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
|
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) {
|
|
||||||
const state = ref(initialValue);
|
|
||||||
const debouncedRef = customRef((track, trigger) => ({
|
|
||||||
get() {
|
|
||||||
track();
|
|
||||||
return state.value;
|
|
||||||
},
|
|
||||||
set: _.debounce(
|
|
||||||
(value) => {
|
|
||||||
state.value = value;
|
|
||||||
trigger();
|
|
||||||
},
|
|
||||||
delay,
|
|
||||||
{ leading: immediate },
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
return debouncedRef;
|
|
||||||
}
|
|
||||||
export default useDebouncedRef;
|
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
import { extension as getExtensionFromMime } from 'mime-types';
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
export {
|
export { getMimeTypeFromBase64, useDownloadFileFromBase64 };
|
||||||
getMimeTypeFromBase64,
|
|
||||||
getMimeTypeFromExtension, getExtensionFromMimeType,
|
|
||||||
useDownloadFileFromBase64, useDownloadFileFromBase64Refs,
|
|
||||||
previewImageFromBase64,
|
|
||||||
};
|
|
||||||
|
|
||||||
const commonMimeTypesSignatures = {
|
const commonMimeTypesSignatures = {
|
||||||
'JVBERi0': 'application/pdf',
|
'JVBERi0': 'application/pdf',
|
||||||
@@ -41,78 +36,30 @@ function getFileExtensionFromMimeType({
|
|||||||
defaultExtension?: string
|
defaultExtension?: string
|
||||||
}) {
|
}) {
|
||||||
if (mimeType) {
|
if (mimeType) {
|
||||||
return getExtensionFromMimeType(mimeType) ?? defaultExtension;
|
return getExtensionFromMime(mimeType) ?? defaultExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultExtension;
|
return defaultExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
function useDownloadFileFromBase64({ source, filename }: { source: Ref<string>; filename?: string }) {
|
||||||
{ sourceValue: string; filename?: string; extension?: string; fileMimeType?: string }) {
|
|
||||||
if (sourceValue === '') {
|
|
||||||
throw new Error('Base64 string is empty');
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultExtension = extension ?? 'txt';
|
|
||||||
const { mimeType } = getMimeTypeFromBase64({ base64String: sourceValue });
|
|
||||||
let base64String = sourceValue;
|
|
||||||
if (!mimeType) {
|
|
||||||
const targetMimeType = fileMimeType ?? getMimeTypeFromExtension(defaultExtension);
|
|
||||||
base64String = `data:${targetMimeType};base64,${sourceValue}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cleanExtension = extension ?? getFileExtensionFromMimeType(
|
|
||||||
{ mimeType, defaultExtension });
|
|
||||||
let cleanFileName = filename ?? `file.${cleanExtension}`;
|
|
||||||
if (extension && !cleanFileName.endsWith(`.${extension}`)) {
|
|
||||||
cleanFileName = `${cleanFileName}.${cleanExtension}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = base64String;
|
|
||||||
a.download = cleanFileName;
|
|
||||||
a.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
function useDownloadFileFromBase64(
|
|
||||||
{ source, filename, extension, fileMimeType }:
|
|
||||||
{ source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) {
|
|
||||||
return {
|
return {
|
||||||
download() {
|
download() {
|
||||||
downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType });
|
if (source.value === '') {
|
||||||
|
throw new Error('Base64 string is empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { mimeType } = getMimeTypeFromBase64({ base64String: source.value });
|
||||||
|
const base64String = mimeType
|
||||||
|
? source.value
|
||||||
|
: `data:text/plain;base64,${source.value}`;
|
||||||
|
|
||||||
|
const cleanFileName = filename ?? `file.${getFileExtensionFromMimeType({ mimeType })}`;
|
||||||
|
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = base64String;
|
||||||
|
a.download = cleanFileName;
|
||||||
|
a.click();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function useDownloadFileFromBase64Refs(
|
|
||||||
{ source, filename, extension }:
|
|
||||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
|
||||||
return {
|
|
||||||
download() {
|
|
||||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function previewImageFromBase64(base64String: string): HTMLImageElement {
|
|
||||||
if (base64String === '') {
|
|
||||||
throw new Error('Base64 string is empty');
|
|
||||||
}
|
|
||||||
|
|
||||||
const img = document.createElement('img');
|
|
||||||
img.src = base64String;
|
|
||||||
|
|
||||||
const container = document.createElement('div');
|
|
||||||
container.appendChild(img);
|
|
||||||
|
|
||||||
const previewContainer = document.getElementById('previewContainer');
|
|
||||||
if (previewContainer) {
|
|
||||||
previewContainer.innerHTML = '';
|
|
||||||
previewContainer.appendChild(container);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('Preview container element not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
import { useRouteQuery } from '@vueuse/router';
|
import { useRouteQuery } from '@vueuse/router';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { useStorage } from '@vueuse/core';
|
|
||||||
|
|
||||||
export { useQueryParam, useQueryParamOrStorage };
|
export { useQueryParam };
|
||||||
|
|
||||||
const transformers = {
|
const transformers = {
|
||||||
number: {
|
number: {
|
||||||
@@ -17,12 +16,6 @@ const transformers = {
|
|||||||
fromQuery: (value: string) => value.toLowerCase() === 'true',
|
fromQuery: (value: string) => value.toLowerCase() === 'true',
|
||||||
toQuery: (value: boolean) => (value ? 'true' : 'false'),
|
toQuery: (value: boolean) => (value ? 'true' : 'false'),
|
||||||
},
|
},
|
||||||
object: {
|
|
||||||
fromQuery: (value: string) => {
|
|
||||||
return JSON.parse(value);
|
|
||||||
},
|
|
||||||
toQuery: (value: object) => JSON.stringify(value),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
|
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
|
||||||
@@ -40,27 +33,3 @@ function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue:
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function useQueryParamOrStorage<T>({ name, storageName, defaultValue }: { name: string; storageName: string; defaultValue: T }) {
|
|
||||||
const type = typeof defaultValue;
|
|
||||||
const transformer = transformers[type as keyof typeof transformers] ?? transformers.string;
|
|
||||||
|
|
||||||
const storageRef = useStorage(storageName, defaultValue);
|
|
||||||
const proxyDefaultValue = transformer.toQuery(defaultValue as never);
|
|
||||||
const proxy = useRouteQuery(name, proxyDefaultValue);
|
|
||||||
|
|
||||||
const r = ref(defaultValue);
|
|
||||||
|
|
||||||
watch(r,
|
|
||||||
(value) => {
|
|
||||||
proxy.value = transformer.toQuery(value as never);
|
|
||||||
storageRef.value = value as never;
|
|
||||||
},
|
|
||||||
{ deep: true });
|
|
||||||
|
|
||||||
r.value = (proxy.value && proxy.value !== proxyDefaultValue
|
|
||||||
? transformer.fromQuery(proxy.value) as unknown as T
|
|
||||||
: storageRef.value as T) as never;
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
@@ -3,11 +3,9 @@ import _ from 'lodash';
|
|||||||
import { type Ref, reactive, watch } from 'vue';
|
import { type Ref, reactive, watch } from 'vue';
|
||||||
|
|
||||||
type ValidatorReturnType = unknown;
|
type ValidatorReturnType = unknown;
|
||||||
type GetErrorMessageReturnType = string;
|
|
||||||
|
|
||||||
export interface UseValidationRule<T> {
|
export interface UseValidationRule<T> {
|
||||||
validator: (value: T) => ValidatorReturnType
|
validator: (value: T) => ValidatorReturnType
|
||||||
getErrorMessage?: (value: T) => GetErrorMessageReturnType
|
|
||||||
message: string
|
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 {
|
export interface ValidationAttrs {
|
||||||
feedback: string
|
feedback: string
|
||||||
validationStatus: string | undefined
|
validationStatus: string | undefined
|
||||||
@@ -72,13 +61,7 @@ export function useValidation<T>({
|
|||||||
|
|
||||||
for (const rule of get(rules)) {
|
for (const rule of get(rules)) {
|
||||||
if (isFalsyOrHasThrown(() => rule.validator(source.value))) {
|
if (isFalsyOrHasThrown(() => rule.validator(source.value))) {
|
||||||
if (rule.getErrorMessage) {
|
state.message = rule.message;
|
||||||
const getErrorMessage = rule.getErrorMessage;
|
|
||||||
state.message = rule.message.replace('{0}', getErrorMessageOrThrown(() => getErrorMessage(source.value)));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
state.message = rule.message;
|
|
||||||
}
|
|
||||||
state.status = 'error';
|
state.status = 'error';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { createPinia } from 'pinia';
|
|||||||
import { createHead } from '@vueuse/head';
|
import { createHead } from '@vueuse/head';
|
||||||
|
|
||||||
import { registerSW } from 'virtual:pwa-register';
|
import { registerSW } from 'virtual:pwa-register';
|
||||||
import shadow from 'vue-shadow-dom';
|
|
||||||
import { plausible } from './plugins/plausible.plugin';
|
import { plausible } from './plugins/plausible.plugin';
|
||||||
|
|
||||||
import 'virtual:uno.css';
|
import 'virtual:uno.css';
|
||||||
@@ -24,6 +23,5 @@ app.use(i18nPlugin);
|
|||||||
app.use(router);
|
app.use(router);
|
||||||
app.use(naive);
|
app.use(naive);
|
||||||
app.use(plausible);
|
app.use(plausible);
|
||||||
app.use(shadow);
|
|
||||||
|
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
@@ -2,19 +2,12 @@
|
|||||||
import { useBase64 } from '@vueuse/core';
|
import { useBase64 } from '@vueuse/core';
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import { useCopy } from '@/composable/copy';
|
import { useCopy } from '@/composable/copy';
|
||||||
import { getExtensionFromMimeType, getMimeTypeFromBase64, previewImageFromBase64, useDownloadFileFromBase64Refs } from '@/composable/downloadBase64';
|
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||||
import { useValidation } from '@/composable/validation';
|
import { useValidation } from '@/composable/validation';
|
||||||
import { isValidBase64 } from '@/utils/base64';
|
import { isValidBase64 } from '@/utils/base64';
|
||||||
|
|
||||||
const fileName = ref('file');
|
|
||||||
const fileExtension = ref('');
|
|
||||||
const base64Input = ref('');
|
const base64Input = ref('');
|
||||||
const { download } = useDownloadFileFromBase64Refs(
|
const { download } = useDownloadFileFromBase64({ source: base64Input });
|
||||||
{
|
|
||||||
source: base64Input,
|
|
||||||
filename: fileName,
|
|
||||||
extension: fileExtension,
|
|
||||||
});
|
|
||||||
const base64InputValidation = useValidation({
|
const base64InputValidation = useValidation({
|
||||||
source: base64Input,
|
source: base64Input,
|
||||||
rules: [
|
rules: [
|
||||||
@@ -25,35 +18,6 @@ const base64InputValidation = useValidation({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
|
||||||
base64Input,
|
|
||||||
(newValue, _) => {
|
|
||||||
const { mimeType } = getMimeTypeFromBase64({ base64String: newValue });
|
|
||||||
if (mimeType) {
|
|
||||||
fileExtension.value = getExtensionFromMimeType(mimeType) || fileExtension.value;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
function previewImage() {
|
|
||||||
if (!base64InputValidation.isValid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const image = previewImageFromBase64(base64Input.value);
|
|
||||||
image.style.maxWidth = '100%';
|
|
||||||
image.style.maxHeight = '400px';
|
|
||||||
const previewContainer = document.getElementById('previewContainer');
|
|
||||||
if (previewContainer) {
|
|
||||||
previewContainer.innerHTML = '';
|
|
||||||
previewContainer.appendChild(image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (_) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function downloadFile() {
|
function downloadFile() {
|
||||||
if (!base64InputValidation.isValid) {
|
if (!base64InputValidation.isValid) {
|
||||||
return;
|
return;
|
||||||
@@ -80,24 +44,6 @@ async function onUpload(file: File) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<c-card title="Base64 to file">
|
<c-card title="Base64 to file">
|
||||||
<n-grid cols="3" x-gap="12">
|
|
||||||
<n-gi span="2">
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="fileName"
|
|
||||||
label="File Name"
|
|
||||||
placeholder="Download filename"
|
|
||||||
mb-2
|
|
||||||
/>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="fileExtension"
|
|
||||||
label="Extension"
|
|
||||||
placeholder="Extension"
|
|
||||||
mb-2
|
|
||||||
/>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="base64Input"
|
v-model:value="base64Input"
|
||||||
multiline
|
multiline
|
||||||
@@ -107,14 +53,7 @@ async function onUpload(file: File) {
|
|||||||
mb-2
|
mb-2
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div flex justify-center py-2>
|
<div flex justify-center>
|
||||||
<div id="previewContainer" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div flex justify-center gap-3>
|
|
||||||
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="previewImage()">
|
|
||||||
Preview image
|
|
||||||
</c-button>
|
|
||||||
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="downloadFile()">
|
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="downloadFile()">
|
||||||
Download file
|
Download file
|
||||||
</c-button>
|
</c-button>
|
||||||
|
|||||||
@@ -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>
|
|
||||||
@@ -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'),
|
|
||||||
});
|
|
||||||
@@ -4,7 +4,6 @@ import emojiKeywords from 'emojilib';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import type { EmojiInfo } from './emoji.types';
|
import type { EmojiInfo } from './emoji.types';
|
||||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
||||||
import useDebouncedRef from '@/composable/debouncedref';
|
|
||||||
|
|
||||||
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join('');
|
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join('');
|
||||||
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined;
|
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined;
|
||||||
@@ -24,7 +23,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
|
|||||||
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
const searchQuery = useDebouncedRef('', 500);
|
const searchQuery = ref('');
|
||||||
|
|
||||||
const { searchResult } = useFuzzySearch({
|
const { searchResult } = useFuzzySearch({
|
||||||
search: searchQuery,
|
search: searchQuery,
|
||||||
|
|||||||
+4
-12
@@ -1,17 +1,13 @@
|
|||||||
import { tool as base64FileConverter } from './base64-file-converter';
|
import { tool as base64FileConverter } from './base64-file-converter';
|
||||||
import { tool as base64StringConverter } from './base64-string-converter';
|
import { tool as base64StringConverter } from './base64-string-converter';
|
||||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||||
import { tool as emailNormalizer } from './email-normalizer';
|
import { tool as jsonToPhpArray } from './json-to-php-array';
|
||||||
|
import { tool as phpArrayToJson } from './php-array-to-json';
|
||||||
|
|
||||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||||
|
|
||||||
import { tool as textToUnicode } from './text-to-unicode';
|
import { tool as textToUnicode } from './text-to-unicode';
|
||||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
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 pdfSignatureChecker } from './pdf-signature-checker';
|
||||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||||
@@ -113,9 +109,6 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
listConverter,
|
listConverter,
|
||||||
tomlToJson,
|
tomlToJson,
|
||||||
tomlToYaml,
|
tomlToYaml,
|
||||||
xmlToJson,
|
|
||||||
jsonToXml,
|
|
||||||
markdownToHtml,
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -137,6 +130,8 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
httpStatusCodes,
|
httpStatusCodes,
|
||||||
jsonDiff,
|
jsonDiff,
|
||||||
safelinkDecoder,
|
safelinkDecoder,
|
||||||
|
jsonToPhpArray,
|
||||||
|
phpArrayToJson,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -157,9 +152,6 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
dockerRunToDockerComposeConverter,
|
dockerRunToDockerComposeConverter,
|
||||||
xmlFormatter,
|
xmlFormatter,
|
||||||
yamlViewer,
|
yamlViewer,
|
||||||
emailNormalizer,
|
|
||||||
regexTester,
|
|
||||||
regexMemo,
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { BrandPhp } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Json to PHP-Array',
|
||||||
|
path: '/json-to-php-array',
|
||||||
|
description: 'Convert JSON to PHP Array',
|
||||||
|
keywords: ['json', 'php', 'array'],
|
||||||
|
component: () => import('./json-to-php-array.vue'),
|
||||||
|
icon: BrandPhp,
|
||||||
|
createdAt: new Date('2024-05-11'),
|
||||||
|
});
|
||||||
+16
-12
@@ -1,19 +1,24 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import convert from 'xml-js';
|
import jsonar from 'jsonar-mod';
|
||||||
import JSON5 from 'json5';
|
import JSON5 from 'json5';
|
||||||
import { withDefaultOnError } from '@/utils/defaults';
|
|
||||||
import type { UseValidationRule } from '@/composable/validation';
|
import type { UseValidationRule } from '@/composable/validation';
|
||||||
|
import { withDefaultOnError } from '@/utils/defaults';
|
||||||
|
|
||||||
const defaultValue = '{"a":{"_attributes":{"x":"1.234","y":"It\'s"}}}';
|
const defaultValue = `{
|
||||||
|
a:"b",
|
||||||
|
arr: [1, "2"],
|
||||||
|
nested: {
|
||||||
|
c:12,
|
||||||
|
d: "az"
|
||||||
|
}
|
||||||
|
}`;
|
||||||
function transformer(value: string) {
|
function transformer(value: string) {
|
||||||
return withDefaultOnError(() => {
|
return withDefaultOnError(() => jsonar.arrify(JSON5.parse(value), { prettify: true }), '');
|
||||||
return convert.js2xml(JSON5.parse(value), { compact: true });
|
|
||||||
}, '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const rules: UseValidationRule<string>[] = [
|
const rules: UseValidationRule<string>[] = [
|
||||||
{
|
{
|
||||||
validator: (v: string) => v === '' || JSON5.parse(v),
|
validator: (v: string) => JSON5.parse(v),
|
||||||
message: 'Provided JSON is not valid.',
|
message: 'Provided JSON is not valid.',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -21,12 +26,11 @@ const rules: UseValidationRule<string>[] = [
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<format-transformer
|
<format-transformer
|
||||||
input-label="Your JSON content"
|
input-label="Your JSON"
|
||||||
:input-default="defaultValue"
|
:input-default="defaultValue"
|
||||||
input-placeholder="Paste your JSON content here..."
|
input-placeholder="Paste your JSON here..."
|
||||||
output-label="Converted XML"
|
output-label="PHP Array version"
|
||||||
output-language="xml"
|
|
||||||
:transformer="transformer"
|
|
||||||
:input-validation-rules="rules"
|
:input-validation-rules="rules"
|
||||||
|
:transformer="transformer"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
declare module 'jsonar-mod' {
|
||||||
|
export function arrify(json: any, options?: { prettify?: boolean}): string
|
||||||
|
export function parse(php: string): object
|
||||||
|
}
|
||||||
@@ -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'),
|
|
||||||
});
|
|
||||||
@@ -39,7 +39,7 @@ const validation = useValidation({
|
|||||||
{{ section.title }}
|
{{ section.title }}
|
||||||
</th>
|
</th>
|
||||||
<tr v-for="{ claim, claimDescription, friendlyValue, value } in decodedJWT[section.key]" :key="claim + value">
|
<tr v-for="{ claim, claimDescription, friendlyValue, value } in decodedJWT[section.key]" :key="claim + value">
|
||||||
<td class="claims" style="vertical-align: top;">
|
<td class="claims">
|
||||||
<span font-bold>
|
<span font-bold>
|
||||||
{{ claim }}
|
{{ claim }}
|
||||||
</span>
|
</span>
|
||||||
@@ -47,7 +47,7 @@ const validation = useValidation({
|
|||||||
({{ claimDescription }})
|
({{ claimDescription }})
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="word-wrap: break-word;word-break: break-all;">
|
<td>
|
||||||
<span>{{ value }}</span>
|
<span>{{ value }}</span>
|
||||||
<span v-if="friendlyValue" ml-2 op-70>
|
<span v-if="friendlyValue" ml-2 op-70>
|
||||||
({{ friendlyValue }})
|
({{ friendlyValue }})
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import { generateLoremIpsum } from './lorem-ipsum-generator.service';
|
import { generateLoremIpsum } from './lorem-ipsum-generator.service';
|
||||||
import { useCopy } from '@/composable/copy';
|
import { useCopy } from '@/composable/copy';
|
||||||
import { randIntFromInterval } from '@/utils/random';
|
import { randIntFromInterval } from '@/utils/random';
|
||||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
|
||||||
|
|
||||||
const paragraphs = ref(1);
|
const paragraphs = ref(1);
|
||||||
const sentences = ref([3, 8]);
|
const sentences = ref([3, 8]);
|
||||||
@@ -10,7 +9,7 @@ const words = ref([8, 15]);
|
|||||||
const startWithLoremIpsum = ref(true);
|
const startWithLoremIpsum = ref(true);
|
||||||
const asHTML = ref(false);
|
const asHTML = ref(false);
|
||||||
|
|
||||||
const [loremIpsumText, refreshLoremIpsum] = computedRefreshable(() =>
|
const loremIpsumText = computed(() =>
|
||||||
generateLoremIpsum({
|
generateLoremIpsum({
|
||||||
paragraphCount: paragraphs.value,
|
paragraphCount: paragraphs.value,
|
||||||
asHTML: asHTML.value,
|
asHTML: asHTML.value,
|
||||||
@@ -19,7 +18,6 @@ const [loremIpsumText, refreshLoremIpsum] = computedRefreshable(() =>
|
|||||||
startWithLoremIpsum: startWithLoremIpsum.value,
|
startWithLoremIpsum: startWithLoremIpsum.value,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to the clipboard' });
|
const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to the clipboard' });
|
||||||
</script>
|
</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" />
|
<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()">
|
<c-button autofocus @click="copy()">
|
||||||
Copy
|
Copy
|
||||||
</c-button>
|
</c-button>
|
||||||
<c-button @click="refreshLoremIpsum">
|
|
||||||
Refresh
|
|
||||||
</c-button>
|
|
||||||
</div>
|
</div>
|
||||||
</c-card>
|
</c-card>
|
||||||
</template>
|
</template>
|
||||||
@@ -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>
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { BrandPhp } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'PHP-Array to JSON',
|
||||||
|
path: '/php-array-to-json',
|
||||||
|
description: 'Convert PHP Array to JSON',
|
||||||
|
keywords: ['php', 'array', 'json'],
|
||||||
|
component: () => import('./php-array-to-json.vue'),
|
||||||
|
icon: BrandPhp,
|
||||||
|
createdAt: new Date('2024-05-11'),
|
||||||
|
});
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import jsonar from 'jsonar-mod';
|
||||||
|
import type { UseValidationRule } from '@/composable/validation';
|
||||||
|
import { withDefaultOnError } from '@/utils/defaults';
|
||||||
|
|
||||||
|
const defaultValue = `array(
|
||||||
|
"a" => "b",
|
||||||
|
"arr" => array(
|
||||||
|
1,
|
||||||
|
"2"
|
||||||
|
),
|
||||||
|
"nested" => array(
|
||||||
|
"c" => 12,
|
||||||
|
"d" => "az"
|
||||||
|
)
|
||||||
|
);`;
|
||||||
|
function transformer(value: string) {
|
||||||
|
return withDefaultOnError(() => JSON.stringify(jsonar.parse(value), null, 2), '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const rules: UseValidationRule<string>[] = [
|
||||||
|
{
|
||||||
|
validator: (v: string) => v === '' || jsonar.parse(v),
|
||||||
|
message: 'Provided PHP Array is not valid.',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<format-transformer
|
||||||
|
input-label="Your PHP Array"
|
||||||
|
:input-default="defaultValue"
|
||||||
|
input-placeholder="Paste your PHP Array here..."
|
||||||
|
output-label="JSON version"
|
||||||
|
output-language="json"
|
||||||
|
:input-validation-rules="rules"
|
||||||
|
:transformer="transformer"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -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'),
|
|
||||||
});
|
|
||||||
@@ -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/)
|
|
||||||
@@ -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>
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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">
|
|
||||||
 
|
|
||||||
</shadow-root>
|
|
||||||
</c-card>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
declare module 'korean-unpacker' {
|
|
||||||
function unpack(text: string): string;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,137 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"lang": "(International)",
|
|
||||||
"input": "TesYW 123 ? = !@",
|
|
||||||
"output": "TANGO echo sierra YANKEE WHISKEY (SPACE) ONE TWO THREE (SPACE) (?) (SPACE) (=) (SPACE) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(France)",
|
|
||||||
"input": "TesYW 123 ? = !@",
|
|
||||||
"output": "THÉRÈSE eugène suzanne YVONNE WILLIAM (ESPACE) UN DEUX TROIS (ESPACE) (?) (ESPACE) (=) (ESPACE) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Belgium)",
|
|
||||||
"input": "TesYW 123 ? = !@",
|
|
||||||
"output": "TELEFOON emiel sofie YVONNE WATERLOO (ESPACE) (1) (2) (3) (ESPACE) (?) (ESPACE) (=) (ESPACE) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Switzerland)",
|
|
||||||
"input": "TesYW 123 ? = !@",
|
|
||||||
"output": "THÉRÈSE émile suzanne (Y) WILLIAM (ESPACE) (1) (2) (3) (ESPACE) (?) (ESPACE) (=) (ESPACE) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Québec)",
|
|
||||||
"input": "TesYW 123 ? = !@",
|
|
||||||
"output": "THOMAS édouard samuel (Y) WILLIAM (ESPACE) (1) (2) (3) (ESPACE) (?) (ESPACE) (=) (ESPACE) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Germany, 2022)",
|
|
||||||
"input": "TesYü 123 ? = !@",
|
|
||||||
"output": "TÜBINGEN essen salzwedel YPSILON umlaut-unna (LEERZEICHEN) (1) (2) (3) (LEERZEICHEN) (?) (LEERZEICHEN) (=) (LEERZEICHEN) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Austria)",
|
|
||||||
"input": "TesYW 123 ? = !@",
|
|
||||||
"output": "THEODOR emil samuel/siegfried YPSILON WILHELM (LEERZEICHEN) (1) (2) (3) (LEERZEICHEN) (?) (LEERZEICHEN) (=) (LEERZEICHEN) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Germany, informal, 2022)",
|
|
||||||
"input": "TesYü 123 ? = !@",
|
|
||||||
"output": "THEODOR emil samuel YPSILON überfluss (LEERZEICHEN) (1) (2) (3) (LEERZEICHEN) (?) (LEERZEICHEN) (=) (LEERZEICHEN) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Netherlands)",
|
|
||||||
"input": "TesY huis rij 123 ? = !@",
|
|
||||||
"output": "THEODOR eduard simon YPSILON (SPATIE) hendrik utrecht izaak simon (SPATIE) richard/rudolf ijmuiden/ijsbrand (SPATIE) (1) (2) (3) (SPATIE) (?) (SPATIE) (=) (SPATIE) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Italian",
|
|
||||||
"input": "TesYj 123 ? = !@",
|
|
||||||
"output": "TORINO empoli savona YORK, YOGURT jolly/juventus (SPAZIO) (1) (2) (3) (SPAZIO) (?) (SPAZIO) (=) (SPAZIO) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Spanish",
|
|
||||||
"input": "TesYñj 123 ? = !@",
|
|
||||||
"output": "TOLEDO españa sábado YOLANDA ñoño josé (ESPACIO) (1) (2) (3) (ESPACIO) (?) (ESPACIO) (=) (ESPACIO) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Brazil)",
|
|
||||||
"input": "TesYÇj 123 ? = !@",
|
|
||||||
"output": "TATU estrela saci YOLANDA (Ç) josé (ESPAÇO) (1) (2) (3) (ESPAÇO) (?) (ESPAÇO) (=) (ESPAÇO) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "(Portugal)",
|
|
||||||
"input": "TesYúj 123 ? = !@",
|
|
||||||
"output": "TAVIRA évora setúbal YORK (ú) josé (ESPAÇO) (1) (2) (3) (ESPAÇO) (?) (ESPAÇO) (=) (ESPAÇO) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Swedish",
|
|
||||||
"input": "TesYj 123 ? = !@",
|
|
||||||
"output": "TORE erik sigurd YNGVE johan (UTRYMME) (1) (2) (3) (UTRYMME) (?) (UTRYMME) (=) (UTRYMME) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Danish",
|
|
||||||
"input": "TesÆYj 123 ? = !@",
|
|
||||||
"output": "THEODOR erik søren ÆGIR YRSA johan (MELLEMRUMSTEGN) (1) (2) (3) (MELLEMRUMSTEGN) (?) (MELLEMRUMSTEGN) (=) (MELLEMRUMSTEGN) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Norwegian",
|
|
||||||
"input": "TesYÅj 123 ? = !@",
|
|
||||||
"output": "TEODOR edith sigrid YNGLING ÅSE johan (MELLOMROMSTEGN) (1) (2) (3) (MELLOMROMSTEGN) (?) (MELLOMROMSTEGN) (=) (MELLOMROMSTEGN) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Finnish",
|
|
||||||
"input": "TesYj 123 ? = !@",
|
|
||||||
"output": "TYYNE eemeli sakari YRJÖ jussi (VÄLILYÖNTI) (1) (2) (3) (VÄLILYÖNTI) (?) (VÄLILYÖNTI) (=) (VÄLILYÖNTI) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Turkish",
|
|
||||||
"input": "TesYj 123 ? = !@",
|
|
||||||
"output": "TOKAT edirne sinop YOZGAT jandarma (BOŞLUK) (1) (2) (3) (BOŞLUK) (?) (BOŞLUK) (=) (BOŞLUK) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Romanian",
|
|
||||||
"input": "TesYj 123 ? = !@",
|
|
||||||
"output": "TUDOR elena sandu I-GREC jean (SPAȚIU) (1) (2) (3) (SPAȚIU) (?) (SPAȚIU) (=) (SPAȚIU) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Czech",
|
|
||||||
"input": "TesYj 123 ? = !@",
|
|
||||||
"output": "TOMÁŠ emil svatopluk YPSILON josef (PROSTOROVÝ) (1) (2) (3) (PROSTOROVÝ) (?) (PROSTOROVÝ) (=) (PROSTOROVÝ) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Yugoslav",
|
|
||||||
"input": "TesYČj 123 ? = !@",
|
|
||||||
"output": "TUZLA evropa skopje IPSILON ČAČAK jadran (PRIESTOROVÝ) (1) (2) (3) (PRIESTOROVÝ) (?) (PRIESTOROVÝ) (=) (PRIESTOROVÝ) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Serbian",
|
|
||||||
"input": "TesYČj 123 ? = !@",
|
|
||||||
"output": "TIMOK evropa sava IPSILON ČAČAK jadran (PROSTORNI) (1) (2) (3) (PROSTORNI) (?) (PROSTORNI) (=) (PROSTORNI) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Slovene",
|
|
||||||
"input": "TesYČj 123 ? = !@",
|
|
||||||
"output": "TRIGLAV evropa soča IPSILON ČATEŽ jadran (PRESLEDKA) (1) (2) (3) (PRESLEDKA) (?) (PRESLEDKA) (=) (PRESLEDKA) (!) (@)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Russian",
|
|
||||||
"input": "Зинаида !.?",
|
|
||||||
"output": "ЗИНАИДА иван николай анна иван дмитрий анна ( ) (!) (.) (?)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Korean",
|
|
||||||
"input": "안녕하세요 여러분",
|
|
||||||
"output": "잉어 아버지 나폴리 나폴리 연못 잉어 한강 아버지 서울 엑스레이 잉어 요지경 ( ) 잉어 연못 로마 어머니 바가지 우편 나폴리"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Greek",
|
|
||||||
"input": "τίγρης !?",
|
|
||||||
"output": "τίγρης (ί) γαλή ρήγας ηρώ σοφός ( ) (!) (?)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "Japanese",
|
|
||||||
"input": "数字のひと おしまいのン ?:",
|
|
||||||
"output": "(数) (字) 野原のノ 飛行機のヒ 東京のト ( ) 大阪のオ 新聞のシ マッチのマ いろはのイ 野原のノ おしまいのン ( ) (?) (:)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,29 +1,28 @@
|
|||||||
export const allLanguagesAndCountries = [
|
export const natoAlphabet = [
|
||||||
'(International)',
|
'Alpha',
|
||||||
'(France)',
|
'Bravo',
|
||||||
'(Belgium)',
|
'Charlie',
|
||||||
'(Switzerland)',
|
'Delta',
|
||||||
'(Québec)',
|
'Echo',
|
||||||
'(Germany, 2022)',
|
'Foxtrot',
|
||||||
'(Austria)',
|
'Golf',
|
||||||
'(Germany, informal, 2022)',
|
'Hotel',
|
||||||
'(Netherlands)',
|
'India',
|
||||||
'Italian',
|
'Juliet',
|
||||||
'Spanish',
|
'Kilo',
|
||||||
'(Brazil)',
|
'Lima',
|
||||||
'(Portugal)',
|
'Mike',
|
||||||
'Swedish',
|
'November',
|
||||||
'Danish',
|
'Oscar',
|
||||||
'Norwegian',
|
'Papa',
|
||||||
'Finnish',
|
'Quebec',
|
||||||
'Turkish',
|
'Romeo',
|
||||||
'Romanian',
|
'Sierra',
|
||||||
'Czech',
|
'Tango',
|
||||||
'Yugoslav',
|
'Uniform',
|
||||||
'Serbian',
|
'Victor',
|
||||||
'Slovene',
|
'Whiskey',
|
||||||
'Russian',
|
'X-ray',
|
||||||
'Korean',
|
'Yankee',
|
||||||
'Greek',
|
'Zulu',
|
||||||
'Japanese',
|
|
||||||
];
|
];
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
import { textToNatoAlphabet } from './text-to-nato-alphabet.service';
|
|
||||||
|
|
||||||
const TestCase_TestYW = 'TesYW 123 ? = !@';
|
|
||||||
const TestCase_TestYJ = 'TesYj 123 ? = !@';
|
|
||||||
const natoTests = [
|
|
||||||
{
|
|
||||||
lang: '(International)',
|
|
||||||
input: TestCase_TestYW,
|
|
||||||
output: 'TANGO echo sierra YANKEE WHISKEY (SPACE) (digit 1) (digit 2) (digit 3) (SPACE) (punctuation ?) (SPACE) (punctuation =) (SPACE) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(France)',
|
|
||||||
input: TestCase_TestYW,
|
|
||||||
output: 'THÉRÈSE eugène suzanne YVONNE WILLIAM (ESPACE) (digit 1) (digit 2) (digit 3) (ESPACE) (punctuation ?) (ESPACE) (punctuation =) (ESPACE) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Belgium)',
|
|
||||||
input: TestCase_TestYW,
|
|
||||||
output: 'TELEFOON emiel sofie YVONNE WATERLOO (ESPACE) (digit 1) (digit 2) (digit 3) (ESPACE) (punctuation ?) (ESPACE) (punctuation =) (ESPACE) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Switzerland)',
|
|
||||||
input: TestCase_TestYW,
|
|
||||||
output: 'THÉRÈSE émile suzanne (Y) WILLIAM (ESPACE) (digit 1) (digit 2) (digit 3) (ESPACE) (punctuation ?) (ESPACE) (punctuation =) (ESPACE) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Québec)',
|
|
||||||
input: TestCase_TestYW,
|
|
||||||
output: 'THOMAS édouard samuel (Y) WILLIAM (ESPACE) (digit 1) (digit 2) (digit 3) (ESPACE) (punctuation ?) (ESPACE) (punctuation =) (ESPACE) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Germany, 2022)',
|
|
||||||
input: 'TesYü 123 ? = !@',
|
|
||||||
output: 'TÜBINGEN essen salzwedel YPSILON umlaut-unna (LEERZEICHEN) (digit 1) (digit 2) (digit 3) (LEERZEICHEN) (punctuation ?) (LEERZEICHEN) (punctuation =) (LEERZEICHEN) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Austria)',
|
|
||||||
input: TestCase_TestYW,
|
|
||||||
output: 'THEODOR emil samuel/siegfried YPSILON WILHELM (LEERZEICHEN) (digit 1) (digit 2) (digit 3) (LEERZEICHEN) (punctuation ?) (LEERZEICHEN) (punctuation =) (LEERZEICHEN) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Germany, informal, 2022)',
|
|
||||||
input: 'TesYü 123 ? = !@',
|
|
||||||
output: 'THEODOR emil samuel YPSILON überfluss (LEERZEICHEN) (digit 1) (digit 2) (digit 3) (LEERZEICHEN) (punctuation ?) (LEERZEICHEN) (punctuation =) (LEERZEICHEN) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Netherlands)',
|
|
||||||
input: 'TesY huis rij 123 ? = !@',
|
|
||||||
output: 'THEODOR eduard simon YPSILON (SPATIE) hendrik utrecht izaak simon (SPATIE) richard/rudolf ijmuiden/ijsbrand (SPATIE) (digit 1) (digit 2) (digit 3) (SPATIE) (punctuation ?) (SPATIE) (punctuation =) (SPATIE) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Italian',
|
|
||||||
input: TestCase_TestYJ,
|
|
||||||
output: 'TORINO empoli savona YORK, YOGURT jolly/juventus (SPAZIO) (digit 1) (digit 2) (digit 3) (SPAZIO) (punctuation ?) (SPAZIO) (punctuation =) (SPAZIO) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Spanish',
|
|
||||||
input: 'TesYñj 123 ? = !@',
|
|
||||||
output: 'TOLEDO españa sábado YOLANDA ñoño josé (ESPACIO) (digit 1) (digit 2) (digit 3) (ESPACIO) (punctuation ?) (ESPACIO) (punctuation =) (ESPACIO) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Brazil)',
|
|
||||||
input: 'TesYÇj 123 ? = !@',
|
|
||||||
output: 'TATU estrela saci YOLANDA (Ç) josé (ESPAÇO) (digit 1) (digit 2) (digit 3) (ESPAÇO) (punctuation ?) (ESPAÇO) (punctuation =) (ESPAÇO) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: '(Portugal)',
|
|
||||||
input: 'TesYúj 123 ? = !@',
|
|
||||||
output: 'TAVIRA évora setúbal YORK (ú) josé (ESPAÇO) (digit 1) (digit 2) (digit 3) (ESPAÇO) (punctuation ?) (ESPAÇO) (punctuation =) (ESPAÇO) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Swedish',
|
|
||||||
input: TestCase_TestYJ,
|
|
||||||
output: 'TORE erik sigurd YNGVE johan (UTRYMME) (digit 1) (digit 2) (digit 3) (UTRYMME) (punctuation ?) (UTRYMME) (punctuation =) (UTRYMME) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Danish',
|
|
||||||
input: 'TesÆYj 123 ? = !@',
|
|
||||||
output: 'THEODOR erik søren ÆGIR YRSA johan (MELLEMRUMSTEGN) (digit 1) (digit 2) (digit 3) (MELLEMRUMSTEGN) (punctuation ?) (MELLEMRUMSTEGN) (punctuation =) (MELLEMRUMSTEGN) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Norwegian',
|
|
||||||
input: 'TesYÅj 123 ? = !@',
|
|
||||||
output: 'TEODOR edith sigrid YNGLING ÅSE johan (MELLOMROMSTEGN) (digit 1) (digit 2) (digit 3) (MELLOMROMSTEGN) (punctuation ?) (MELLOMROMSTEGN) (punctuation =) (MELLOMROMSTEGN) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Finnish',
|
|
||||||
input: TestCase_TestYJ,
|
|
||||||
output: 'TYYNE eemeli sakari YRJÖ jussi (VÄLILYÖNTI) (digit 1) (digit 2) (digit 3) (VÄLILYÖNTI) (punctuation ?) (VÄLILYÖNTI) (punctuation =) (VÄLILYÖNTI) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Turkish',
|
|
||||||
input: TestCase_TestYJ,
|
|
||||||
output: 'TOKAT edirne sinop YOZGAT jandarma (BOŞLUK) (digit 1) (digit 2) (digit 3) (BOŞLUK) (punctuation ?) (BOŞLUK) (punctuation =) (BOŞLUK) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Romanian',
|
|
||||||
input: TestCase_TestYJ,
|
|
||||||
output: 'TUDOR elena sandu I-GREC jean (SPAȚIU) (digit 1) (digit 2) (digit 3) (SPAȚIU) (punctuation ?) (SPAȚIU) (punctuation =) (SPAȚIU) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Czech',
|
|
||||||
input: TestCase_TestYJ,
|
|
||||||
output: 'TOMÁŠ emil svatopluk YPSILON josef (PROSTOROVÝ) (digit 1) (digit 2) (digit 3) (PROSTOROVÝ) (punctuation ?) (PROSTOROVÝ) (punctuation =) (PROSTOROVÝ) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Yugoslav',
|
|
||||||
input: 'TesYČj 123 ? = !@',
|
|
||||||
output: 'TUZLA evropa skopje IPSILON ČAČAK jadran (PRIESTOROVÝ) (digit 1) (digit 2) (digit 3) (PRIESTOROVÝ) (punctuation ?) (PRIESTOROVÝ) (punctuation =) (PRIESTOROVÝ) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Serbian',
|
|
||||||
input: 'TesYČj 123 ? = !@',
|
|
||||||
output: 'TIMOK evropa sava IPSILON ČAČAK jadran (PROSTORNI) (digit 1) (digit 2) (digit 3) (PROSTORNI) (punctuation ?) (PROSTORNI) (punctuation =) (PROSTORNI) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Slovene',
|
|
||||||
input: 'TesYČj 123 ? = !@',
|
|
||||||
output: 'TRIGLAV evropa soča IPSILON ČATEŽ jadran (PRESLEDKA) (digit 1) (digit 2) (digit 3) (PRESLEDKA) (punctuation ?) (PRESLEDKA) (punctuation =) (PRESLEDKA) (punctuation !) (punctuation @)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Russian',
|
|
||||||
input: 'Зинаида !.?',
|
|
||||||
output: 'ЗИНАИДА иван николай анна иван дмитрий анна ( ) (punctuation !) (punctuation .) (punctuation ?)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Korean',
|
|
||||||
input: '안녕하세요 여러분',
|
|
||||||
output: '잉어 아버지 나폴리 나폴리 연못 잉어 한강 아버지 서울 엑스레이 잉어 요지경 ( ) 잉어 연못 로마 어머니 바가지 우편 나폴리',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Greek',
|
|
||||||
input: 'τίγρης !?',
|
|
||||||
output: 'τίγρης (ί) γαλή ρήγας ηρώ σοφός ( ) (punctuation !) (punctuation ?)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lang: 'Japanese',
|
|
||||||
input: '数字のひと おしまいのン ?:',
|
|
||||||
output: '(数) (字) 野原のノ 飛行機のヒ 東京のト ( ) 大阪のオ 新聞のシ マッチのマ いろはのイ 野原のノ おしまいのン ( ) (punctuation ?) (punctuation :)',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('text-to-nato', () => {
|
|
||||||
it('Convert text to NATO', async () => {
|
|
||||||
for (const nato of natoTests) {
|
|
||||||
const { lang, input, output } = nato;
|
|
||||||
expect(textToNatoAlphabet({ text: input, langOrCountry: lang })).to.equal(output);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Convert text to NATO (includes punctuations and digits names)', async () => {
|
|
||||||
expect(textToNatoAlphabet({ text: 'a 1 2 3 ! % ? ;', langOrCountry: '(France)', useDigitsNames: true, usePunctuationsNames: true })).to.equal(
|
|
||||||
'anatole (ESPACE) {digit 1 => un} (ESPACE) {digit 2 => deux} (ESPACE) {digit 3 => trois} (ESPACE) {punctuation ! => point d\'exclamation} (ESPACE) {punctuation % => pour cent} (ESPACE) {punctuation ? => point d\'interrogation} (ESPACE) {punctuation ; => point-virgule}');
|
|
||||||
expect(textToNatoAlphabet({ text: 'и 1 2 3 ! % ? ;', langOrCountry: 'Russian', useDigitsNames: true, usePunctuationsNames: true })).to.equal(
|
|
||||||
'иван ( ) {digit 1 => один (odin)} ( ) {digit 2 => два (dva)} ( ) {digit 3 => три (tri)} ( ) {punctuation ! => восклицательный знак (vosklitsatel\'nyy znak)} ( ) {punctuation % => процент (protsent)} ( ) {punctuation ? => вопросительный знак (voprositel\'nyy znak)} ( ) {punctuation ; => точка с запятой (tochka s zapyatoy)}');
|
|
||||||
expect(textToNatoAlphabet({ text: 'TesYj 1 2 3 ! % ? ;', langOrCountry: 'Swedish', useDigitsNames: true, usePunctuationsNames: true })).to.equal(
|
|
||||||
'TORE erik sigurd YNGVE johan (UTRYMME) {digit 1 => ett} (UTRYMME) {digit 2 => två} (UTRYMME) {digit 3 => tre} (UTRYMME) {punctuation ! => utropstecken} (UTRYMME) {punctuation % => procent} (UTRYMME) {punctuation ? => frågetecken} (UTRYMME) {punctuation ; => semikolon}');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,80 +1,19 @@
|
|||||||
import hangul from 'korean-unpacker';
|
import { natoAlphabet } from './text-to-nato-alphabet.constants';
|
||||||
import allAlphabets from './nato.alphabets.json';
|
|
||||||
|
|
||||||
type AllAlphabetsKeys = keyof typeof allAlphabets[0];
|
|
||||||
|
|
||||||
export { textToNatoAlphabet };
|
export { textToNatoAlphabet };
|
||||||
|
|
||||||
function isPunctuation(char: string) {
|
function getLetterPositionInAlphabet({ letter }: { letter: string }) {
|
||||||
const punctuations = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
|
return letter.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0);
|
||||||
return punctuations.includes(char);
|
|
||||||
}
|
|
||||||
function isDigit(char: string) {
|
|
||||||
const digits = '0123456789';
|
|
||||||
return digits.includes(char);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeRegExp(string: string) {
|
function textToNatoAlphabet({ text }: { text: string }) {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
return text
|
||||||
}
|
.split('')
|
||||||
|
.map((character) => {
|
||||||
function textToNatoAlphabet({
|
const alphabetIndex = getLetterPositionInAlphabet({ letter: character });
|
||||||
text, langOrCountry = '(International)',
|
const natoWord = natoAlphabet[alphabetIndex];
|
||||||
useDigitsNames = false, usePunctuationsNames = false,
|
|
||||||
}: {
|
return natoWord ?? character;
|
||||||
text: string
|
})
|
||||||
langOrCountry: string
|
.join(' ');
|
||||||
useDigitsNames?: boolean
|
|
||||||
usePunctuationsNames?: boolean
|
|
||||||
}) {
|
|
||||||
const getNatoWord = (searchChar: string) => {
|
|
||||||
const alphabetLetter = allAlphabets.find(letter => letter.Letter === searchChar);
|
|
||||||
if (alphabetLetter && alphabetLetter[langOrCountry as AllAlphabetsKeys]) {
|
|
||||||
return alphabetLetter[langOrCountry as AllAlphabetsKeys] || '';
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const charRegex = new RegExp(
|
|
||||||
`(${
|
|
||||||
allAlphabets
|
|
||||||
.sort((a, b) => b.Letter.length - a.Letter.length)
|
|
||||||
.filter(a => a[langOrCountry as AllAlphabetsKeys])
|
|
||||||
.map(a => escapeRegExp(a.Letter))
|
|
||||||
.join('|')
|
|
||||||
}|.)`,
|
|
||||||
'gi');
|
|
||||||
return hangul.unpack(text)
|
|
||||||
.replace(/\s+/g, ' ')
|
|
||||||
.replace(
|
|
||||||
charRegex,
|
|
||||||
(character) => {
|
|
||||||
const searchChar = character.toUpperCase();
|
|
||||||
const isUpper = character[0].toUpperCase() === character[0];
|
|
||||||
const natoWord = getNatoWord(searchChar);
|
|
||||||
|
|
||||||
if (isDigit(searchChar)) {
|
|
||||||
if (useDigitsNames) {
|
|
||||||
return ` {digit ${searchChar} => ${natoWord}}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return ` (digit ${character})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isPunctuation(searchChar)) {
|
|
||||||
if (usePunctuationsNames) {
|
|
||||||
return ` {punctuation ${searchChar} => ${natoWord}}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return ` (punctuation ${character})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (natoWord) {
|
|
||||||
return ` ${isUpper ? natoWord.toUpperCase() : natoWord.toLowerCase()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ` (${character})`;
|
|
||||||
})
|
|
||||||
.trim();
|
|
||||||
}
|
}
|
||||||
@@ -1,33 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { textToNatoAlphabet } from './text-to-nato-alphabet.service';
|
import { textToNatoAlphabet } from './text-to-nato-alphabet.service';
|
||||||
import { allLanguagesAndCountries } from './text-to-nato-alphabet.constants';
|
|
||||||
import { useCopy } from '@/composable/copy';
|
import { useCopy } from '@/composable/copy';
|
||||||
|
|
||||||
const lang = useStorage('text-to-nato:lang', '(International)');
|
|
||||||
const input = ref('');
|
const input = ref('');
|
||||||
const useDigitsNames = useStorage('text-to-nato:digits', false);
|
const natoText = computed(() => textToNatoAlphabet({ text: input.value }));
|
||||||
const usePunctuationsNames = useStorage('text-to-nato:puncts', false);
|
|
||||||
const natoText = computed(() => textToNatoAlphabet({ text: input.value, langOrCountry: lang.value }));
|
|
||||||
const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.' });
|
const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.' });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<c-select
|
|
||||||
v-model:value="lang"
|
|
||||||
:options="allLanguagesAndCountries"
|
|
||||||
searchable
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div flex justify-center>
|
|
||||||
<n-form-item label="Use digits pronunciation">
|
|
||||||
<n-checkbox v-model:checked="usePunctuationsNames" />
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item label="Use punctuations pronunciation">
|
|
||||||
<n-checkbox v-model:checked="useDigitsNames" />
|
|
||||||
</n-form-item>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="input"
|
v-model:value="input"
|
||||||
label="Your text to convert to NATO phonetic alphabet"
|
label="Your text to convert to NATO phonetic alphabet"
|
||||||
@@ -38,7 +19,7 @@ const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.
|
|||||||
|
|
||||||
<div v-if="natoText">
|
<div v-if="natoText">
|
||||||
<div mb-2>
|
<div mb-2>
|
||||||
Your text in NATO phonetic alphabet ({{ lang }})
|
Your text in NATO phonetic alphabet
|
||||||
</div>
|
</div>
|
||||||
<c-card>
|
<c-card>
|
||||||
{{ natoText }}
|
{{ natoText }}
|
||||||
|
|||||||
@@ -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'),
|
|
||||||
});
|
|
||||||
@@ -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>
|
|
||||||
@@ -38,8 +38,7 @@ describe('base64 utils', () => {
|
|||||||
|
|
||||||
it('should throw for incorrect base64 string', () => {
|
it('should throw for incorrect base64 string', () => {
|
||||||
expect(() => base64ToText('a')).to.throw('Incorrect base64 string');
|
expect(() => base64ToText('a')).to.throw('Incorrect base64 string');
|
||||||
// should not really be false because trimming of space is now implied
|
expect(() => base64ToText(' ')).to.throw('Incorrect base64 string');
|
||||||
// expect(() => base64ToText(' ')).to.throw('Incorrect base64 string');
|
|
||||||
expect(() => base64ToText('é')).to.throw('Incorrect base64 string');
|
expect(() => base64ToText('é')).to.throw('Incorrect base64 string');
|
||||||
// missing final '='
|
// missing final '='
|
||||||
expect(() => base64ToText('bG9yZW0gaXBzdW0')).to.throw('Incorrect base64 string');
|
expect(() => base64ToText('bG9yZW0gaXBzdW0')).to.throw('Incorrect base64 string');
|
||||||
@@ -57,17 +56,17 @@ describe('base64 utils', () => {
|
|||||||
|
|
||||||
it('should return false for incorrect base64 string', () => {
|
it('should return false for incorrect base64 string', () => {
|
||||||
expect(isValidBase64('a')).to.eql(false);
|
expect(isValidBase64('a')).to.eql(false);
|
||||||
|
expect(isValidBase64(' ')).to.eql(false);
|
||||||
expect(isValidBase64('é')).to.eql(false);
|
expect(isValidBase64('é')).to.eql(false);
|
||||||
expect(isValidBase64('data:text/plain;notbase64,YQ==')).to.eql(false);
|
expect(isValidBase64('data:text/plain;notbase64,YQ==')).to.eql(false);
|
||||||
// missing final '='
|
// missing final '='
|
||||||
expect(isValidBase64('bG9yZW0gaXBzdW0')).to.eql(false);
|
expect(isValidBase64('bG9yZW0gaXBzdW0')).to.eql(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true for untrimmed correct base64 string', () => {
|
it('should return false for untrimmed correct base64 string', () => {
|
||||||
expect(isValidBase64('bG9yZW0gaXBzdW0= ')).to.eql(true);
|
expect(isValidBase64('bG9yZW0gaXBzdW0= ')).to.eql(false);
|
||||||
expect(isValidBase64(' LTE=')).to.eql(true);
|
expect(isValidBase64(' LTE=')).to.eql(false);
|
||||||
expect(isValidBase64(' YQ== ')).to.eql(true);
|
expect(isValidBase64(' YQ== ')).to.eql(false);
|
||||||
expect(isValidBase64(' ')).to.eql(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+4
-7
@@ -1,9 +1,7 @@
|
|||||||
import { Base64 } from 'js-base64';
|
|
||||||
|
|
||||||
export { textToBase64, base64ToText, isValidBase64, removePotentialDataAndMimePrefix };
|
export { textToBase64, base64ToText, isValidBase64, removePotentialDataAndMimePrefix };
|
||||||
|
|
||||||
function textToBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boolean } = {}) {
|
function textToBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boolean } = {}) {
|
||||||
const encoded = Base64.encode(str);
|
const encoded = window.btoa(str);
|
||||||
return makeUrlSafe ? makeUriSafe(encoded) : encoded;
|
return makeUrlSafe ? makeUriSafe(encoded) : encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +16,7 @@ function base64ToText(str: string, { makeUrlSafe = false }: { makeUrlSafe?: bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Base64.decode(cleanStr);
|
return window.atob(cleanStr);
|
||||||
}
|
}
|
||||||
catch (_) {
|
catch (_) {
|
||||||
throw new Error('Incorrect base64 string');
|
throw new Error('Incorrect base64 string');
|
||||||
@@ -36,11 +34,10 @@ function isValidBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const reEncodedBase64 = Base64.fromUint8Array(Base64.toUint8Array(cleanStr));
|
|
||||||
if (makeUrlSafe) {
|
if (makeUrlSafe) {
|
||||||
return removePotentialPadding(reEncodedBase64) === cleanStr;
|
return removePotentialPadding(window.btoa(window.atob(cleanStr))) === cleanStr;
|
||||||
}
|
}
|
||||||
return reEncodedBase64 === cleanStr.replace(/\s/g, '');
|
return window.btoa(window.atob(cleanStr)) === cleanStr;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
import { URL, fileURLToPath } from 'node:url';
|
import { URL, fileURLToPath } from 'node:url';
|
||||||
|
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||||
|
|
||||||
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
|
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
@@ -97,6 +98,7 @@ export default defineConfig({
|
|||||||
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
|
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
|
||||||
}),
|
}),
|
||||||
Unocss(),
|
Unocss(),
|
||||||
|
nodePolyfills(),
|
||||||
],
|
],
|
||||||
base: baseUrl,
|
base: baseUrl,
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
Reference in new issue
Block a user