mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-23 22:31:10 +03:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
473c9cc8cf | ||
|
|
aba466ac89 | ||
|
|
123c26d6b8 | ||
|
|
324fd63fcf | ||
|
|
bda56ac263 | ||
|
|
8881f440ef | ||
|
|
f7e535f3c0 | ||
|
|
4ca3ac357e | ||
|
|
0f28ddd0d5 | ||
|
|
0d67535df2 | ||
|
|
cbd32fdade | ||
|
|
8a49f233a0 | ||
|
|
ff57fda388 |
No files matched your search
Vendored
+4
-5
@@ -129,10 +129,8 @@ declare module '@vue/runtime-core' {
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.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']
|
||||
NA: typeof import('naive-ui')['NA']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
@@ -143,9 +141,10 @@ declare module '@vue/runtime-core' {
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NP: typeof import('naive-ui')['NP']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
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']
|
||||
|
||||
+2
-2
@@ -298,7 +298,7 @@ tools:
|
||||
|
||||
phone-parser-and-formatter:
|
||||
title: Phone parser and formatter
|
||||
description: Parse, validate and format phone numbers. Get information about the phone number, like the country code, type, etc. Forge link to send message in WhatsApp and SMS.
|
||||
description: Parse, validate and format phone numbers. Get information about the phone number, like the country code, type, etc.
|
||||
|
||||
ipv4-subnet-calculator:
|
||||
title: IPv4 subnet calculator
|
||||
@@ -390,4 +390,4 @@ tools:
|
||||
|
||||
text-to-binary:
|
||||
title: Text to ASCII binary
|
||||
description: Convert text to its ASCII binary representation and vice-versa.
|
||||
description: Convert text to its ASCII binary representation and vice-versa.
|
||||
@@ -18,9 +18,6 @@ export const tool = defineTool({
|
||||
'cell',
|
||||
'international',
|
||||
'national',
|
||||
'whatsapp',
|
||||
'sms',
|
||||
'message',
|
||||
],
|
||||
component: () => import('./phone-parser-and-formatter.vue'),
|
||||
icon: Phone,
|
||||
|
||||
@@ -9,10 +9,9 @@ import {
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import { booleanToHumanReadable } from '@/utils/boolean';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
const rawPhone = ref('');
|
||||
const defaultCountryCode = useQueryParamOrStorage({ name: 'country', storageName: 'phone-parser:country', defaultValue: getDefaultCountryCode() });
|
||||
const defaultCountryCode = ref(getDefaultCountryCode());
|
||||
const validation = useValidation({
|
||||
source: rawPhone,
|
||||
rules: [
|
||||
@@ -23,16 +22,13 @@ const validation = useValidation({
|
||||
],
|
||||
});
|
||||
|
||||
const parsedRaw = computed(() => {
|
||||
const parsedDetails = computed(() => {
|
||||
if (!validation.isValid) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return withDefaultOnError(() => parsePhoneNumber(rawPhone.value, defaultCountryCode.value), undefined);
|
||||
});
|
||||
const parsed = withDefaultOnError(() => parsePhoneNumber(rawPhone.value, defaultCountryCode.value), undefined);
|
||||
|
||||
const parsedDetails = computed(() => {
|
||||
const parsed = parsedRaw.value;
|
||||
if (!parsed) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -85,27 +81,6 @@ const countriesOptions = getCountries().map(code => ({
|
||||
label: `${lookup.byIso(code)?.country || code} (+${getCountryCallingCode(code)})`,
|
||||
value: code,
|
||||
}));
|
||||
|
||||
const messageToSend = ref('');
|
||||
const whatsAppLink = computed(() => {
|
||||
const parsed = parsedRaw.value;
|
||||
if (!parsed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const internationalNoPunts = parsed.formatInternational().replace(/^\+0*/g, '').replace(/\D/g, '');
|
||||
|
||||
return `https://wa.me/${internationalNoPunts}?text=${encodeURIComponent(messageToSend.value)}`;
|
||||
});
|
||||
const smsLink = computed(() => {
|
||||
const parsed = parsedRaw.value;
|
||||
if (!parsed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const internationalNoSpaces = parsed.formatInternational().replace(/\s/g, '');
|
||||
return `sms:${internationalNoSpaces}&body=${encodeURIComponent(messageToSend.value)}`;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -135,34 +110,5 @@ const smsLink = computed(() => {
|
||||
</tr>
|
||||
</tbody>
|
||||
</n-table>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-input-text
|
||||
v-model:value="messageToSend"
|
||||
multiline
|
||||
rows="4"
|
||||
placeholder="Enter a message to send"
|
||||
label="Message to send:"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<c-card v-if="whatsAppLink" title="WhatsApp Send link" mb-2>
|
||||
<input-copyable :value="whatsAppLink" mb-2 />
|
||||
<div flex justify-center>
|
||||
<!-- //NOSONAR --><c-button :href="whatsAppLink" target="_blank">
|
||||
Send via WhatsApp
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card v-if="smsLink" title="SMS Send link">
|
||||
<input-copyable :value="smsLink" mb-2 />
|
||||
<div flex justify-center>
|
||||
<!-- //NOSONAR --><c-button :href="smsLink" target="_blank">
|
||||
Send via SMS
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -94,5 +94,19 @@ describe('token-generator', () => {
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[a-zA-Z]+$/);
|
||||
});
|
||||
|
||||
it('should generate a random string with just numbers except 1 and 2 if only withNumbers is set and deniedChars contains 1 and 2', () => {
|
||||
const token = createToken({
|
||||
withLowercase: false,
|
||||
withUppercase: false,
|
||||
withNumbers: true,
|
||||
withSymbols: false,
|
||||
length: 256,
|
||||
deniedChars: '12',
|
||||
});
|
||||
|
||||
expect(token).toHaveLength(256);
|
||||
expect(token).toMatch(/^[03456789]+$/);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,7 @@ export function createToken({
|
||||
withLowercase = true,
|
||||
withNumbers = true,
|
||||
withSymbols = false,
|
||||
deniedChars = '',
|
||||
length = 64,
|
||||
alphabet,
|
||||
}: {
|
||||
@@ -12,15 +13,17 @@ export function createToken({
|
||||
withLowercase?: boolean
|
||||
withNumbers?: boolean
|
||||
withSymbols?: boolean
|
||||
deniedChars?: string
|
||||
length?: number
|
||||
alphabet?: string
|
||||
}) {
|
||||
const allAlphabet = alphabet ?? [
|
||||
withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : '',
|
||||
withLowercase ? 'abcdefghijklmopqrstuvwxyz' : '',
|
||||
withNumbers ? '0123456789' : '',
|
||||
withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '',
|
||||
].join('');
|
||||
const allAlphabet = (alphabet ?? (
|
||||
(withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : '')
|
||||
+ (withLowercase ? 'abcdefghijklmopqrstuvwxyz' : '')
|
||||
+ (withNumbers ? '0123456789' : '')
|
||||
+ (withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '')
|
||||
)).split('').filter(c => !(deniedChars?.includes(c))).join('');
|
||||
|
||||
return shuffleString(allAlphabet.repeat(length)).substring(0, length);
|
||||
const len = length < 1 ? 1 : length;
|
||||
return shuffleString(allAlphabet.repeat(len)).substring(0, len);
|
||||
}
|
||||
@@ -1,75 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import { createToken } from './token-generator.service';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParam } from '@/composable/queryParams';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
|
||||
const length = useQueryParam({ name: 'length', defaultValue: 64 });
|
||||
const withUppercase = useQueryParam({ name: 'uppercase', defaultValue: true });
|
||||
const withLowercase = useQueryParam({ name: 'lowercase', defaultValue: true });
|
||||
const withNumbers = useQueryParam({ name: 'numbers', defaultValue: true });
|
||||
const withSymbols = useQueryParam({ name: 'symbols', defaultValue: false });
|
||||
const count = useQueryParamOrStorage({ name: 'count', storageName: 'token-generator:count', defaultValue: 1 });
|
||||
const length = useQueryParamOrStorage({ name: 'length', storageName: 'token-generator:length', defaultValue: 64 });
|
||||
const withUppercase = useQueryParamOrStorage({ name: 'uppercase', storageName: 'token-generator:uppercase', defaultValue: true });
|
||||
const withLowercase = useQueryParamOrStorage({ name: 'lowercase', storageName: 'token-generator:lowercase', defaultValue: true });
|
||||
const withNumbers = useQueryParamOrStorage({ name: 'numbers', storageName: 'token-generator:numbers', defaultValue: true });
|
||||
const withSymbols = useQueryParamOrStorage({ name: 'symbols', storageName: 'token-generator:symbols', defaultValue: false });
|
||||
const deniedChars = useQueryParamOrStorage({ name: 'deny', storageName: 'token-generator:deny', defaultValue: '' });
|
||||
const { t } = useI18n();
|
||||
|
||||
const [token, refreshToken] = computedRefreshable(() =>
|
||||
createToken({
|
||||
length: length.value,
|
||||
withUppercase: withUppercase.value,
|
||||
withLowercase: withLowercase.value,
|
||||
withNumbers: withNumbers.value,
|
||||
withSymbols: withSymbols.value,
|
||||
}),
|
||||
const [tokens, refreshTokens] = computedRefreshable(() =>
|
||||
Array.from({ length: count.value < 1 ? 1 : count.value },
|
||||
() => createToken({
|
||||
length: length.value,
|
||||
withUppercase: withUppercase.value,
|
||||
withLowercase: withLowercase.value,
|
||||
withNumbers: withNumbers.value,
|
||||
withSymbols: withSymbols.value,
|
||||
deniedChars: deniedChars.value,
|
||||
})).join('\n'),
|
||||
);
|
||||
|
||||
const { copy } = useCopy({ source: token, text: t('tools.token-generator.copied') });
|
||||
const { copy } = useCopy({ source: tokens, text: t('tools.token-generator.copied') });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card>
|
||||
<n-form label-placement="left" label-width="140">
|
||||
<div flex justify-center>
|
||||
<div>
|
||||
<n-form-item :label="t('tools.token-generator.uppercase')">
|
||||
<n-switch v-model:value="withUppercase" />
|
||||
</n-form-item>
|
||||
<n-space justify="center">
|
||||
<n-form-item :label="t('tools.token-generator.uppercase')">
|
||||
<n-switch v-model:value="withUppercase" />
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item :label="t('tools.token-generator.lowercase')">
|
||||
<n-switch v-model:value="withLowercase" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<n-form-item :label="t('tools.token-generator.lowercase')">
|
||||
<n-switch v-model:value="withLowercase" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('tools.token-generator.numbers')">
|
||||
<n-switch v-model:value="withNumbers" />
|
||||
</n-form-item>
|
||||
|
||||
<div>
|
||||
<n-form-item :label="t('tools.token-generator.numbers')">
|
||||
<n-switch v-model:value="withNumbers" />
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item :label="t('tools.token-generator.symbols')">
|
||||
<n-switch v-model:value="withSymbols" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</div>
|
||||
<n-form-item :label="t('tools.token-generator.symbols')">
|
||||
<n-switch v-model:value="withSymbols" />
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
</n-form>
|
||||
|
||||
<n-form-item label="Denied Characters (ie, visually similar { oO01lI } or punctuations)" label-placement="top">
|
||||
<c-input-text
|
||||
v-model:value="deniedChars"
|
||||
placeholder="Put characters to deny from token"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item :label="`${t('tools.token-generator.length')} (${length})`" label-placement="left">
|
||||
<n-slider v-model:value="length" :step="1" :min="1" :max="512" />
|
||||
<n-slider v-model:value="length" :step="1" :min="1" :max="512" mr-2 />
|
||||
<n-input-number v-model:value="length" :min="1" :max="512" size="small" />
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="Number of token to generate" label-placement="left">
|
||||
<n-slider v-model:value="count" :step="1" :min="1" mr-2 />
|
||||
<n-input-number v-model:value="count" :min="1" size="small" />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="token"
|
||||
v-model:value="tokens"
|
||||
multiline
|
||||
:placeholder="t('tools.token-generator.tokenPlaceholder')"
|
||||
readonly
|
||||
rows="3"
|
||||
autosize
|
||||
class="token-display"
|
||||
word-wrap
|
||||
/>
|
||||
|
||||
<div mt-5 flex justify-center gap-3>
|
||||
<c-button @click="copy()">
|
||||
{{ t('tools.token-generator.button.copy') }}
|
||||
</c-button>
|
||||
<c-button @click="refreshToken">
|
||||
<c-button @click="refreshTokens">
|
||||
{{ t('tools.token-generator.button.refresh') }}
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user