Narcissistic Passion Minified
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

finnish-business-ids

2.0.1 • Public • Published

Finnish business id and vat number validator/generator

Build Status 0 deps Downloads License

  • A micro library for validating and creating Finnish business ids (y-tunnus, alv-numero)
  • Lightweight, 4.3kB
  • No dependencies
  • ES6 + Babel for compatibility

Installation

# NPM 
npm install finnish-business-ids
 
# Bower 
bower install finnish-business-ids

Usage

Node.js

const FinnishBusinessIds = require('finnish-business-ids')
FinnishBusinessIds.isValidBusinessId('2617416-4')

Browser: Writes FinnishBusinessIds into global namespace.

<script src="finnish-business-ids.min.js"></script>
<script>
  FinnishBusinessIds.isValidBusinessId('2617416-4')
</script> 
 

Examples

# Valid isValidVatNumber returns true, allows whitespace 
FinnishBusinessIds.isValidBusinessId('2617416-4')
// true
FinnishBusinessIds.isValidVatNumber('FI26174164')
// true
# Generate a Finnish business id (y-tunnus), format: 1234567-8 
FinnishBusinessIds.generateBusinessId()
// '2617416-4'
 
# Generate a Finnish vat number (alv-numero), format: FI12345678 
FinnishBusinessIds.generateVatNumber()
// 'FI26174164'

Functions

  • Validation functions return TypeError when unexpected type is passed as a parameter.
  • Using Flow annotations for static type checking
isValidBusinessId(businessId: string) : string --> boolean

-Validates parameter given business id (y-tunnus), format: 1234567-8 -A TypeError is thrown in case of non-string parameter

isValidVatNumber(vatNumber: string) : string --> boolean

-Validates parameter given Finnish vat number (alv-numero), format: FI12345678 -A TypeError is thrown in case of non-string parameter

generateBusinessId() : void --> string

-Generates a random Finnish business id

generateVatNumber() : void --> string

-Generates a random Finnish vat number

calculateChecksum(idNumbers: string) : string --> number

-Calculates checksum for parameter given business id without checksum, format: 1234567 -A TypeError is thrown in case of non-string parameter

Changelog

CHANGELOG

Building

# Build a distributable, minified UMD library compatible with browsers and Node 
npm run dist
 
# Run static type checkts using flow 
npm run flow
 
# Run tests 
npm run test

License

MIT License

install

npm i finnish-business-ids

Downloadsweekly downloads

152

version

2.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar