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

svelte-price-estimate

v0.4.9

Published

An easy way to show and manage your price estimation for your Svelte project

Downloads

4

Readme

🚥 Getting Started

You have to install this component via npm:

npm i svelte-price-estimate

And import these js and css in your index.html :

  • bootstrap, only for styles and icons
  • jquery, we need jquery for slik to work
  • slick, carousel for category selector => js and css

You can check this sample app here and check index.html for more info

▶️ Running

Import this component in any of your svelte files:

import PriceEstimate from "svelte-price-estimate"; 

Add the component tag inside your html

<PriceEstimate data={data} mailingURL={mail}></PriceEstimate>

The "data" attribute is explained below (with example) and the "mailingURL" is the URL of your endpoint or service to process the estimate data with the email that users input in the email field (if mailingURL is set).

Then, you can access it by default in http://localhost:5000 and watch the app running with changes in real time. You can check this sample repository.

🛠️ Tools and libraries

📔 Data definition

The data field in PriceEstimate is defined as an array. This is an example:

let data = [
    {
      icon: 'assets/icons/clean.png', 
      name: 'Bathroom', 
      title: 'Bathroom Renovation ',
      category_name: 'Quality',
      unique: false,
      measure: {name : 'Meters', short_name: 'm²'}, 
      items: [
        {
          description: 'Toilet, bath, faucets, furnishings and mirrors', 
          category: {
            medium: {
              label: 'Medium',
              price_ranges: [
                {from_quantity:0, to_quantity: 6, price: 1000, step: 6},
                {from_quantity:6, price: 100, step: 1}
              ]
            }, 
            high: {
              label: 'High',
              price_ranges: [
                {from_quantity:0, to_quantity: 6, price: 2000, step: 6},
                {from_quantity:6, price: 200, step: 1}
              ]
            }
          },
          selected: 'medium'
        },
        {
          description: 'Instalation, plumbing, electrical wiring and veneer', 
          category: {
            medium: {
              label: 'Medium',
              price_ranges: [
                {from_quantity:0, to_quantity: 6, price: 500, step: 6},
                {from_quantity:6, price: 50, step: 1}
              ]
            }, 
            high: {
              label: 'High',
              price_ranges: [
                {from_quantity:0, to_quantity: 6, price: 1000, step: 6},
                {from_quantity:6, price: 100, step: 1}
              ]
            }
          },
          selected: 'medium'
        }
      ]
    },
    {
      icon: 'assets/icons/kitchen.png', 
      name: 'Kitchen', 
      title: 'Kitchen Design',
      category_name: 'Quality',
      unique: false,
      measure: {name : 'Meters', short_name: 'm²'}, 
      items: [
        {
          description: 'Furniture from bottom to top', 
          category: {
            medium: {
              label: 'Medium',
              price_ranges: [
                { price: 120, step: 1}
              ]
            }, 
            high: {
              label: 'High',
              price_ranges: [
                { price: 210, step: 1}
              ]
            }
          },
          selected: 'medium'
        },
        {
          description: 'Installations, plumbing and electrical wiring', 
          category: {
            medium: {
              label: 'Medium',
              price_ranges: [
                {from_quantity:0, to_quantity: 6, price: 1230, step: 6},
                {from_quantity:6, price: 200, step: 1}
              ]
            }, 
            high: {
              label: 'High',
              price_ranges: [
                {from_quantity:0, to_quantity: 6, price: 1230, step: 6},
                {from_quantity:6, price: 200, step: 1}
              ]
            }
          },
          selected: 'medium'
        }
      ]
    },
    {
      icon: 'assets/icons/heater.png', 
      name: 'Heater', 
      title: 'Heater',
      category_name: 'Rank',
      unique: true,
      measure: {name : 'Unidad', short_name: 'und'},
      items: [
        {
          description: 'Heating circuit, radiators and boiler', 
          category: {
            one_room: {
              label: 'One room',
              price_ranges: [
                {price: 1230}
              ]
            }, 
            full_house: {
              label: 'Full house',
              price_ranges: [
                {price: 1890}
              ]
            }
          },
          selected: 'full_house'
        }
      ]
    }
];

This sample shows something like this: ScreenShot

It looks complex, but is pretty easy to understand:

  • Every item in the array is a section.
  • Every section has list of items.
  • Every item has a category that can be dinamically set as a group of price range.

icon: Icon of the section, 
name: Short name below icon, 
title: Full name of the section,
category_name: Column name for the selectors,
unique: 'true' if only one price applies or 'false' if we need to process the quantity,
measure: 
    name : Metering name ex=(meters, foot, unit...), 
    short_name: Short name ex=(m2, ft, ud...)
items:
    description: Item name or description (row in table)
    category: You can set any identifier for the category
        label: Option in the selector
        price_ranges: This array has to be in order
            from_quantity: Minimum quantity to evaluate
            to_quantity: Maximum quantity to evaluate
            price: Price of the step
            step: Quantity in this range will be multiply by step

🎓 Considerations

  • with unique value set true, we can manage 1 price. That means, a section has no quantity because it is an one life time payment:
price_ranges: [
    { price: 120, step: 1}
]
  • with unique value set false, you can play more.
price_ranges: [
    {from_quantity:0, to_quantity: 6, price: 1230, step: 6},
    {from_quantity:6, price: 200, step: 1}
]

With this definition of price ranges, you can set a quantity. This quantity will be distribute. For example, I want 7 of this section. so, 7 fill the first range, because 0 < 7 < 6, so we have actually 6 in this section, then it'll be divide by step (6) = 1. And then multiply by price (1230).

But wait! we have 1 left, because 7 - 6 = 1, so we pass to the next range: 6 to N (because we have no to_quantity). Thus 1 / step (1) = 1, then multiply by price (200).

Finally, total = 1430

You can play with almost any value and try to fit it into your application