swiss-ssn
v1.0.1
Published
Small utility for validating and generating Swiss national identification number.
Downloads
522
Maintainers
Readme
Swiss National Identification Number (AHV/AVS) or (SSN) validation and generation
- A micro Javascript library for validating and generating Swiss National Identification Number.
- Lightweight
- No dependencies
Installation
NPM
npm install swiss-ssn
Bower
bower install swiss-ssn
From unpkg.com
<script src="https://unpkg.com/swiss-ssn/dist/swiss-ssn.min.js"></script>
Usage
ES6
import SwissSSN from "../swiss-ssn"
const isValid = SwissSSN.validate('756.9217.0769.85');
console.log(isValid);
// result true
Using global namespace.
<script src="https://unpkg.com/swiss-ssn/swiss-ssn.min.js"></script>
<script>
// This is valid SSN
var isValid = SwissSSN.validate('756.9217.0769.85');
console.log(isValid);
// result true
</script>
Examples
Validate SSN
// This is valid Swiss SSN
console.log('valid ssn returns ' + SwissSSN.validate('756.9217.0769.85'));
// 'valid ssn returns true'
// This is invalid Swiss SSN
console.log('invalid ssn returns ' + SwissSSN.validate('756.9217.0769.88'));
// 'invalid ssn returns false'
Generate SSN
// generate a random SSN
var fakeSSN = SwissSSN.generateSSN();
// now validate it
console.log('Is ssn valid: ' + SwissSSN.validate(fakeSSN));
Functions
#validate(ssn)
- Validates parameter given SSN. Returns true if SSN is valid, otherwise false
#generate()
- Generates a random SSN. Returns formatted: '756.9217.0769.88'
Building
# Build a distributable, minified UMD library compatible with browsers and Node
npm run dist
# Run tests
npm run test
Test Online
Changelog
1.0.0
- Initial release