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

weety

v1.1.1

Published

Tiny and pure framework library for complex web development. No compilation need and minimal modification of standard JavaScript and DOM layer.

Downloads

4

Readme

weety

Tiny and pure framework library for complex web development. No compilation need and minimal modification of standard JavaScript and DOM layer.

Summary of standard JavaScript modifications / changes:

  • Object.deepCopy - Object prototype extended by method that returns deep copy of first parameter given.

  • HTMLElement.state - All DOM elements extended by state property which is get only and returns editable associative array.

  • HTMLAnchorElement and HTMLButtonElement behavior overrite - all a an button elements with href (or data-href in button) that doesn't start with // http:// or https:// trigger history.pushState instead of redirecting page. This functionality is implemented via MutationObserver.

  • window.route - window extended by route functionality that provides routing based on history.pushState and history.replaceState method calls. Detailed description below. -history.pushState and history.replaceState - behavior overwritten to trigger route processing. Also added 'popstate' listener which does the same thing.

  • window.endpoint - window extended by endpoint functionality that provides routing over responses returned via fetch and XMLHttpRequest. Detailed description below. -fetch and XMLHttpRequest.prototype.open - behavior overwritten to trigger endpoint route processing upon recieving a response.

Instalation

Download from url:

Tiny version:

https://gitlab.com/katry/weety/-/raw/master/dist/weety.min.js

Compatibility version (IE9+):

https://gitlab.com/katry/weety/-/raw/master/dist/weety.babel.min.js

Use npm

npm install weety

Initialization

Script tag

<script src="<path-to-your-js-lib-folder>/weety.min.js"></script>

or when installed by npm | yarn

<script src="/node_modules/weety/dist/weety.min.js"></script>

Using

Elements

HTMLElement

All HTML elements are enhanced by property state, which stores non overwritable but editable object ({}) to element.

HTMLAnchorElement adn HTMLButtonElement

Weety overwrites behavior of elements <a> and <button> that you should use to navigation through web app routes for navigation is used content of href or data-href attributes in the order listed.

  • When overwritten behavior is applied only when location is written as relative or absolute path without domain, so you can use url starting with one of (// http://, https://) starting strings to enforce default behavior of elements (skip routing and force the redirect on <a> element or <button> element in form).
  • When click event is triggered elements state of the element is passed to pushState event.
  • You can use title or data-title attributes to provide title text for pushState event.

Useful tidbits

  • Object.deepcopy(a) - returns copy of first argument

Routes

Routes functionality is provided by object window.routeand his following methods:

  • get(pattern) - get route object by the pattern passed in first argument, pattern must be typed as string or regex.
  • terminate(route_or_pattern) - terminate and remove all routes listeners.
  • load(state=null) - invokes matching routes for actual url with optional state argument (should be used on website first load, after all routes are set).

Route object (returned by window.route.get method) method and properties:

  • addEventListener(type, trigger) - adds listener to the route. First argument is type which shoulbe be one of values load or befoureunload and second is callback to be triggered.
  • removeEventListener(type, trigger) - removes listener from route. First argument is type (load, befoureunload) and second is callback to be removed.
  • load(state=null) - method for instant call all route triggers of load type with optional state argument.
  • unload() - method for instant call all route triggers of beforeunload type.
  • pattern - property contains pattern of route (RegExp or string).

Endpoints

Endpoints functionality is provided by object window.endpointand his following methods:

  • get(pattern) - get endpoint object by the pattern passed in first argument, pattern must be typed as string or regex.
  • terminate(endpoint_or_pattern) - terminate and remove all endpoints listeners.

Endpoint object (returned by window.endpoint.get method) method and properties:

  • addEventListener(type, trigger) - adds listener to the endpoint. First argument is type which shoulbe be one of values load or error and second is callback to be triggered.
  • removeEventListener(type, trigger) - removes listener from endpoint. First argument is type (load, befoureunload) and second is callback to be removed.
  • load(state=null) - method for instant call all endpoint triggers of load type with optional state argument.
  • error(err, evt) - method for instant call all endpoint triggers of error type. Arguments err and evt are given by fetch and XMLXtthRequest error triggers.
  • pattern - property contains pattern of endpoint (RegExp or string).

Example

<!DOCTYPE html>
<html>
<head>
	<title>Weety Test HTML</title>
	<meta charset="utf-8" />

	<script src="build/weety.min.js"></script>
</head>
<body>
	<div class="btc" style="display: none">NO BTC DATA LOADED</div>
	<div class="eth" style="display: none">NO LTC DATA LOADED</div>

	<div>
		<a title="Bitcoin" href="/">bitcoin</a>
		<button title="Litecoin" data-href="/litecoin">litecoin</a>
	</div>
	<button id="load-data">Load</button>

	<script>
	// element state element using example
	document.body.state.test = "stest-state value";

	//routing example
	let btc_route = window.route.get("/");
	btc_route.addEventListener("load", function() {
		let btc = document.querySelector(".btc");
		let eth = document.querySelector(".eth");
		eth.style.display = "none";
		btc.style.display = "block";
	});

	let eth_route = window.route.create(/lite.*/);
	eth_route.addEventListener("load", function() {
		let btc = document.querySelector(".btc");
		let eth = document.querySelector(".eth");
		eth.style.display = "block";
		btc.style.display = "none";
	});


	//endpoints processing example

	const address = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&page=1&sparkline=false";

	//getting endpoint route
	const endpoint = window.endpoint.get(e);

	//setting load listener
	endpoint.addEventListener("load", function(e) {
		console.log(e);
		let btc = document.querySelector(".btc");
		btc.innerHTML = "1 BTC = $" + e[0].current_price + " USD";
	}, "GET");

	//setting another load listener
	window.endpoint[e].addEventListener("load", function(e) {
		let eth = document.querySelector(".eth");
		eth.innerHTML = "1 ETH = $" + e[2].current_price + " USD";
	});

	//click load button to fetching endpoint url and trigger listeners:
	document.querySelector("button#load-data").addEventListener("click", e => {
		fetch(e);
	});
	</script>
</body>
</html>

TODO List:

  • routing for WebSocket and RTCDataChannel messages
  • automated tests - DONE
  • more examples simple examples
  • complex app example