- A micro Javascript library for validating and generating Swiss National Identification Number.
- Lightweight
- No dependencies
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>
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>
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));
- Validates parameter given SSN. Returns true if SSN is valid, otherwise false
- Generates a random SSN. Returns formatted: '756.9217.0769.88'
# Build a distributable, minified UMD library compatible with browsers and Node
npm run dist
# Run tests
npm run test
- Dependencies upgraded because of security problems.
- Initial release