# website-toolbox

> A dead-simple framework for dealing with all sorts of "website things".

Latest version **0.6.0** (published 2020-11-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install website-toolbox
pnpm add website-toolbox
yarn add website-toolbox
bun add website-toolbox
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2020-11-30 |
| First published | 2020-11-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 160 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Doug Alcantara |
| Maintainers | dougalcantara |

## Links

- npm: https://www.npmjs.com/package/website-toolbox
- Repository: https://github.com/dougalcantara/website-toolbox
- Homepage: https://github.com/dougalcantara/website-toolbox#readme
- Issues: https://github.com/dougalcantara/website-toolbox/issues
- npm.io page: https://npm.io/package/website-toolbox

## Recent versions

- 0.6.0 (latest) — 2020-11-30
- 0.5.1 — 2020-11-21
- 0.5.0 — 2020-11-21
- 0.4.3 — 2020-11-17
- 0.4.2 — 2020-11-17
- 0.4.1 — 2020-11-17
- 0.4.0 — 2020-11-17
- 0.3.0 — 2020-11-17
- 0.2.1 — 2020-11-17
- 0.1.1 — 2020-11-15
- 0.1.0 — 2020-11-15

## README

# 🧰 Website Toolbox 🛠
A dead-simple framework for dealing with all sorts of "website things". This framework is particularly helpful when you're doing things like:

- Dealing directly with the DOM
- Upgrading old jQuery code to `currentYear`
- Spinning up a quick [codepen](https://codepen.io/trending)
- Adding functionality to Wordpress, Shopify, HubSpot, and other marketing, brochure & e-commerce sites
- Re~~heating~~writing some old spaghetti

## Why It's Good
Sometimes, you can't ([or shouldn't!](https://dev.to/gypsydave5/why-you-shouldnt-use-a-web-framework-3g24)) use a full-sized framework like Vue or React. This happens typically when developing something like a Shopify or Wordpress theme, although there are quite a few other cases where you'd need something that provides a little structure to the JavaScript that typically gets written in this environment. 

The Website Toolbox provides some structure and opinion about how your classic "website JS" code is written and implemented. Of course, it's possible you may need something that does *more*. But this framework is for when you *don't*.

That's not to say this framework is primitive -- it still has cool stuff like:

- Reactive data properties
- Lifecycle hooks
- Reference to the parent scope/context using the `this` keyword (similar to the way `this` is handled in VueJS)
- Global reactive state (and `this.setState`!)
- Cross-component communication (in development)
- Custom plugin & mixin integration (in development)
- Helpful methods like `resize()`, `updated()` and `inView()` (in development)

The Website Toolbox doesn't replace React, Vue, or Angular. Those provide helpful and practical tools & opinions about how to handle frontend JS code. *But you don't always need all that stuff*. 

Here's an example of what's currently possible with the `Component` class:
```js
import { Component } from 'website-toolbox';

// A simple and familiar API
const carousel = new Component({
  name: 'HomepageCarousel',

  // nothing gets mounted, this just gets `document.querySelector`'d for you
  root: '.carousel',

  // these are all queried relative to the root element
  nodes: {
    headline: '.some-headline', // querySelector
    buttons: ['.some-button'], // querySelectorAll
  },

  data: {
    /**
     * Must declare initial state, even if null or falsy. Otherwise, you'll
     * get barked at. This enforces that all variables must be declared 
     * before use.
     * */
    currentSlide: 0,
    delay: 1500,
  },

  // think "lifecycle hooks", not React hooks
  hooks() {
    // like a `componentDidMount` or `useEffect(() => {}, [])`
    setup() {
      // the `Component` instance is available as `this`
      this.methods.attachEventListeners();
    },

    // Called immediately after anything in `Component.data` is updated 
    updated(next, prev, key) {
      /**
       * `next` & `prev` are the upcoming & previous values of the
       * updated data prop, respectively
       * 
       * `key` is the keyname of the property that updated, so you can do 
       * `this.data[key]` to track a specific data prop for changes.
       * */
    }
  },

  methods: {
    attachEventListeners() {
      const submitButton = this.nodes.buttons[0];
      submitButton.addEventListener('click', () => 'Submitted!');
    },
  },

});
```
## Testing
Testing with Jest in `tests/`. To run tests:
```
npm run test // test: jest
```

## Building
```
npm run build // build: npm run test && rollup --config
```

---
_Source: https://npm.io/package/website-toolbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
