Compare commits

..
10 changed files with 221 additions and 263 deletions

No files matched your search

+4 -6
View File
@@ -90,6 +90,7 @@ declare module '@vue/runtime-core' {
HttpStatusCodes: typeof import('./src/tools/http-status-codes/http-status-codes.vue')['default']
IbanValidatorAndParser: typeof import('./src/tools/iban-validator-and-parser/iban-validator-and-parser.vue')['default']
'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default']
'IconMdi:contentCopy': typeof import('~icons/mdi/content-copy')['default']
'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default']
IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
@@ -116,7 +117,6 @@ declare module '@vue/runtime-core' {
JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default']
JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default']
KeycodeInfo: typeof import('./src/tools/keycode-info/keycode-info.vue')['default']
ListComparer: typeof import('./src/tools/list-comparer/list-comparer.vue')['default']
ListConverter: typeof import('./src/tools/list-converter/list-converter.vue')['default']
LocaleSelector: typeof import('./src/modules/i18n/components/locale-selector.vue')['default']
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
@@ -136,18 +136,15 @@ declare module '@vue/runtime-core' {
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFlex: typeof import('naive-ui')['NFlex']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NInput: typeof import('naive-ui')['NInput']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSlider: typeof import('naive-ui')['NSlider']
NSpace: typeof import('naive-ui')['NSpace']
NSwitch: typeof import('naive-ui')['NSwitch']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
@@ -167,6 +164,7 @@ declare module '@vue/runtime-core' {
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
SmartTextReplacer: typeof import('./src/tools/smart-text-replacer/smart-text-replacer.vue')['default']
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
StringObfuscator: typeof import('./src/tools/string-obfuscator/string-obfuscator.vue')['default']
-3
View File
@@ -42,7 +42,6 @@
"@tiptap/pm": "2.1.6",
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/arr-diff": "^4.0.3",
"@types/figlet": "^1.5.8",
"@types/markdown-it": "^13.0.7",
"@vicons/material": "^0.12.0",
@@ -50,7 +49,6 @@
"@vueuse/core": "^10.3.0",
"@vueuse/head": "^1.0.0",
"@vueuse/router": "^10.0.0",
"arr-diff": "^4.0.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"colord": "^2.9.3",
@@ -63,7 +61,6 @@
"dompurify": "^3.0.6",
"email-normalizer": "^1.0.0",
"emojilib": "^3.0.10",
"fast_array_intersect": "^1.1.0",
"figlet": "^1.7.0",
"figue": "^1.2.0",
"fuse.js": "^6.6.2",
+3 -25
View File
@@ -26,9 +26,6 @@ dependencies:
'@tiptap/vue-3':
specifier: 2.0.3
version: 2.0.3(@tiptap/core@2.1.12)(@tiptap/pm@2.1.6)(vue@3.3.4)
'@types/arr-diff':
specifier: ^4.0.3
version: 4.0.3
'@types/figlet':
specifier: ^1.5.8
version: 1.5.8
@@ -50,9 +47,6 @@ dependencies:
'@vueuse/router':
specifier: ^10.0.0
version: 10.0.0(vue-router@4.1.6)(vue@3.3.4)
arr-diff:
specifier: ^4.0.0
version: 4.0.0
bcryptjs:
specifier: ^2.4.3
version: 2.4.3
@@ -89,9 +83,6 @@ dependencies:
emojilib:
specifier: ^3.0.10
version: 3.0.10
fast_array_intersect:
specifier: ^1.1.0
version: 1.1.0
figlet:
specifier: ^1.7.0
version: 1.7.0
@@ -2925,10 +2916,6 @@ packages:
resolution: {integrity: sha512-yhxwIlFVSVcMym3O31HoMnRXpoenmpIxcj4Yoes2DUpe+xCJnA7ECQP1Vw889V0jTt/2nzvpLQ/UuMYCd3JPIg==}
dev: true
/@types/arr-diff@4.0.3:
resolution: {integrity: sha512-oIBe7qtc48Q1JPNuqSIUYCNMQxYzTkQAEw07b0NEZpwKbUeOswzex3qfvXCLrZDIQ9t3ucIxH6JqFmjRTPbDEg==}
dev: false
/@types/bcryptjs@2.4.2:
resolution: {integrity: sha512-LiMQ6EOPob/4yUL66SZzu6Yh77cbzJFYll+ZfaPiPPFswtIlA/Fs1MzdKYA7JApHU49zQTbJGX3PDmCpIdDBRQ==}
dev: true
@@ -3408,7 +3395,7 @@ packages:
dependencies:
'@unhead/dom': 0.5.1
'@unhead/schema': 0.5.1
'@vueuse/shared': 11.1.0(vue@3.3.4)
'@vueuse/shared': 11.0.3(vue@3.3.4)
unhead: 0.5.1
vue: 3.3.4
transitivePeerDependencies:
@@ -4050,8 +4037,8 @@ packages:
- vue
dev: false
/@vueuse/shared@11.1.0(vue@3.3.4):
resolution: {integrity: sha512-YUtIpY122q7osj+zsNMFAfMTubGz0sn5QzE5gPzAIiCmtt2ha3uQUY1+JPyL4gRCTsLPX82Y9brNbo/aqlA91w==}
/@vueuse/shared@11.0.3(vue@3.3.4):
resolution: {integrity: sha512-0rY2m6HS5t27n/Vp5cTDsKTlNnimCqsbh/fmT2LgE+aaU42EMfXo8+bNX91W9I7DDmxfuACXMmrd7d79JxkqWA==}
dependencies:
vue-demi: 0.14.10(vue@3.3.4)
transitivePeerDependencies:
@@ -4167,11 +4154,6 @@ packages:
/argparse@2.0.1:
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
/arr-diff@4.0.0:
resolution: {integrity: sha512-YVIQ82gZPGBebQV/a8dar4AitzCQs0jjXwMPZllpXMaGjXPYVUawSxQrRsjhjupyVxEvbHgUmIhKVlND+j02kA==}
engines: {node: '>=0.10.0'}
dev: false
/array-buffer-byte-length@1.0.0:
resolution: {integrity: sha512-LPuwb2P+NrQw3XhxGc36+XSvuBPopovXYTR9Ew++Du9Yb/bx5AzBfrIsBoj0EZUifjQU+sHL21sseZ3jerWO/A==}
dependencies:
@@ -5654,10 +5636,6 @@ packages:
resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==}
dev: true
/fast_array_intersect@1.1.0:
resolution: {integrity: sha512-/DCilZlUdz2XyNDF+ASs0PwY+RKG9Y4Silp/gbS72Cvbg4oibc778xcecg+pnNyiNHYgh/TApsiDTjpdniyShw==}
dev: false
/fastq@1.15.0:
resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==}
dependencies:
+2 -2
View File
@@ -1,6 +1,7 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as smartTextReplacer } from './smart-text-replacer';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
@@ -29,7 +30,6 @@ import { tool as tomlToJson } from './toml-to-json';
import { tool as jsonToCsv } from './json-to-csv';
import { tool as cameraRecorder } from './camera-recorder';
import { tool as listConverter } from './list-converter';
import { tool as listComparer } from './list-comparer';
import { tool as phoneParserAndFormatter } from './phone-parser-and-formatter';
import { tool as jsonDiff } from './json-diff';
import { tool as ipv4RangeExpander } from './ipv4-range-expander';
@@ -112,7 +112,6 @@ export const toolsByCategory: ToolCategory[] = [
jsonToYaml,
jsonToToml,
listConverter,
listComparer,
tomlToJson,
tomlToYaml,
xmlToJson,
@@ -185,6 +184,7 @@ export const toolsByCategory: ToolCategory[] = [
stringObfuscator,
textDiff,
numeronymGenerator,
smartTextReplacer,
asciiTextDrawer,
],
},
-12
View File
@@ -1,12 +0,0 @@
import { List } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Lists Comparer',
path: '/list-comparer',
description: 'Compare two list items',
keywords: ['list', 'comparer'],
component: () => import('./list-comparer.vue'),
icon: List,
createdAt: new Date('2024-08-15'),
});
@@ -1,97 +0,0 @@
import { describe, expect, it } from 'vitest';
import { compareLists } from './list-comparer.service';
describe('list-comparer', () => {
describe('compareLists', () => {
it('return correct comparaison', () => {
expect(compareLists({
list1: '1\n 2\n3\n4\n5\n4\n7\nA',
list2: '1\n2\n3\n4\n6\n4\n7\na',
trimItems: true,
ignoreCase: true,
})).to.deep.eq({
list1Not2: [
'5',
],
list2Not1: [
'6',
],
same: [
'1',
'2',
'3',
'4',
'7',
'a',
],
});
expect(compareLists({
list1: '1\n 2\n3\n4\n5\n4\n7\nA',
list2: '1\n2\n3\n4\n6\n4\n7\na',
trimItems: false,
ignoreCase: false,
})).to.deep.eq({
list1Not2: [
' 2',
'5',
'A',
],
list2Not1: [
'2',
'6',
'a',
],
same: [
'1',
'3',
'4',
'7',
],
});
expect(compareLists({
list1: '1, 2,3,4,5\n4,7,A,A',
list2: '1\n2\n3\n4\n6\n4\n7\na',
trimItems: false,
ignoreCase: false,
separator: ',',
})).to.deep.eq({
list1Not2: [
' 2',
'5',
'A',
],
list2Not1: [
'2',
'6',
'a',
],
same: [
'1',
'3',
'4',
'7',
],
});
expect(compareLists({
list1: '10\n20\n20\n30',
list2: '30\n20\n40',
trimItems: false,
ignoreCase: false,
})).to.deep.eq({
list1Not2: [
'10',
],
list2Not1: [
'40',
],
same: [
'30',
'20',
],
});
});
});
});
@@ -1,36 +0,0 @@
import _ from 'lodash';
import intersect from 'fast_array_intersect';
import diff from 'arr-diff';
export function compareLists({
list1,
list2,
ignoreCase = false,
trimItems = true,
separator = '',
}: {
list1: string
list2: string
separator?: string
ignoreCase?: boolean
trimItems?: boolean
}) {
const splitSep = separator ? `${separator}|` : '';
const splitRegExp = new RegExp(`(?:${splitSep}\\n)`, 'g');
const prepareList = (list: string) =>
_.chain(list ?? '')
.thru(text => ignoreCase ? text.toLowerCase() : text)
.split(splitRegExp)
.map(text => trimItems ? text.trim() : text)
.value();
const list1Arr = prepareList(list1);
const list2Arr = prepareList(list2);
return {
same: [...new Set(intersect([list1Arr, list2Arr]))],
list2Not1: [...new Set(diff(list2Arr, list1Arr))],
list1Not2: [...new Set(diff(list1Arr, list2Arr))],
};
}
-82
View File
@@ -1,82 +0,0 @@
<script setup lang="ts">
import { compareLists } from './list-comparer.service';
const compareConfig = useStorage<{ ignoreCase: boolean; trimItems: boolean; noDuplicate: boolean; separator: string }>('list-cmp:conf', {
ignoreCase: false,
trimItems: true,
noDuplicate: false,
separator: '',
});
const list1 = ref('');
const list2 = ref('');
const compareResult = computed(() => {
return compareLists({
list1: list1.value,
list2: list2.value,
ignoreCase: compareConfig.value.ignoreCase,
trimItems: compareConfig.value.trimItems,
separator: compareConfig.value.separator,
});
});
</script>
<template>
<div>
<n-space justify="center" gap-1 align="baseline">
<n-form-item
label="Trim items"
label-placement="left"
>
<n-switch v-model:value="compareConfig.trimItems" />
</n-form-item>
<n-form-item
label="Ignore case"
label-placement="left"
mb-2
>
<n-switch v-model:value="compareConfig.ignoreCase" />
</n-form-item>
<n-form-item
label="Separator"
label-placement="left"
>
<n-input
v-model:value="compareConfig.separator"
placeholder="Additional separator"
/>
</n-form-item>
</n-space>
<div flex gap-1>
<c-input-text
v-model:value="list1"
multiline
rows="10"
label="List 1"
/>
<c-input-text
v-model:value="list2"
multiline
rows="10"
label="List 2"
/>
</div>
<div v-if="list1 || list2">
<n-divider />
<c-card title="Items in both lists" mb-2>
<textarea-copyable :value="compareResult.same.join('\n')" />
</c-card>
<c-card title="Items in List 1 but not in List 2" mb-2>
<textarea-copyable :value="compareResult.list1Not2.join('\n')" />
</c-card>
<c-card title="Items in List 2 but not in List 1" mb-2>
<textarea-copyable :value="compareResult.list2Not1.join('\n')" />
</c-card>
</div>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
import { Search } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Smart Text Replacer and Linebreaker',
path: '/smart-text-replacer',
description: 'Search and replace a word on single or multiple occurrences just like windows notepad search and replace. Also allows to manage linebreaking and text splitting',
keywords: ['smart', 'text-replacer', 'linebreak', 'remove', 'add', 'split', 'search', 'replace'],
component: () => import('./smart-text-replacer.vue'),
icon: Search,
createdAt: new Date('2024-04-03'),
});
@@ -0,0 +1,200 @@
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
const str = ref('Lorem ipsum dolor sit amet DOLOR Lorem ipsum dolor sit amet DOLOR');
const findWhat = ref('');
const replaceWith = ref('');
const matchCase = ref(false);
const keepLineBreaks = ref(true);
const addLineBreakPlace = ref('before');
const addLineBreakRegex = ref('');
const splitEveryCharacterCounts = ref(0);
// Tracks the index of the currently active highlight.
const currentActiveIndex = ref(0);
// Tracks the total number of matches found to cycle through them.
const totalMatches = ref(0);
const highlightedText = computed(() => {
const findWhatValue = findWhat.value;
let strValue = str.value;
if (!strValue) {
return strValue;
}
if (!keepLineBreaks.value) {
strValue = strValue.replace(/\r?\n/g, '');
}
if (addLineBreakRegex.value) {
const addLBRegex = new RegExp(addLineBreakRegex.value, matchCase.value ? 'g' : 'gi');
if (addLineBreakPlace.value === 'before') {
strValue = strValue.replace(addLBRegex, m => `\n${m}`);
}
else if (addLineBreakPlace.value === 'after') {
strValue = strValue.replace(addLBRegex, m => `${m}\n`);
}
else if (addLineBreakPlace.value === 'place') {
strValue = strValue.replace(addLBRegex, '\n');
}
}
if (splitEveryCharacterCounts.value) {
strValue = strValue.replace(new RegExp(`[^\n]{${splitEveryCharacterCounts.value}}`, 'g'), m => `${m}\n`);
}
if (!findWhatValue) {
return strValue;
}
const regex = new RegExp(findWhatValue, matchCase.value ? 'g' : 'gi');
let index = 0;
const newStr = strValue.replace(regex, (match) => {
index++;
return `<span class="${match === findWhatValue ? 'highlight' : 'outline'}">${match}</span>`;
});
totalMatches.value = index;
// Reset to -1 to ensure the first match is highlighted upon next search
currentActiveIndex.value = -1;
return newStr;
});
// Automatically highlight the first occurrence after any change
watchEffect(async () => {
if (highlightedText.value) {
await nextTick();
updateHighlighting();
}
});
watch(matchCase, () => {
// Use nextTick to wait for the DOM to update after highlightedText re-reaction
nextTick().then(() => {
const matches = document.querySelectorAll('.outline, .highlight');
if (matches.length === 0) {
// No matches after change, reset
currentActiveIndex.value = -1;
totalMatches.value = 0;
}
else if (matches.length <= currentActiveIndex.value || currentActiveIndex.value === -1) {
// Current selection is out of range or reset, select the first match
currentActiveIndex.value = 0;
updateHighlighting(); // Ensure correct highlighting
}
else {
// The current selection is still valid, ensure it's highlighted correctly
updateHighlighting(); // This might need adjustment to not advance the index
}
});
});
// Function to add active highlighting
function updateHighlighting() {
currentActiveIndex.value = (currentActiveIndex.value + 1) % totalMatches.value;
const matches = document.querySelectorAll('.outline, .highlight');
matches.forEach((match, index) => {
match.className = index === currentActiveIndex.value ? 'highlight' : 'outline';
});
}
function replaceSelected() {
const matches = document.querySelectorAll('.outline, .highlight');
if (matches.length > currentActiveIndex.value) {
const selectedMatch = matches[currentActiveIndex.value];
if (selectedMatch) {
const newText = replaceWith.value;
selectedMatch.textContent = newText;
selectedMatch.classList.remove('highlight');
currentActiveIndex.value--;
totalMatches.value--;
}
}
updateHighlighting();
}
function replaceAll() {
const matches = document.querySelectorAll('.outline, .highlight');
matches.forEach((match) => {
match.textContent = replaceWith.value;
match.classList.remove('highlight');
match.classList.remove('outline');
});
currentActiveIndex.value = -1;
totalMatches.value = matches.length;
}
function findNext() {
updateHighlighting();
}
const { copy } = useCopy({ source: highlightedText });
</script>
<template>
<div>
<c-input-text v-model:value="str" raw-text placeholder="Enter text here..." label="Text to search and replace:" clearable multiline rows="10" />
<div mt-4 w-full flex gap-10px>
<div flex-1>
<div>Find what:</div>
<c-input-text v-model:value="findWhat" placeholder="Search regex" @keyup.enter="findNext()" />
</div>
<div flex-1>
<div>Replace with:</div>
<c-input-text v-model:value="replaceWith" placeholder="Replacement expression" @keyup.enter="replaceSelected()" />
</div>
</div>
<n-space mt-4 gap-1 align="baseline" justify="space-between">
<c-button @click="findNext()">
<label>Find Next</label>
</c-button>
<c-button @click="replaceSelected()">
<label>Replace</label>
</c-button>
<c-button @click="replaceAll()">
<label>Replace All</label>
</c-button>
<n-checkbox v-model:checked="matchCase">
<label>Match case</label>
</n-checkbox>
<n-checkbox v-model:checked="keepLineBreaks">
<label>Keep linebreaks</label>
</n-checkbox>
</n-space>
<n-divider />
<div mt-4 w-full flex items-baseline gap-10px>
<c-select
v-model:value="addLineBreakPlace"
:options="[{ value: 'before', label: 'Add linebreak before' }, { value: 'after', label: 'Add linebreak after' }, { value: 'place', label: 'Add linebreak in place of' }]"
/>
<c-input-text
v-model:value="addLineBreakRegex"
placeholder="Split text regex"
/>
</div>
<div mt-4 w-full flex items-baseline gap-10px>
<n-form-item label="Split every characters:" label-placement="left">
<n-input-number v-model:value="splitEveryCharacterCounts" :min="0" />
</n-form-item>
</div>
<c-card v-if="highlightedText" mt-60px max-w-600px flex items-center gap-5px font-mono>
<!-- //NOSONAR --><div flex-1 break-anywhere text-wrap style="white-space: pre-wrap" v-html="highlightedText" />
<c-button @click="copy()">
<icon-mdi:content-copy />
</c-button>
</c-card>
</div>
</template>
<style lang="less">
.highlight {
background-color: #ff0;
color: black;
}
</style>