JSPM

gtin13generator

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q32010F
  • License ISC

A robust utility for automatically generating and validating GTIN-13 numbers, ideal for e-commerce platforms, inventory management, and integration with Google Shopping.

Package Exports

  • gtin13generator
  • gtin13generator/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gtin13generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GTIN-13 Generator πŸš€

Overview

gtin13generator is a lightweight Node.js utility designed to automatically generate valid GTIN-13 numbers, specifically optimized for use in Google product listings and other e-commerce platforms. The package ensures compliance with GTIN-13 standards by calculating the necessary check digit, making it an ideal tool for product identification in retail and online markets.

Features ✨

  • Automatic GTIN-13 Generation: Effortlessly create valid GTIN-13 numbers.
  • GTIN-13 Validation: Verify the correctness of a GTIN-13 number.
  • Lightweight & Fast: Designed to be quick and efficient, with minimal dependencies.
  • Easy Integration: Simple API that can be easily integrated into your Node.js applications.
  • Optimized for E-commerce: Perfect for Google Merchant Center and other product listing services.

Installation πŸ› οΈ

You can install gtin13generator via npm:

npm install gtin13generator --save

Usage πŸ’»

Generating a GTIN-13

const { generateGTIN13 } = require('gtin13generator');

const gtin13 = generateGTIN13();
console.log(gtin13); // Outputs a valid GTIN-13 number

Example Usage in Real World Projects

Imagine you want to upload some products to Google Shopping. You would need a GTIN number for each product. In your schema, you can add a gtin column and set its default value to a generated GTIN-13 number like this:

const { generateGTIN13 } = require('gtin13generator');

const productSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  price: {
    type: Number,
    required: true
  },
  gtin: {
    type: Number,
    unique: true,
    default: generateGTIN13
  }
});

const Product = mongoose.model('Product', productSchema);

This way, each product will automatically have a unique and valid GTIN-13 number assigned to it.

Validating a GTIN-13

const { validateGTIN13 } = require('gtin13generator');

const isValid = validateGTIN13('1234567890128');
console.log(isValid); // Outputs true or false depending on the validity of the GTIN-13

Example πŸ“¦

Here’s how you might use the package in a real-world scenario:

const { generateGTIN13, validateGTIN13 } = require('gtin13generator');

const newProductGTIN = generateGTIN13();
console.log(`Generated GTIN-13: ${newProductGTIN}`);

if (validateGTIN13(newProductGTIN)) {
  console.log('This GTIN-13 is valid and ready for use!');
} else {
  console.error('There was an error generating a valid GTIN-13.');
}

API Reference πŸ“š

generateGTIN13()

Generates a valid GTIN-13 number.

  • Returns: string - A 13-digit GTIN-13 number.
  • Example:
const gtin = generateGTIN13();
console.log(gtin); // e.g., "1234567890128"

generateGTIN13

Alternative usage without parentheses. This can be useful when passing the function as a callback or reference.

  • Returns: Function - The GTIN-13 generator function.
  • Example:
console.log(generateGTIN13); // e.g., "9876543210987"

validateGTIN13(gtin13)

Validates a given GTIN-13 number.

  • Parameters:
    • gtin13 (string): The GTIN-13 number to validate.
  • Returns: boolean - true if the GTIN-13 number is valid, false otherwise.

License βš–οΈ

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing 🀝

Contributions are welcome! If you have any suggestions, improvements, or bug fixes, feel free to submit a pull request or open an issue.

Contact πŸ“¬

For any questions or issues, please open an issue on the GitHub repository or contact me via my website.

Acknowledgements πŸ™

Special thanks to generate-unique-id and gtin packages for making this tool possible.