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 🙏

© 2026 – Pkg Stats / Ryan Hefner

swedish-ssn-tool

v1.0.3

Published

Small utility for validating and generating Swedish social security number.

Readme

Swedish Personal Number or Swedish Social Security Number Validation and Generation

A modern JavaScript library for validating and generating Swedish Personal Numbers (Social Security Numbers).

npm version License: GPL

Features

  • 🔍 Validate Swedish Personal Numbers
  • 🎲 Generate valid random SSNs
  • 👥 Generate SSNs with specific gender
  • 📅 Support for both YY and YYYY date formats
  • 0️⃣ Zero dependencies
  • 🌐 Works in Node.js and browsers
  • 📦 Modern ES modules and UMD builds

Installation

# Using npm
npm install swedish-ssn-tool

# Using yarn
yarn add swedish-ssn-tool

# Using pnpm
pnpm add swedish-ssn-tool

Usage

ES Modules (Recommended)

import SwedishSSN from 'swedish-ssn-tool';

// Validate an SSN
const isValid = SwedishSSN.validate('870430-2713');
console.log(isValid); // true

// Generate a random SSN
const randomSSN = SwedishSSN.generateRandomSSN();
console.log(randomSSN); // e.g., '901224-1234'

// Generate SSN for specific gender and date
const femaleSSN = SwedishSSN.generateSSNWithParameters(
  new Date('1990-12-24'), 
  'female'
);

Browser (UMD)

<script src="https://unpkg.com/swedish-ssn-tool/dist/swedish-ssn.min.js"></script>
<script>
  // Library is available as global SwedishSSN
  const isValid = SwedishSSN.validate('20870430-2713');
  console.log(isValid); // true
</script>

API Reference

validate(ssn: string): boolean

Validates a Swedish SSN. Returns true if valid, false otherwise.

SwedishSSN.validate('870430-2713');  // true
SwedishSSN.validate('20870430-2713'); // true (YYYY format)
SwedishSSN.validate('invalid');       // false

generateRandomSSN(): string

Generates a random valid Swedish SSN.

const ssn = SwedishSSN.generateRandomSSN();
// Returns formatted SSN like '870430-2713'

generateSSNWithParameters(birthdate: Date, gender?: 'male' | 'female'): string

Generates a valid SSN with specified parameters.

// Generate female SSN
const femaleSSN = SwedishSSN.generateSSNWithParameters(
  new Date('1987-04-30'), 
  'female'
);

// Generate male SSN
const maleSSN = SwedishSSN.generateSSNWithParameters(
  new Date('1987-04-30'), 
  'male'
);

// Generate random gender SSN
const randomSSN = SwedishSSN.generateSSNWithParameters(
  new Date('1987-04-30')
);

Development

# Install dependencies
npm install

# Run tests
npm test

# Build distribution files
npm run build

# Lint code
npm run lint

# Format code
npm run format

Format Specification

Swedish Personal Numbers follow this format:

  • YYMMDD-XXXX (10 digits)
  • YYYYMMDD-XXXX (12 digits)

Where:

  • YY/YYYY = Year
  • MM = Month
  • DD = Day
  • XXXX = Four digit sequence where last digit is a checksum
  • The second to last digit indicates gender (even for female, odd for male)

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

GPL License

Author

teaddict - GitHub

Changelog

1.0.3

  • Update package and simplify build process

1.0.2

  • Modernized build system with Rollup
  • Added ESM module support
  • Improved testing setup
  • Added TypeScript types
  • Enhanced documentation

1.0.1

  • Bug fixes and improvements

1.0.0

  • Initial release