Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

minute-designs-hsn-code

joyalshaji84SEE LICENSE IN LICENSE.md1.0.21

A set of utilities for working with GSTIN, state codes, HSN/SAC codes, and GST slabs.

GST, GSTIN, HSN, SAC, GST Slabs, PAN Types, State Codes, India, Tax, GST Validation, Goods and Services Tax, GST Utilities

readme

Code Functionality Explanation

This document explains the functionality of the various methods defined in the provided code. These functions mainly deal with handling state, HSN, SAC, GST slabs, PAN types, and GSTIN validation in the context of Goods and Services Tax (GST).

State Methods

1. getStateCode(state?: string): string | undefined

  • Description:
    This function retrieves the state code for a given state name. It searches through the stateData array and returns the state code that matches the provided state name.

  • Parameters:

    • state (optional): A string representing the name of the state (e.g., "Delhi", "Maharashtra").
  • Returns:
    A string representing the state code if a matching state is found. Otherwise, it returns undefined.

  • Example:

      getStateCode("Delhi");  // Returns: "07"

2. getStateByCode(code?: string): string | undefined

  • Description:
    This function retrieves the state name based on the provided state code. It searches through the stateData array and returns the state name for the matching state code.

  • Parameters:

    • code (optional): A string representing the state code (e.g., "07", "19").
  • Returns:
    A string representing the state name if a matching code is found. Otherwise, it returns undefined.

  • Example:

      getStateByCode("07");  // Returns: "Delhi"

3. getAllStates(): typeof stateData

  • Description:
    This function returns all the state data from the stateData JSON.

  • Returns:
    The entire stateData array, which includes information about multiple states and their corresponding codes.

  • Example:

      getAllStates();  // Returns: [ { state: "Delhi", code: "07" }, { state: "Maharashtra", code: "19" }, ... ]

GST Slab Methods

4. getGstSlab(hsnCode: number)

  • Description:
    This function retrieves GST slab details based on a given HSN code. It searches through the gstSlab array and returns an object containing the GST slab details such as CGST, SGST, IGST, and tax rate for the corresponding HSN code.

  • Parameters:

    • hsnCode: A number representing the HSN code (e.g., 1101 for rice).
  • Returns:
    An object containing the GST slab details (hsn_code, description, CGST, SGST, IGST, TAX_RATE) if a matching HSN code is found. Otherwise, it returns undefined.

  • Example:

      getGstSlab(1101);  // Returns: { hsn_code: 1101, description: "Rice", CGST: 9, SGST: 9, IGST: 18, TAX_RATE: 18 }

HSN Code Methods

5. getAllHSNCodes(): typeof hsnData

  • Description:
    This function returns all the HSN codes and their descriptions from the hsnData JSON file.

  • Returns:
    The entire hsnData array containing HSN codes and corresponding descriptions.

  • Example:

      getAllHSNCodes();  // Returns: [ { hsn: "1101", description: "Rice" }, { hsn: "2005", description: "Fruit Juice" }, ... ]

6. getHsnDescriptionByCode(code?: number): string | undefined

  • Description:
    This function retrieves the description for a given HSN code. It searches through the hsnData array and returns the description corresponding to the provided HSN code.

  • Parameters:

    • code (optional): The HSN code as a number (e.g., 1101).
  • Returns:
    A string representing the description of the given HSN code if a match is found. Otherwise, it returns undefined.

  • Example:

      getHsnDescriptionByCode(1101);  // Returns: "Rice"

SAC Code Methods

7. getAllSacCodes(): typeof sacData

  • Description:
    This function returns all the SAC codes and their descriptions from the sacData JSON file.

  • Returns:
    The entire sacData array containing SAC codes and corresponding descriptions.

  • Example:

      getAllSacCodes();  // Returns: [ { sac: "9983", description: "Transport services" }, { sac: "9997", description: "Other services" }, ... ]

8. getSacDescriptionByCode(code?: string): string | undefined

  • Description:
    This function retrieves the description for a given SAC code. It searches through the sacData array and returns the description for the provided SAC code.

  • Parameters:

    • code (optional): The SAC code as a string (e.g., "9983").
  • Returns:
    A string representing the description of the given SAC code if found. Otherwise, it returns undefined.

  • Example:

      getSacDescriptionByCode("9983");  // Returns: "Transport services"

PAN Type Methods

9. getAllPanTypes(): typeof panTypes

  • Description:
    This function returns all the PAN type data from the panTypes JSON file.

  • Returns:
    The entire panTypes array containing information about different PAN types.

  • Example:

      getAllPanTypes();  // Returns: [ { code: "A", pan_type: "Individual" }, { code: "B", pan_type: "Company" }, ... ]

GSTIN Validation & Information Methods

10. calculateChecksum(gstin: string): string

  • Description:
    This function calculates the checksum for a given GSTIN. It follows a specified algorithm to compute the checksum character.

  • Parameters:

    • gstin: A string representing the GSTIN number.
  • Returns:
    A string representing the calculated checksum character for the GSTIN.

  • Example:

      calculateChecksum("29ABCDE1234F2Z5");  // Returns: "5"

11. isValidGstinPattern(gstin: string): boolean

  • Description:
    This function checks whether the provided GSTIN matches the expected pattern using a regular expression.

  • Parameters:

    • gstin: A string representing the GSTIN number.
  • Returns:
    true if the GSTIN matches the pattern, otherwise false.

  • Example:

      isValidGstinPattern("29ABCDE1234F2Z5");  // Returns: true

12. isValidGSTNumber(gstin: string): boolean

  • Description:
    This function checks if the provided GSTIN is valid by both matching the pattern and calculating the checksum.

  • Parameters:

    • gstin: A string representing the GSTIN number.
  • Returns:
    true if the GSTIN is valid, otherwise false.

  • Example:

      isValidGSTNumber("29ABCDE1234F2Z5");  // Returns: true

13. getGstinInfo(gstin: string): string

  • Description:
    This function retrieves detailed information about a GSTIN. It returns information such as the state, PAN type, and entity number for the provided GSTIN.

  • Parameters:

    • gstin: A string representing the GSTIN number.
  • Returns:
    A string containing detailed information about the GSTIN (e.g., state name, PAN type, entity number).
    If the GSTIN is invalid, it returns "Invalid GSTIN".

  • Example:

      getGstinInfo("29ABCDE1234F2Z5");  // Returns: "The GSTIN 29ABCDE1234F2Z5 is entity #5 belonging to Individual PAN registered in Karnataka (KA)"

Conclusion

This code provides utility functions for handling GST-related data, such as state codes, HSN/SAC codes, GST slabs, and PAN types. It also offers functionality for validating GSTINs and extracting detailed information about them. These functions are useful for building GST-compliant applications, managing state-specific data, and validating GSTINs for businesses or individuals.