Skip to content

Commit 1702fc3

Browse files
committed
Merge branch 'feat/smart-text-replacer-and-linebreaks' of https://github.com/sharevb/it-tools into feat/smart-text-replacer-and-linebreaks
2 parents 2f8fad5 + 0afbf52 commit 1702fc3

18 files changed

+651
-5
lines changed

.github/logo-dark.png

39.5 KB
Loading

.github/logo-white.png

38.7 KB
Loading

.github/logo.png

-7.81 KB
Binary file not shown.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
![logo](.github/logo.png)
1+
<picture>
2+
<source srcset="./.github/logo-dark.png" media="(prefers-color-scheme: light)">
3+
<source srcset="./.github/logo-white.png" media="(prefers-color-scheme: dark)">
4+
<img src="./.github/logo-dark.png" alt="logo">
5+
</picture>
26

37
Useful tools for developer and people working in IT. [Have a look !](https://it-tools.tech).
48

components.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ declare module '@vue/runtime-core' {
141141
NH1: typeof import('naive-ui')['NH1']
142142
NH3: typeof import('naive-ui')['NH3']
143143
NIcon: typeof import('naive-ui')['NIcon']
144-
NInputNumber: typeof import('naive-ui')['NInputNumber']
145144
NLayout: typeof import('naive-ui')['NLayout']
146145
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
147146
NMenu: typeof import('naive-ui')['NMenu']
@@ -155,6 +154,9 @@ declare module '@vue/runtime-core' {
155154
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
156155
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
157156
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
157+
RegexMemo: typeof import('./src/tools/regex-memo/regex-memo.vue')['default']
158+
'RegexMemo.content': typeof import('./src/tools/regex-memo/regex-memo.content.md')['default']
159+
RegexTester: typeof import('./src/tools/regex-tester/regex-tester.vue')['default']
158160
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
159161
RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default']
160162
RouterLink: typeof import('vue-router')['RouterLink']

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
"dependencies": {
3838
"@it-tools/bip39": "^0.0.4",
3939
"@it-tools/oggen": "^1.3.0",
40+
"@regexper/render": "^1.0.0",
4041
"@sindresorhus/slugify": "^2.2.1",
4142
"@tiptap/pm": "2.1.6",
4243
"@tiptap/starter-kit": "2.1.6",
4344
"@tiptap/vue-3": "2.0.3",
44-
"@types/markdown-it": "^13.0.7",
4545
"@types/figlet": "^1.5.8",
46+
"@types/markdown-it": "^13.0.7",
4647
"@vicons/material": "^0.12.0",
4748
"@vicons/tabler": "^0.12.0",
4849
"@vueuse/core": "^10.3.0",
@@ -84,6 +85,7 @@
8485
"pinia": "^2.0.34",
8586
"plausible-tracker": "^0.3.8",
8687
"qrcode": "^1.5.1",
88+
"randexp": "^0.5.3",
8789
"sql-formatter": "^13.0.0",
8890
"ua-parser-js": "^1.0.35",
8991
"ulid": "^2.3.0",
@@ -93,6 +95,7 @@
9395
"vue": "^3.3.4",
9496
"vue-i18n": "^9.9.1",
9597
"vue-router": "^4.1.6",
98+
"vue-shadow-dom": "^4.2.0",
9699
"vue-tsc": "^1.8.1",
97100
"xml-formatter": "^3.3.2",
98101
"xml-js": "^1.6.11",

pnpm-lock.yaml

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/composable/queryParams.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useRouteQuery } from '@vueuse/router';
22
import { computed } from 'vue';
3+
import { useStorage } from '@vueuse/core';
34

4-
export { useQueryParam };
5+
export { useQueryParam, useQueryParamOrStorage };
56

67
const transformers = {
78
number: {
@@ -16,6 +17,12 @@ const transformers = {
1617
fromQuery: (value: string) => value.toLowerCase() === 'true',
1718
toQuery: (value: boolean) => (value ? 'true' : 'false'),
1819
},
20+
object: {
21+
fromQuery: (value: string) => {
22+
return JSON.parse(value);
23+
},
24+
toQuery: (value: object) => JSON.stringify(value),
25+
},
1926
};
2027

2128
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
@@ -33,3 +40,27 @@ function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue:
3340
},
3441
});
3542
}
43+
44+
function useQueryParamOrStorage<T>({ name, storageName, defaultValue }: { name: string; storageName: string; defaultValue: T }) {
45+
const type = typeof defaultValue;
46+
const transformer = transformers[type as keyof typeof transformers] ?? transformers.string;
47+
48+
const storageRef = useStorage(storageName, defaultValue);
49+
const proxyDefaultValue = transformer.toQuery(defaultValue as never);
50+
const proxy = useRouteQuery(name, proxyDefaultValue);
51+
52+
const r = ref(defaultValue);
53+
54+
watch(r,
55+
(value) => {
56+
proxy.value = transformer.toQuery(value as never);
57+
storageRef.value = value as never;
58+
},
59+
{ deep: true });
60+
61+
r.value = (proxy.value && proxy.value !== proxyDefaultValue
62+
? transformer.fromQuery(proxy.value) as unknown as T
63+
: storageRef.value as T) as never;
64+
65+
return r;
66+
}

src/composable/validation.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import _ from 'lodash';
33
import { type Ref, reactive, watch } from 'vue';
44

55
type ValidatorReturnType = unknown;
6+
type GetErrorMessageReturnType = string;
67

78
export interface UseValidationRule<T> {
89
validator: (value: T) => ValidatorReturnType
10+
getErrorMessage?: (value: T) => GetErrorMessageReturnType
911
message: string
1012
}
1113

@@ -24,6 +26,15 @@ export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
2426
}
2527
}
2628

29+
export function getErrorMessageOrThrown(cb: () => GetErrorMessageReturnType): string {
30+
try {
31+
return cb() || '';
32+
}
33+
catch (e: any) {
34+
return e.toString();
35+
}
36+
}
37+
2738
export interface ValidationAttrs {
2839
feedback: string
2940
validationStatus: string | undefined
@@ -61,7 +72,13 @@ export function useValidation<T>({
6172

6273
for (const rule of get(rules)) {
6374
if (isFalsyOrHasThrown(() => rule.validator(source.value))) {
64-
state.message = rule.message;
75+
if (rule.getErrorMessage) {
76+
const getErrorMessage = rule.getErrorMessage;
77+
state.message = rule.message.replace('{0}', getErrorMessageOrThrown(() => getErrorMessage(source.value)));
78+
}
79+
else {
80+
state.message = rule.message;
81+
}
6582
state.status = 'error';
6683
}
6784
}

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createPinia } from 'pinia';
33
import { createHead } from '@vueuse/head';
44

55
import { registerSW } from 'virtual:pwa-register';
6+
import shadow from 'vue-shadow-dom';
67
import { plausible } from './plugins/plausible.plugin';
78

89
import 'virtual:uno.css';
@@ -23,5 +24,6 @@ app.use(i18nPlugin);
2324
app.use(router);
2425
app.use(naive);
2526
app.use(plausible);
27+
app.use(shadow);
2628

2729
app.mount('#app');

0 commit comments

Comments
 (0)