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

satang

v0.2.1

Published

Satang is a money managing package for Javascript

Downloads

18

Readme

Satang

Node Module to manage money information.


This is not ready to be used in production


Install

Install via npm

npm install satang --save

Install via yarn

yarn add satang

Initializing

import Satang, { Currencies } from 'satang';

// First param is the amount of money in subunits. To map $100, amount should be 10000.
// Only Currencies.THB and Currencies.USD are supported
const price = new Satang(Currencies.THB, 10000);

You could also directly import Thai baht currency directly,

import Satang, { ThaiBaht } from 'satang';

// First param is the amount of money in subunits. To map $100, amount should be 10000.
// Only Currencies.THB and Currencies.USD are supported
const price = new Satang(ThaiBaht, 10000);

Supported currencies are ThaiBaht & USD

Pretty String

You can get a pretty string that represents your money by using the display() method

const price = new Satang(Currencies.THB, 10000);
price.display(); // output => ฿100.00

Satang Manipulation

You can manipulate satang value. To add 2 satangs, you can use the add() method

 const cartPrice = new Satang(Currencies.THB, 0);
 const product1Price = new Satang(Currencies.THB, 10000);
 const product2Price = new Satang(Currencies.THB, 15000);

 cartPrice.add(product1Price);
 cartPrice.display(); // output => ฿100.00

You can also chain manipulations

cartPrice.add(product1Price).add(product2Price).display(); // output => ฿250.00

Supported Currencies

At the moment, Satang only supports USD & THB. Frankly, it's not the best implementation for currency support and it will be changed in the future. You can get access to supported currency using two methods

  • Just import it using import { Currencies } from 'satang'

  • Second, you can access supported currency data from using the supportedCurrencies() method.

Satang.supportedCurrencies();

Custom Currencies

If you'd like to use a custom currency, you'll need to create an instance of Currency. Here's an example:

import Satang, { Currency } from 'satang';

const Euro = new Currency({
  // Symbol used when display-ing value for this currency,
  symbol: '€',
  // Short code, should be unique
  code: 'eur',
  // Will be used when dispay-ing value for this currency
  prettyCode: 'EUR',
  // Name of the currency
  fullName: 'Euro',
  // Locale used to format string displaying the value of the currency
  locale: 'de-AT'
});

const price = new Satang(Euro, 9000);

console.log(price.display()); // Logs €90.00

If you would like to more control over the display function, you can inherit Currency to create your own Currency instead

Eg: 
```javascript
class EuroCurrency extends Currency {
  constructor(props) {
    super(props);
  }

  display(moneyInSubunits) {
    const formatter = new Intl.NumberFormat(this.locale, { 
      style: 'currency', 
      currency: this.code 
    });

    const money = Math.round(moneyInSubunits / 100);
    return `<strong>${formatter.format(money)}</strong>`;
  }
}

const Euro = new EuroCurrency({
  symbol: '€',
  code: 'EUR',
  prettyCode: 'EUR',
  fullName: 'Euro',
  locale: 'de-DE'
});

const priceInEur = new Satang(Euro, 9000);

priceInEur.display(); // Return <strong>90,00 €</strong>

Note

If your currency display doesn't match your expected format and you are running in node environment, you might be missing ICU data file.

Install the icu file with npm install full-icu

then point to the icu dataset by NODE_ICU_DATA=node_modules/full-icu node app.js

Just keep in mind that this means binary size is going to increase. [https://github.com/unicode-org/full-icu-npm](Read more here)