1.0.3 • Published 3 years ago

totality v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

Totality

Total from subtotals, automatically updating in your DOM with mutation observations.

Installation

npm i totality

Usage

Create a [data-totality] element, which will sum up all the items pointed to by its data attribute, e.g.

<div class="subtotal">£1.99</div>
<div class="subtotal">£2.99</div>
<div class="subtotal">£3.99</div>
<div data-totality=".subtotal"></div>
import Totality from "totality";

// Spin up instances for any [data-totality] elements
const totalityElements = document.querySelectorAll("[data-totality]");
if (totalityElements) {
  const totalities = [...totalityElements].map(
    element => new Totality({ element, currency: "£" })
  );
}

And it will populate the total with £8.97.

Updating

It observes mutations within the given subtotal elements, so if you've got other scripts wrangling prices, we good.

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago