mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 07:04:39 +03:00
Merge branch 'feat/isbn-formatter' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
d22e0d60d1
5 files changed
+126
No files matched your search
@@ -217,6 +217,7 @@
|
|||||||
"ip-cidr": "^4.0.0",
|
"ip-cidr": "^4.0.0",
|
||||||
"is-cidr": "^5.0.3",
|
"is-cidr": "^5.0.3",
|
||||||
"is-ip": "^5.0.1",
|
"is-ip": "^5.0.1",
|
||||||
|
"isbn3": "^1.1.44",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"jsonpath": "^1.1.1",
|
"jsonpath": "^1.1.1",
|
||||||
"jsonar-mod": "^1.9.0",
|
"jsonar-mod": "^1.9.0",
|
||||||
|
|||||||
Generated
+10
@@ -365,6 +365,9 @@ dependencies:
|
|||||||
is-ip:
|
is-ip:
|
||||||
specifier: ^5.0.1
|
specifier: ^5.0.1
|
||||||
version: 5.0.1
|
version: 5.0.1
|
||||||
|
isbn3:
|
||||||
|
specifier: ^1.1.44
|
||||||
|
version: 1.2.3
|
||||||
iso-639-1:
|
iso-639-1:
|
||||||
specifier: ^3.1.3
|
specifier: ^3.1.3
|
||||||
version: 3.1.3
|
version: 3.1.3
|
||||||
@@ -10693,6 +10696,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==}
|
resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/isbn3@1.2.3:
|
||||||
|
resolution: {integrity: sha512-3X3N1G7ThWYFdrnoMAuy/aRdA9Pk7jksa8LQMAhPm1TXrWji2MiggsDbuT6QBmpF/j5dAdbO0CGA67Ks/YSr+A==}
|
||||||
|
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==}
|
||||||
|
|
||||||
@@ -10924,6 +10933,7 @@ packages:
|
|||||||
/jsesc@2.5.2:
|
/jsesc@2.5.2:
|
||||||
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
|
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
/jsesc@3.0.2:
|
/jsesc@3.0.2:
|
||||||
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
|
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ import { tool as powerConverter } from './power-converter';
|
|||||||
import { tool as dockerComposeConverter } from './docker-compose-converter';
|
import { tool as dockerComposeConverter } from './docker-compose-converter';
|
||||||
import { tool as imageExifReader } from './image-exif-reader';
|
import { tool as imageExifReader } from './image-exif-reader';
|
||||||
import { tool as ipInRange } from './ip-in-range';
|
import { tool as ipInRange } from './ip-in-range';
|
||||||
|
import { tool as isbnValidatorAndParser } from './isbn-validator-and-parser';
|
||||||
import { tool as yamlViewer } from './yaml-viewer';
|
import { tool as yamlViewer } from './yaml-viewer';
|
||||||
import { tool as barcodeReader } from './barcode-reader';
|
import { tool as barcodeReader } from './barcode-reader';
|
||||||
import { tool as barcodeGenerator } from './barcode-generator';
|
import { tool as barcodeGenerator } from './barcode-generator';
|
||||||
@@ -506,6 +507,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
luhnValidator,
|
luhnValidator,
|
||||||
vatValidator,
|
vatValidator,
|
||||||
airCodes,
|
airCodes,
|
||||||
|
isbnValidatorAndParser,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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>
|
||||||
Reference in new issue
Block a user