Compare commits

..
12 changed files with 6726 additions and 8465 deletions

No files matched your search

+4 -4
View File
@@ -37,6 +37,7 @@ declare module '@vue/runtime-core' {
'CFileUpload.demo': typeof import('./src/ui/c-file-upload/c-file-upload.demo.vue')['default']
ChmodCalculator: typeof import('./src/tools/chmod-calculator/chmod-calculator.vue')['default']
Chronometer: typeof import('./src/tools/chronometer/chronometer.vue')['default']
CidrInCidr: typeof import('./src/tools/cidr-in-cidr/cidr-in-cidr.vue')['default']
CInputText: typeof import('./src/ui/c-input-text/c-input-text.vue')['default']
'CInputText.demo': typeof import('./src/ui/c-input-text/c-input-text.demo.vue')['default']
CKeyValueList: typeof import('./src/ui/c-key-value-list/c-key-value-list.vue')['default']
@@ -103,6 +104,7 @@ declare module '@vue/runtime-core' {
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
IpInRange: typeof import('./src/tools/cidr-in-cidr/cidr-in-cidr.vue')['default']
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
@@ -132,17 +134,15 @@ declare module '@vue/runtime-core' {
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDatePicker: typeof import('naive-ui')['NDatePicker']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NTable: typeof import('naive-ui')['NTable']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
@@ -161,6 +161,7 @@ declare module '@vue/runtime-core' {
RouterView: typeof import('vue-router')['RouterView']
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']
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
@@ -185,7 +186,6 @@ declare module '@vue/runtime-core' {
UserAgentParser: typeof import('./src/tools/user-agent-parser/user-agent-parser.vue')['default']
UserAgentResultCards: typeof import('./src/tools/user-agent-parser/user-agent-result-cards.vue')['default']
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
WeekNumberConverter: typeof import('./src/tools/week-number-converter/week-number-converter.vue')['default']
WifiQrCodeGenerator: typeof import('./src/tools/wifi-qr-code-generator/wifi-qr-code-generator.vue')['default']
XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default']
XmlToJson: typeof import('./src/tools/xml-to-json/xml-to-json.vue')['default']
+1
View File
@@ -70,6 +70,7 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"ip-matching": "^2.1.2",
"js-base64": "^3.7.6",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
+6542 -8340
View File
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,48 @@
import { describe, expect, it } from 'vitest';
import { cidrInCidr } from './cidr-in-cidr.service';
describe('cidr-in-cidr', () => {
describe('cidrInCidr', () => {
it('should return correct inclusion', () => {
expect(cidrInCidr({ baseRange: '192.168.0.0/16', ipOrRangeToTest: '192.168.0.1' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.1.0/24', ipOrRangeToTest: '192.168.0.10' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.1.*', ipOrRangeToTest: '192.168.0.10' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.0.0/24', ipOrRangeToTest: '192.168.0.0/28' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.0/24', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.*', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.0.*', ipOrRangeToTest: '192.168.0.0/28' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.12' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.20' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.9-192.168.20.12' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.15', ipOrRangeToTest: '192.168.20.9-192.168.20.20' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.0-192.168.20.255', ipOrRangeToTest: '192.168.20.0/28' }).isIncluded).toBe(true); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.20.0-192.168.20.255', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(false); // NOSONAR
expect(cidrInCidr({ baseRange: '192.168.0.0-192.168.1.255', ipOrRangeToTest: '192.168.1.0/28' }).isIncluded).toBe(true); // NOSONAR
});
it('should return correct subnet', () => {
expect(cidrInCidr({ baseRange: '192.168.0.0/16', ipOrRangeToTest: '192.168.0.1' }).baseSubnets).to.deep.eq([ // NOSONAR
{
cidr: '192.168.0.0/16', // NOSONAR
end: '192.168.255.255', // NOSONAR
start: '192.168.0.0', // NOSONAR
},
]);
expect(cidrInCidr({ baseRange: '192.168.20.1-192.168.20.3', ipOrRangeToTest: '192.168.1.0/28' }).baseSubnets).to.deep.eq([ // NOSONAR
{
cidr: '192.168.20.1/32', // NOSONAR
end: '192.168.20.1', // NOSONAR
start: '192.168.20.1', // NOSONAR
},
{
cidr: '192.168.20.2/31', // NOSONAR
end: '192.168.20.3', // NOSONAR
start: '192.168.20.2', // NOSONAR
},
]);
});
});
});
@@ -0,0 +1,28 @@
import { getMatch } from 'ip-matching';
export function cidrInCidr(
{ baseRange, ipOrRangeToTest }:
{
baseRange: string
ipOrRangeToTest: string
}) {
const baseMatchMasks = getMatch(baseRange)?.convertToMasks() || [];
const ipOrRangeToTestMatchMasks = getMatch(ipOrRangeToTest)?.convertToMasks() || [];
const baseSubnets = baseMatchMasks.map((mask) => {
const subnet = mask.convertToSubnet();
if (!subnet) {
return { cidr: '', start: '', end: '' };
}
return {
cidr: subnet.toString(),
start: subnet.getFirst().toString(),
end: subnet.getLast().toString(),
};
}).filter(subnet => subnet.cidr !== '');
return {
baseSubnets,
isIncluded: baseMatchMasks.some(baseMask => ipOrRangeToTestMatchMasks.every(ipOrRangeMask => ipOrRangeMask.isSubsetOf(baseMask))),
};
}
+80
View File
@@ -0,0 +1,80 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core';
import { Check as CheckIcon, LetterX as CrossIcon } from '@vicons/tabler';
import { getMatch } from 'ip-matching';
import { cidrInCidr } from './cidr-in-cidr.service';
import { withDefaultOnError } from '@/utils/defaults';
import { isNotThrowing } from '@/utils/boolean';
import SpanCopyable from '@/components/SpanCopyable.vue';
const baseRange = useStorage('cidr-in-cidr:range', '192.168.0.1/24'); // NOSONAR
const ipOrRangeToTest = useStorage('cidr-in-cidr:ip', '192.168.0.1'); // NOSONAR
const matchResult = computed(() => withDefaultOnError(
() => cidrInCidr({ baseRange: baseRange.value, ipOrRangeToTest: ipOrRangeToTest.value }),
{ baseSubnets: [], isIncluded: false }));
const rangeValidationRules = [
{
message: 'We cannot parse this CIDR/IP Range/Mask/Wildcard, check the format',
validator: (value: string) => isNotThrowing(() => getMatch(value)) && getMatch(value),
},
];
</script>
<template>
<div>
<c-input-text
v-model:value="baseRange"
label="An IPv4/6 CIDR/Range/Mask/Wildcard (base network)"
placeholder="The ipv4/6 CIDR..."
:validation-rules="rangeValidationRules"
mb-4
/>
<c-input-text
v-model:value="ipOrRangeToTest"
label="An IPv4/6 CIDR/Range/Mask/Wildcard (to test for inclusion)"
placeholder="The An IPv4/6 CIDR/Range/Mask/Wildcard..."
:validation-rules="rangeValidationRules"
mb-4
/>
<n-divider />
<div flex justify-center>
<span v-if="matchResult.isIncluded">
<n-icon color="green">
<CheckIcon />
</n-icon>
Included
</span>
<span v-else>
<n-icon color="red">
<CrossIcon />
</n-icon>
Not included
</span>
</div>
<n-divider />
<c-card title="Subnets">
<n-table>
<tbody>
<tr v-for="{ cidr, start, end } in matchResult.baseSubnets" :key="cidr">
<td font-bold>
<SpanCopyable :value="cidr" />
</td>
<td>
<SpanCopyable :value="start" />
</td>
<td>
<SpanCopyable :value="end" />
</td>
</tr>
</tbody>
</n-table>
</c-card>
</div>
</template>
+13
View File
@@ -0,0 +1,13 @@
import { UnfoldMoreOutlined } from '@vicons/material';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'IPv4-6/IPRange/CIDR in IPRange/CIDR/IPMask',
path: '/cidr-in-cidr',
description: 'Given a CIDR/IP Range/Wildcard IP/IP Mask, tell if a given IPv4-6/Range/CIDR/Wildcard IP/IP Mask is in subnet range',
keywords: ['ip', 'cidr', 'range', 'mask', 'wildcard', 'ipv4', 'ipv6', 'subnet', 'include', 'inclusion'],
component: () => import('./cidr-in-cidr.vue'),
redirectFrom: ['/ip-in-range'],
icon: UnfoldMoreOutlined,
createdAt: new Date('2025-01-12'),
});
+10 -3
View File
@@ -2,7 +2,6 @@ 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 emailNormalizer } from './email-normalizer';
import { tool as weekNumberConverter } from './week-number-converter';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
@@ -87,6 +86,7 @@ import { tool as urlParser } from './url-parser';
import { tool as uuidGenerator } from './uuid-generator';
import { tool as macAddressLookup } from './mac-address-lookup';
import { tool as xmlFormatter } from './xml-formatter';
import { tool as cidrInCidr } from './cidr-in-cidr';
import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
@@ -117,7 +117,6 @@ export const toolsByCategory: ToolCategory[] = [
xmlToJson,
jsonToXml,
markdownToHtml,
weekNumberConverter,
],
},
{
@@ -166,7 +165,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
cidrInCidr,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
],
},
{
name: 'Math',
-12
View File
@@ -1,12 +0,0 @@
import { Calendar } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Week Numbers Converter',
path: '/week-number-converter',
description: 'Convert between ISO Week number, Week number in month and date',
keywords: ['week', 'month', 'number', 'iso', 'converter'],
component: () => import('./week-number-converter.vue'),
icon: Calendar,
createdAt: new Date('2024-08-15'),
});
@@ -1,20 +0,0 @@
import { describe, expect, it } from 'vitest';
import { getWeekOfMonth } from 'date-fns';
import { getFirstMondayFromISOWeek, getFirstMondayFromMonthWeek } from './week-number-converter.service';
describe('week-number-converter', () => {
describe('getFirstMondayFromISOWeek', () => {
it('return right monday date from week number', () => {
expect(getFirstMondayFromISOWeek(11, 2022).toDateString()).toBe('Mon Mar 14 2022');
expect(getFirstMondayFromISOWeek(1, 2023).toDateString()).toBe('Mon Jan 02 2023');
expect(getFirstMondayFromISOWeek(53, 2026).toDateString()).toBe('Mon Dec 28 2026');
});
});
describe('getFirstMondayFromMonthWeek', () => {
it('return right date from month week number', () => {
expect(getFirstMondayFromMonthWeek(getWeekOfMonth(new Date('2022-03-14')), 3, 2022).toDateString()).toBe('Mon Mar 14 2022');
expect(getFirstMondayFromMonthWeek(getWeekOfMonth(new Date('2023-01-02')), 1, 2023).toDateString()).toBe('Mon Jan 02 2023');
expect(getFirstMondayFromMonthWeek(getWeekOfMonth(new Date('2026-12-28')), 12, 2026).toDateString()).toBe('Mon Dec 28 2026');
});
});
});
@@ -1,15 +0,0 @@
// Returns the first day (Monday) of the specified week
// Year defaults to the current local calendar year
export function getFirstMondayFromISOWeek(weekInYear: number, year = new Date().getFullYear()) {
const d = new Date(year, 0, 4);
d.setDate(d.getDate() - (d.getDay() || 7) + 1 + 7 * (weekInYear - 1));
return d;
}
export function getFirstMondayFromMonthWeek(weekInMonth: number, month = new Date().getMonth() + 1, year = new Date().getFullYear()) {
const d = new Date(year, month - 1, 4);
const day = d.getDay() || 7;
d.setDate(d.getDate() - day + 1);
d.setDate(d.getDate() + 7 * (weekInMonth - 1));
return d;
}
@@ -1,71 +0,0 @@
<script setup lang="ts">
import { getISOWeek, getWeek, getWeekOfMonth } from 'date-fns';
import { getFirstMondayFromISOWeek, getFirstMondayFromMonthWeek } from './week-number-converter.service';
const now = new Date();
const inputDate = ref(now.getTime());
const outputWeekInMonth = computed(() => getWeekOfMonth(inputDate.value));
const outputLocalWeekInYear = computed(() => getWeek(inputDate.value));
const outputISOWeekInYear = computed(() => getISOWeek(inputDate.value));
const inputWeekInMonth = ref({
week: getWeekOfMonth(now),
month: now.getMonth() + 1,
year: now.getFullYear(),
});
const outputWeekInMonthMonday = computed(() => getFirstMondayFromMonthWeek(inputWeekInMonth.value.week, inputWeekInMonth.value.month, inputWeekInMonth.value.year));
const inputWeekInYear = ref({
week: getWeek(now),
year: now.getFullYear(),
});
const outputWeekInYearMonday = computed(() => getFirstMondayFromISOWeek(inputWeekInYear.value.week, inputWeekInYear.value.year));
</script>
<template>
<div>
<c-card title="Date to Week numbers" mb-2>
<n-form-item label="Date:" label-placement="left">
<n-date-picker v-model:value="inputDate" type="date" />
</n-form-item>
<n-divider />
<input-copyable readonly label="Local Week in Year:" label-position="left" label-width="130px" :value="outputLocalWeekInYear" mb-1 />
<input-copyable readonly label="ISO Week (in Year):" label-position="left" label-width="130px" :value="outputISOWeekInYear" mb-1 />
<input-copyable readonly label="Week in Month:" label-position="left" label-width="130px" :value="outputWeekInMonth" mb-1 />
</c-card>
<c-card title="ISO Week number to date" mb-2>
<div flex items-baseline gap-2>
<n-form-item label="ISO Week number:" label-placement="left" flex-1>
<n-input-number v-model:value="inputWeekInYear.week" :min="1" :max="53" />
</n-form-item>
<n-form-item label="Year:" label-placement="left" flex-1>
<n-input-number v-model:value="inputWeekInYear.year" />
</n-form-item>
</div>
<n-divider />
<input-copyable readonly label="First Monday" label-position="left" :value="outputWeekInYearMonday" />
</c-card>
<c-card title="Week number in month to date" mb-2>
<div flex items-baseline gap-2>
<n-form-item label="Week in month:" label-placement="left" flex-1>
<n-input-number v-model:value="inputWeekInMonth.week" :min="1" :max="5" />
</n-form-item>
<n-form-item label="Month:" label-placement="left" flex-1>
<n-input-number v-model:value="inputWeekInMonth.month" :min="1" :max="12" />
</n-form-item>
<n-form-item label="Year:" label-placement="left" flex-1>
<n-input-number v-model:value="inputWeekInMonth.year" />
</n-form-item>
</div>
<n-divider />
<input-copyable readonly label="First Monday" label-position="left" :value="outputWeekInMonthMonday" />
</c-card>
</div>
</template>