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

sni-codes-utils

v1.0.1

Published

A npm package designed for working with Swedish SNI (Standard för Svensk Näringsgrensindelning) codes.

Downloads

12

Readme

Sni-Codes-Utils

Push and Pull Request CI

sni-codes-utils is an utility package for working with SNI (Svensk Näringsgrensindelning).

It provides fast search capabilities through an indexed search and fuzzy matching fallback using Fuse.js, along with functions for validating, searching, and retrieving SNI codes.

The package also includes support for debounced autocomplete.

Features

  • Validate SNI Codes: Easily check if an SNI code is valid.
  • Fast Search: Search through SNI codes using an optimized keyword index.
  • Fuzzy Search: When no exact match is found, Fuse.js provides a fuzzy search fallback.
  • Autocomplete: Provides fast, debounced suggestions based on user input.
  • Cached Results: Frequently searched terms are cached for improved performance.

Installation

To install the package via npm, run:

npm install sni-codes-utils

Usage

Import the Module

const {
  validateSniCode,
  searchSniCodes,
  getSniCodeDetails,
  autocomplete,
  debouncedAutocomplete
} = require('sni-codes-utils');

Validate SNI Code

To check if a given SNI code exists:

const isValid = validateSniCode('62010');
console.log(isValid); // true if valid, false otherwise

Search SNI Codes

Search for SNI codes using a keyword. This uses an optimized keyword index and falls back to fuzzy search if necessary:

const results = searchSniCodes('data');
console.log(results);
/*
[
  {
    code: '62010',
    description: 'Dataprogrammering',
    relevance: '99.90' // Relevance score based on search
  },
  ...
]
*/

Get SNI Code Details

Retrieve detailed information for a specific SNI code:

const details = getSniCodeDetails('62010');
console.log(details);
/*
{
  code: '62010',
  description: 'Dataprogrammering'
}
*/

Autocomplete

Use the autocomplete function to provide real-time suggestions as the user types:

const suggestions = autocomplete('data');
console.log(suggestions);
/*
[
  'Dataprogrammering',
  'Datakonsultverksamhet',
  ...
]
*/

Debounced Autocomplete

You can also use the debounced version of autocomplete to handle rapid user input more efficiently:


debouncedAutocomplete('data');

Example

Here's a full example of how you can integrate the utility in your application:


const {
  validateSniCode,
  searchSniCodes,
  getSniCodeDetails,
  autocomplete
} = require('sni-codes-utils');

// Validate a code
console.log(validateSniCode('62010')); // true

// Search for SNI codes with keyword
const searchResults = searchSniCodes('software');
console.log(searchResults);

// Get details of a specific SNI code
const details = getSniCodeDetails('62010');
console.log(details);

// Get autocomplete suggestions
const suggestions = autocomplete('data');
console.log(suggestions);

Performance

  • Index-Based Search: The package builds an index based on SNI descriptions for fast, exact keyword searches.
  • Fuse.js Fallback: When no match is found in the index, the package falls back to Fuse.js, allowing for fuzzy searching.
  • Caching: Frequently searched terms are cached for faster repeated lookups.

License

This package is licensed under the MIT License.


Keywords

  • SNI Codes
  • Svensk Näringsgrensindelning
  • Business Classification
  • Industry Codes
  • Fuzzy Search
  • Autocomplete
  • Data Search
  • Fuse.js
  • Validate SNI Codes

Developed by Fiive