Merge branch 'feat/luhn-checker' into chore/all-my-stuffs

# Conflicts:
#	package.json
#	pnpm-lock.yaml
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 21:00:41 +01:00
commit 48a51cbfd9
5 files changed
+76 -2

No files matched your search

+1
View File
@@ -144,6 +144,7 @@
"libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21",
"luxon": "^3.5.0",
"luhn-js": "^1.1.2",
"markdown-it": "^14.0.0",
"lodash.defaultsdeep": "^4.6.1",
"lodash.flattendeep": "^4.4.0",
+8 -1
View File
@@ -299,6 +299,9 @@ dependencies:
lorem-ipsum-japanese:
specifier: ^1.0.1
version: 1.0.1
luhn-js:
specifier: ^1.1.2
version: 1.1.2
luxon:
specifier: ^3.5.0
version: 3.5.0
@@ -4973,7 +4976,7 @@ packages:
/@vueuse/shared@10.0.0(vue@3.3.4):
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
dependencies:
vue-demi: 0.14.10(vue@3.3.4)
vue-demi: 0.14.5(vue@3.3.4)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
@@ -8931,6 +8934,10 @@ packages:
dependencies:
yallist: 4.0.0
/luhn-js@1.1.2:
resolution: {integrity: sha512-GdINoHY50s4Zkhvmt6Pss/8ZwVxIOLsMHuJCg6EDcT1heSt4hM2V+7aKCihemn8rI0n22+lxqomzgvWDzMyEuQ==}
dev: false
/luxon@3.5.0:
resolution: {integrity: sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==}
engines: {node: '>=12'}
+6 -1
View File
@@ -24,6 +24,7 @@ import { tool as jsonToPhpArray } from './json-to-php-array';
import { tool as phpArrayToJson } from './php-array-to-json';
import { tool as jsonSizeAnalyzer } from './json-size-analyzer';
import { tool as jsonToCsharp } from './json-to-csharp';
import { tool as luhnValidator } from './luhn-validator';
import { tool as cssXpathConverter } from './css-xpath-converter';
import { tool as cssSelectorsMemo } from './css-selectors-memo';
@@ -316,7 +317,11 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Data',
components: [phoneParserAndFormatter, ibanValidatorAndParser],
components: [
phoneParserAndFormatter,
ibanValidatorAndParser,
luhnValidator,
],
},
];
+12
View File
@@ -0,0 +1,12 @@
import { Check } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Luhn Validator',
path: '/luhn-validator',
description: 'Check and generate key for identifier validated by a Luhn checknum',
keywords: ['luhn', 'credit-card', 'imei', 'identifier', 'validator'],
component: () => import('./luhn-validator.vue'),
icon: Check,
createdAt: new Date('2024-08-15'),
});
@@ -0,0 +1,49 @@
<script setup lang="ts">
import Luhn from 'luhn-js';
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
const rawValue = ref('44540661970241257');
const cleanedValue = computed(() => rawValue.value.replace(/[^\d]/g, ''));
const isValid = computed(() => {
try {
return Luhn.isValid(cleanedValue.value);
}
catch (_) {
return false;
}
});
const luhnInfos = computed<CKeyValueListItems>(() => {
return [
{
label: 'Is valid ?',
value: isValid.value,
},
{
label: 'Luhn Key',
value: (isValid.value
? cleanedValue.value.slice(-1)
: Luhn.generate(cleanedValue.value).slice(-1)) || '',
},
{
label: 'Value with Luhn Key',
value: (isValid.value
? cleanedValue.value
: Luhn.generate(cleanedValue.value)) || '',
},
];
});
</script>
<template>
<div>
<c-input-text v-model:value="rawValue" placeholder="Enter a 'Luhn validated' value..." />
<n-alert v-if="!isValid" type="error">
Invalid Luhn Key.
<input-copyable label="Probably correct" label-position="left" :value="Luhn.generate(cleanedValue)" disabled="true" />
</n-alert>
<c-card v-if="luhnInfos.length > 0" mt-5 title="Infos">
<c-key-value-list :items="luhnInfos" />
</c-card>
</div>
</template>