js-product-pricing-calculator
v1.0.19
Published
A package for calculating product pricing based on various rules, usable in both frontend and server-side applications.
Downloads
33
Maintainers
Readme
jeevika-shah-price-lib
NPM module to calculate pricing /**
- Calculates the final pricing for a given product, considering gold, diamond, labour, miscellaneous costs,
- tax, and payment gateway fees.
- @param product - The product for which the price is being calculated.
- @param CentralPricing - The central pricing information containing gold and diamond prices.
- @param productSize - The selected size variant of the product.
- @returns An object containing the product ID and the computed final price. */
Example usage:
import { calculatePricing, Product, CentralPricing, ProductSize } from 'jeevika-shah-price-lib';
const product: Product = {
_id: 'prod123',
name: 'Gold Ring',
isDeleted: false,
description: '18K gold ring with diamonds',
category: 'Rings',
images: [],
sizes: [
{ displayName: '6', weightOfMetal: 1.2, _id: 'size6' },
{ displayName: '7', weightOfMetal: 1.3, _id: 'size7' }
],
karatOfGold: 18,
weightOfGold: 2,
karatOfDiamond: 0.5,
costOfDiamond: 1000,
costOfLabour: 500,
miscellaneousCost: 100,
isCentralisedDiamond: true,
isNaturalDiamond: true,
isLabDiamond: false,
isActive: true,
isLandingPageProduct: false,
createdAt: '2024-06-01T00:00:00Z',
updatedAt: '2024-06-01T00:00:00Z',
__v: 0
};
const centralPricing: CentralPricing = {
goldPricePerGram: 6000,
naturalDiamondPricePerCarat: 50000,
labDiamondPricePerCarat: 20000
};
const productSize: ProductSize = product.sizes[0];
const result = calculatePricing(product, centralPricing, productSize);
console.log(result);
// Output: { productId: 'prod123', finalPrice: <calculated_value> }