@lytrax/afm
v1.0.1
Published
Greek AFM (TIN) validator and generator
Downloads
177
Readme
Greek TIN/AFM Validator and Generator
Validate and generate Greek TIN (Tax Identification Number) / AFM (Αριθμός Φορολογικού Μητρώου). Generation function can create valid or invalid numbers including parameters for old format, individuals, legal entities and repet tolerance digits control.
Online demo and presentation
https://lytrax.io/blog/projects/greek-tin-validator-generator
Installation
Install @lytrax/afm
using npm
:
npm install @lytrax/afm
Or yarn
:
yarn add @lytrax/afm
Usage
Import or require (ESM, CJS):
// ESM
import {
validateAFM,
generateAFM,
generateValidAFM,
generateInvalidAFM
} from '@lytrax/afm';
// CJS
const {
validateAFM,
generateAFM,
generateValidAFM,
generateInvalidAFM
} = require('@lytrax/afm');
For browsers (UMD), download latest release from releases, or browse JSDeliver CDN to pick the latest version and then include the script file:
// UMD (Browsers)
<script src="https://cdn.jsdelivr.net/npm/@lytrax/afm@latest/dist/lytrax-afm.min.js"></script>
Validate a number:
> validateAFM('090000045')
< true
> validateAFM('123456789')
< false
Generate a valid number:
> generateValidAFM()
< "731385437"
Generate an invalid number:
> generateInvalidAFM()
< "853003357"
API
validateAFM (afm, [{ extendedResult = false }])
afm: string
- A number to be checked[params: object]
- Optional object for named parameters[params.extendedResult: boolean = false]
- Return aboolean
orValidateAFMExtendedResult
- Returns:
boolean
orValidateAFMExtendedResult
Example:
> validateAFM('ab1234', { extendedResult: true })
< {valid: false, error: "length"}
generateAFM ([{
forceFirstDigit,
pre99 = false,
individual = false,
legalEntity = false,
repeatTolerance,
valid = true
}])
[params: object]
- Optional object for named parameters[params.forceFirstDigit: null|number]
- If specified, overrides all pre99, legalEntity and individual[params.pre99: boolean = false]
- Για ΑΦΜ πριν από 1/1/1999 (ξεκινάει με 0), (if true, overrides both legalEntity and individual)[params.individual: boolean = false]
- Φυσικά πρόσωπα, (ξεκινάει με 1-4)[params.legalEntity: boolean = false]
- Νομικές οντότητες (ξεκινάει με 7-9)[params.repeatTolerance: null|number]
- Number for max repeat tolerance (0 for no repeats, unspecified for no check)[params.valid: boolean = true]
- Generate valid or invalid AFM- Returns:
string
- A valid or invalid 9 digit AFM number
Example:
> generateAFM({ forceFirstDigit: 3, repeatTolerance: 1, valid: true })
< "335151580"
generateValidAFM - Same as generateAFM
with params.valid
force and override to true
- Returns:
string
- A valid 9 digit AFM number
Example:
> generateValidAFM({ pre99: true })
< "070825250"
generateInvalidAFM - Same as generateAFM
with params.valid
force and override to false
- Returns:
string
- An invalid 9 digit AFM number
Example:
> generateInvalidAFM({ legalEntity: true })
< "877577341"
Object result typedef ValidateAFMExtendedResult
- Property
valid: boolean
- Whether the AFM number is valid or not. - Property
error: 'length' or 'nan' or 'zero' or 'invalid'
Test
Clone this repository, intall modules and run test:
git clone https://github.com/clytras/afm-es.git && cd afm-es
npm install
npm run test
Changelog
See CHANGELOG
License
MIT License - see the LICENSE file for details