Skip to content

Commit 98c50f0

Browse files
committed
feat(new tool): Luhn Checker
Check kuhn identifiers
1 parent 318fb6e commit 98c50f0

File tree

6 files changed

+84
-15
lines changed

6 files changed

+84
-15
lines changed

components.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ declare module '@vue/runtime-core' {
119119
ListConverter: typeof import('./src/tools/list-converter/list-converter.vue')['default']
120120
LocaleSelector: typeof import('./src/modules/i18n/components/locale-selector.vue')['default']
121121
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
122+
LuhnValidator: typeof import('./src/tools/luhn-validator/luhn-validator.vue')['default']
122123
MacAddressGenerator: typeof import('./src/tools/mac-address-generator/mac-address-generator.vue')['default']
123124
MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default']
124125
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']
@@ -128,23 +129,17 @@ declare module '@vue/runtime-core' {
128129
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
129130
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
130131
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
132+
NAlert: typeof import('naive-ui')['NAlert']
131133
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
132-
NCode: typeof import('naive-ui')['NCode']
133134
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
134135
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
135136
NEllipsis: typeof import('naive-ui')['NEllipsis']
136-
NForm: typeof import('naive-ui')['NForm']
137-
NFormItem: typeof import('naive-ui')['NFormItem']
138137
NH1: typeof import('naive-ui')['NH1']
139138
NH3: typeof import('naive-ui')['NH3']
140139
NIcon: typeof import('naive-ui')['NIcon']
141-
NInputNumber: typeof import('naive-ui')['NInputNumber']
142140
NLayout: typeof import('naive-ui')['NLayout']
143141
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
144142
NMenu: typeof import('naive-ui')['NMenu']
145-
NScrollbar: typeof import('naive-ui')['NScrollbar']
146-
NSlider: typeof import('naive-ui')['NSlider']
147-
NSwitch: typeof import('naive-ui')['NSwitch']
148143
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
149144
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
150145
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"jwt-decode": "^3.1.2",
7171
"libphonenumber-js": "^1.10.28",
7272
"lodash": "^4.17.21",
73+
"luhn-js": "^1.1.2",
7374
"marked": "^10.0.0",
7475
"mathjs": "^11.9.1",
7576
"mime-types": "^2.1.35",

pnpm-lock.yaml

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
22
import { tool as base64StringConverter } from './base64-string-converter';
33
import { tool as basicAuthGenerator } from './basic-auth-generator';
44
import { tool as emailNormalizer } from './email-normalizer';
5+
import { tool as luhnValidator } from './luhn-validator';
56

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

@@ -182,7 +183,11 @@ export const toolsByCategory: ToolCategory[] = [
182183
},
183184
{
184185
name: 'Data',
185-
components: [phoneParserAndFormatter, ibanValidatorAndParser],
186+
components: [
187+
phoneParserAndFormatter,
188+
ibanValidatorAndParser,
189+
luhnValidator,
190+
],
186191
},
187192
];
188193

src/tools/luhn-validator/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Check } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Luhn Validator',
6+
path: '/luhn-validator',
7+
description: 'Check and generate key for identifier validated by a Luhn checknum',
8+
keywords: ['luhn', 'credit-card', 'imei', 'identifier', 'validator'],
9+
component: () => import('./luhn-validator.vue'),
10+
icon: Check,
11+
createdAt: new Date('2024-08-15'),
12+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script setup lang="ts">
2+
import Luhn from 'luhn-js';
3+
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
4+
5+
const rawValue = ref('44540661970241257');
6+
const cleanedValue = computed(() => rawValue.value.replace(/[^\d]/g, ''));
7+
const isValid = computed(() => {
8+
try {
9+
return Luhn.isValid(cleanedValue.value);
10+
}
11+
catch (_) {
12+
return false;
13+
}
14+
});
15+
const luhnInfos = computed<CKeyValueListItems>(() => {
16+
return [
17+
{
18+
label: 'Is valid ?',
19+
value: isValid.value,
20+
},
21+
{
22+
label: 'Luhn Key',
23+
value: (isValid.value
24+
? cleanedValue.value.slice(-1)
25+
: Luhn.generate(cleanedValue.value).slice(-1)) || '',
26+
},
27+
{
28+
label: 'Value with Luhn Key',
29+
value: (isValid.value
30+
? cleanedValue.value
31+
: Luhn.generate(cleanedValue.value)) || '',
32+
},
33+
];
34+
});
35+
</script>
36+
37+
<template>
38+
<div>
39+
<c-input-text v-model:value="rawValue" placeholder="Enter a 'Luhn validated' value..." />
40+
<n-alert v-if="!isValid" type="error">
41+
Invalid Luhn Key.
42+
<input-copyable label="Probably correct" label-position="left" :value="Luhn.generate(cleanedValue)" disabled="true" />
43+
</n-alert>
44+
45+
<c-card v-if="luhnInfos.length > 0" mt-5 title="Infos">
46+
<c-key-value-list :items="luhnInfos" />
47+
</c-card>
48+
</div>
49+
</template>

0 commit comments

Comments
 (0)