mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
Merge 84d0f7fd53
into d3b32cc14e
This commit is contained in:
commit
90189e1b99
6 changed files with 130 additions and 1 deletions
1
components.d.ts
vendored
1
components.d.ts
vendored
|
@ -106,6 +106,7 @@ declare module '@vue/runtime-core' {
|
||||||
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.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']
|
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
|
||||||
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
|
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
|
||||||
|
IsbnValidatorAndParser: typeof import('./src/tools/isbn-validator-and-parser/isbn-validator-and-parser.vue')['default']
|
||||||
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']
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
"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",
|
||||||
|
"isbn3": "^1.1.44",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"libphonenumber-js": "^1.10.28",
|
"libphonenumber-js": "^1.10.28",
|
||||||
|
|
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
|
@ -92,6 +92,9 @@ dependencies:
|
||||||
ibantools:
|
ibantools:
|
||||||
specifier: ^4.3.3
|
specifier: ^4.3.3
|
||||||
version: 4.3.3
|
version: 4.3.3
|
||||||
|
isbn3:
|
||||||
|
specifier: ^1.1.44
|
||||||
|
version: 1.1.45
|
||||||
json5:
|
json5:
|
||||||
specifier: ^2.2.3
|
specifier: ^2.2.3
|
||||||
version: 2.2.3
|
version: 2.2.3
|
||||||
|
@ -6434,6 +6437,12 @@ packages:
|
||||||
resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==}
|
resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/isbn3@1.1.45:
|
||||||
|
resolution: {integrity: sha512-9oD3yItVFRlYhm/K6RI2K6f+Dti0unzG74X9I7D+xVKMK3TbRl2PMvnWgK6scKnvk4t0BZFyNIznX4H45RrwzQ==}
|
||||||
|
engines: {node: '>= 6.4.0'}
|
||||||
|
hasBin: true
|
||||||
|
dev: false
|
||||||
|
|
||||||
/isexe@2.0.0:
|
/isexe@2.0.0:
|
||||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
|
@ -80,6 +80,7 @@ import { tool as urlParser } from './url-parser';
|
||||||
import { tool as uuidGenerator } from './uuid-generator';
|
import { tool as uuidGenerator } from './uuid-generator';
|
||||||
import { tool as macAddressLookup } from './mac-address-lookup';
|
import { tool as macAddressLookup } from './mac-address-lookup';
|
||||||
import { tool as xmlFormatter } from './xml-formatter';
|
import { tool as xmlFormatter } from './xml-formatter';
|
||||||
|
import { tool as isbnValidatorAndParser } from './isbn-validator-and-parser';
|
||||||
import { tool as yamlViewer } from './yaml-viewer';
|
import { tool as yamlViewer } from './yaml-viewer';
|
||||||
|
|
||||||
export const toolsByCategory: ToolCategory[] = [
|
export const toolsByCategory: ToolCategory[] = [
|
||||||
|
@ -176,7 +177,11 @@ export const toolsByCategory: ToolCategory[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Data',
|
name: 'Data',
|
||||||
components: [phoneParserAndFormatter, ibanValidatorAndParser],
|
components: [
|
||||||
|
phoneParserAndFormatter,
|
||||||
|
ibanValidatorAndParser,
|
||||||
|
isbnValidatorAndParser,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
12
src/tools/isbn-validator-and-parser/index.ts
Normal file
12
src/tools/isbn-validator-and-parser/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { Books } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'ISBN Validator and Parser',
|
||||||
|
path: '/isbn-validator-and-parser',
|
||||||
|
description: 'Parse, validate, format and get infos for an ISBN',
|
||||||
|
keywords: ['isbn', 'validator', 'parser', 'formatter'],
|
||||||
|
component: () => import('./isbn-validator-and-parser.vue'),
|
||||||
|
icon: Books,
|
||||||
|
createdAt: new Date('2024-01-10'),
|
||||||
|
});
|
|
@ -0,0 +1,101 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import ISBN3 from 'isbn3';
|
||||||
|
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
|
||||||
|
|
||||||
|
const rawIsbn = ref('9782021304534');
|
||||||
|
|
||||||
|
const isbnInfos = computed<CKeyValueListItems>(() => {
|
||||||
|
const isbn = ISBN3.parse(rawIsbn.value);
|
||||||
|
|
||||||
|
if (isbn == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Is ISBN valid ?',
|
||||||
|
value: isbn.isValid,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Country',
|
||||||
|
value: isbn.groupname,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ISBN 13',
|
||||||
|
value: isbn.isbn13,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ISBN 13 Formatted',
|
||||||
|
value: isbn.isbn13h,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ISBN 10',
|
||||||
|
value: isbn.isbn10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ISBN 10 Formatted',
|
||||||
|
value: isbn.isbn10h,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
function isbnChecksum(isbn: string) {
|
||||||
|
let check = 0;
|
||||||
|
|
||||||
|
if (isbn.length === 9) {
|
||||||
|
for (let n = 0; n < 9; n += 1) {
|
||||||
|
check += (10 - n) * Number(isbn.charAt(n));
|
||||||
|
}
|
||||||
|
check = (11 - check % 11) % 11;
|
||||||
|
return check === 10 ? 'X' : String(check);
|
||||||
|
}
|
||||||
|
else if (isbn.length === 12) {
|
||||||
|
for (let n = 0; n < 12; n += 2) {
|
||||||
|
check += Number(isbn.charAt(n)) + 3 * Number(isbn.charAt(n + 1));
|
||||||
|
}
|
||||||
|
return String((10 - check % 10) % 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedISBN = computed(() => {
|
||||||
|
let normalized = rawIsbn.value.replace(/[^\dX]/g, '');
|
||||||
|
if (normalized.length >= 13) {
|
||||||
|
normalized = normalized.substring(0, 12);
|
||||||
|
}
|
||||||
|
else if (normalized.length >= 10) {
|
||||||
|
normalized = normalized.substring(0, 9);
|
||||||
|
}
|
||||||
|
const checksum = isbnChecksum(normalized);
|
||||||
|
return ISBN3.parse(`${normalized}${checksum}`)?.isbn13h;
|
||||||
|
});
|
||||||
|
|
||||||
|
const isbnAuditInfos = computed<{ isValid: boolean; clues: CKeyValueListItems }>(() => {
|
||||||
|
const isbn = ISBN3.audit(rawIsbn.value);
|
||||||
|
|
||||||
|
const isValid = (isbn?.validIsbn ?? false);
|
||||||
|
return {
|
||||||
|
isValid,
|
||||||
|
clues: Array.from((isbn?.clues ?? []),
|
||||||
|
clue => ({ label: `${clue.message} (${clue.groupname})`, value: clue.candidate })),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-input-text v-model:value="rawIsbn" placeholder="Enter an ISBN to check for validity..." test-id="isbn-input" />
|
||||||
|
<n-alert v-if="!isbnAuditInfos.isValid" type="error">
|
||||||
|
Invalid ISBN.
|
||||||
|
<input-copyable v-if="normalizedISBN" label="Probably correct" label-position="left" :value="normalizedISBN" disabled="true" />
|
||||||
|
</n-alert>
|
||||||
|
|
||||||
|
<c-card v-if="isbnInfos.length > 0" mt-5 title="ISBN Infos">
|
||||||
|
<c-key-value-list :items="isbnInfos" data-test-id="isbn-info" />
|
||||||
|
</c-card>
|
||||||
|
<c-card v-if="isbnAuditInfos.clues.length > 0" mt-5 title="ISBN Audit Infos">
|
||||||
|
<c-key-value-list :items="isbnAuditInfos" data-test-id="isbn-info" />
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Add table
Add a link
Reference in a new issue