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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fiscal-es

v1.0.0

Published

Spanish personal income tax (IRPF) on the savings base: exact integer-cent engine with executable YAML test cases

Readme

fiscal-es

Spanish personal income tax (IRPF) on the savings base (Spain, common territory): integrates capital gains, capital losses and investment income for one tax year and applies the state and regional scales separately.

TypeScript, ESM, no runtime dependencies, pure functions. Amounts in integer cents (Cents) and rates in integer basis points (Bp); never floating point.

Installation

npm install fiscal-es

ESM only (import); there is no CommonJS build.

Usage

Computing the savings tax

import { computeSavingsTax, formatEuros, parseEuros } from "fiscal-es";

const r = computeSavingsTax({
  taxYear: 2026,
  capitalGains: parseEuros("10000.00"),
  capitalLosses: parseEuros("3000.00"),
  investmentIncome: parseEuros("0.00"),
});
// r = { savingsTaxableBase: 700000, stateTax: 67500, regionalTax: 67500, totalTax: 135000 }
formatEuros(r.totalTax); // "1350.00"

parseEuros only accepts the format "-1234.56" (decimal point, two decimals); anything else throws SyntaxError. Input that makes no sense (non-integer amounts, negative gains or losses) throws InvalidInput; a tax year without a table throws UnknownTaxYear.

Available tax years

import { availableTaxYears, getTaxTable } from "fiscal-es";

for (const taxYear of availableTaxYears()) {
  console.log(taxYear, getTaxTable(taxYear).source.verifiedOn); // 2026 "2026-10-25"
}

Range and errors

The computation is exact for amounts up to ≈ 9 000 million euros per operation: with rates up to 10 000 bp, the intermediate product cents × basis points fits in Number.MAX_SAFE_INTEGER. Above that, any operation whose result or intermediate product leaves the safe integer range throws RangeError.

  • SyntaxError: parseEuros receives a format other than "-1234.56" (see Usage).
  • InvalidInput: computeSavingsTax receives an amount that is not an integer number of cents (NaN, a fraction of a cent), negative gains or losses, or a non-integer tax year.
  • UnknownTaxYear: computeSavingsTax receives a tax year without a table.
  • RangeError: parseEuros, add, subtract, timesBp or roundCents receive or produce a value outside the safe integer range.

Supported tax years

| Tax year | Scale verified on | | -------- | ----------------- | | 2026 | 2026-10-25 |

cases/: the executable spec

Each YAML file in cases/ is a case with its input, the expected output to the cent, the legal reference and the date on which a person verified it. The package's test suite runs all of them against the engine; a change to the engine that alters the output of a verified case is a major version change. The format is described in cases/SCHEMA.md. The cases are written in Spanish, with Spanish keys (ganancias_patrimoniales, cuota_ahorro…), because they are checked against the Spanish tax return manual; Terminology maps them to the API.

Terminology

| Identifier | Spanish term | LIRPF | | ---------- | ------------ | ----- | | computeSavingsTax | cuota del ahorro | arts. 49, 50.2, 66.1 y 76 | | SavingsInput / SavingsResult | entrada / resultado del ahorro | | | taxYear | ejercicio | | | capitalGains (ganancias_patrimoniales) | ganancias patrimoniales | art. 33 | | capitalLosses (perdidas_patrimoniales) | pérdidas patrimoniales | art. 33 | | investmentIncome (rendimientos_capital_mobiliario) | rendimientos del capital mobiliario | art. 25 | | savingsTaxableBase (base_liquidable_ahorro) | base liquidable del ahorro | arts. 49 y 50.2 | | stateTax (cuota_estatal) | cuota estatal | art. 66.1 | | regionalTax (cuota_autonomica) | cuota autonómica | art. 76 | | totalTax (cuota_ahorro) | cuota del ahorro (estatal + autonómica) | | | TaxTable / getTaxTable / availableTaxYears | tabla normativa del ejercicio / ejercicios disponibles | | | TaxBracket (upTo, stateBp, regionalBp) | tramo de la escala del ahorro (hasta, tipo estatal, tipo autonómico) | arts. 66.1 y 76 | | UnknownTaxYear | ejercicio sin tabla | | | InvalidInput | entrada inválida | | | Cents / Bp | céntimos / puntos básicos | | | add / subtract / clampZero / ZERO | sumar / restar / acotar a cero / cero | | | timesBp / roundCents | céntimos × puntos básicos / redondeo al céntimo | |

Known limitations

  • No cross-offsetting: a negative balance of gains and losses does not offset positive investment income, nor the other way round (art. 49.1 LIRPF). The negative balance simply is not taxed.
  • No carry-forward of negative balances to the following four tax years (art. 49.2 LIRPF).
  • No foral regimes (Navarra, País Vasco).
  • Savings base only: does not compute the general base, personal allowances or deductions.

Development in the monorepo

exports has a custom condition, fiscal-es-src, pointing to src/ so the monorepo app can use the engine without building it; external consumers do not enable it and get dist/.

Disclaimer

A calculation tool. Not tax or financial advice. Check your situation against current legislation or with a professional.

License

MIT