npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lytrax/afm

v1.0.1

Published

Greek AFM (TIN) validator and generator

Downloads

177

Readme

Greek TIN/AFM Validator and Generator

Linux Build Status tested with jest NPM

Logo

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 a boolean or ValidateAFMExtendedResult
  • Returns: boolean or ValidateAFMExtendedResult

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