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

@balena/balena-pricing

v1.3.0

Published

Balena pricing/savings calculators

Downloads

9,821

Readme

Balena Pricing/Savings Calculators

This library provides a set of functions that can be used to calculate credit purchase costs and savings when compared to dynamic billing. Credit pricing definitions can be passed in during instantiation, useful for testing and experimentation, but pricing definitions used in production are also defined within this package.

Usage

import { CreditPricing } from '@balena/balena-pricing';

// Format output to dollar currency.
const dollar = Intl.NumberFormat('en-US', {
	style: 'currency',
	currency: 'USD',
});
function toDollar(pennies: number): string {
	return dollar.format(pennies / 100);
}

// Set dynamic base price.
const dynamicPrice = 150;

// Use production credit pricing definitions.
let pricing = new CreditPricing();

// Use production credit pricing definitions.
// Explicitly target current versions (default).
let pricing = new CreditPricing({
	target: 'current',
});

// Use production credit pricing definitions.
// Target most recent versions, even those slated for future use.
pricing = new CreditPricing({
	target: 'latest',
});

// Use production credit pricing parameters.
// Target version 2, will return undefined for features without a version 2.
let pricing = new CreditPricing({
	target: 2,
});

// Use production credit pricing parameters.
// Target most recent versions valid up to a given date.
let pricing = new CreditPricing({
	target: new Date('2023-03-01T00:00:00Z'),
});

// Use custom credit pricing parameters.
// Mostly useful for testing parameters against the curve,
// should not normally be used in production.
pricing = CreditPricing({
	credits: {
		'foo:bar': [
			{
				version: 1,
				validFrom: new Date('2023-02-01T00:00:00Z'),
				basePriceCents: 150,
				firstDiscountPriceCents: 149,
				discountRate: 0.33,
				discountThreshold: 12000,
				discountThresholdPriceCents: 125,
			},
		],
	},
});

// Get individual credit price
const creditPrice = pricing.getCreditPrice('foo:bar', 0, 1000);
console.log('Credit unit price:', toDollar(creditPrice));

// Get total price for credit purchase
const totalPrice = pricing.getCreditTotalPrice('foo:bar', 0, 1000);
console.log('Credit total price:', toDollar(totalPrice));

// Get discount percentage compared to dynamic
const discount = pricing.getDiscountOverDynamic('foo:bar', 0, 1000, dynamicPrice);
console.log('Discount over dynamic:', `${discount}%`);

// Get total savings for credit purchase compared to dynamic
const totalSavings = pricing.getTotalSavings('foo:bar', 0, 1000, dynamicPrice);
console.log('Total savings:', toDollar(totalSavings));