Skip to content

Commit

Permalink
feat(new tool): Luhn Checker
Browse files Browse the repository at this point in the history
Check kuhn identifiers
  • Loading branch information
sharevb committed Sep 28, 2024
1 parent 318fb6e commit 04cfe12
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 luhnValidator } from './luhn-validator';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -182,7 +183,11 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Data',
components: [phoneParserAndFormatter, ibanValidatorAndParser],
components: [
phoneParserAndFormatter,
ibanValidatorAndParser,
luhnValidator,
],
},
];

Expand Down
12 changes: 12 additions & 0 deletions src/tools/luhn-validator/index.ts
Original file line number Diff line number Diff line change
@@ -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'),
});
36 changes: 36 additions & 0 deletions src/tools/luhn-validator/luhn-validator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
import Luhn from 'luhn-js';

Check failure on line 2 in src/tools/luhn-validator/luhn-validator.vue

View workflow job for this annotation

GitHub Actions / ci

Cannot find module 'luhn-js' or its corresponding type declarations.
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
const rawValue = ref('44540661970241257');
const luhnInfos = computed<CKeyValueListItems>(() => {
return [
{
label: 'Is valid ?',
value: Luhn.isValid(rawValue.value),
},
{
label: 'Luhn Key',
value: Luhn.getRemainder(rawValue.value),
},
{
label: 'Value with Luhn Key',
value: Luhn.generate(rawValue.value),
},
];
});
</script>

<template>
<div>
<c-input-text v-model:value="rawValue" placeholder="Enter a 'Luhn validated' value..." />
<n-alert v-if="!Luhn.isValid()" type="error">
Invalid Luhn Key.
<input-copyable label="Probably correct" label-position="left" :value="Luhn.generate(rawValue)" 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>

0 comments on commit 04cfe12

Please sign in to comment.