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

avris-vanillin

v0.2.0

Published

Almost like vanilla JavaScript

Downloads

4

Readme

Vanillin.js – Almost like vanilla JavaScript

Logo

jQuery used to be virtually indispensable, if you wanted to develop a cross-browser website without getting a headache.

Today, however, you might not need jQuery, especially, if you're developing a library and want to avoid unnecessary dependencies.

Still, some helpers could be useful... Vanillin is an opinionated set of helpers that I find most useful, a bare minimum to make life easier.

Installation

You can either install Vanillin as a node module:

$ npm i --save avris-vanillin

or

$ yarn add avris-vanillin

require('avris-vanillin');

Use a CDN:

<script src="https://glcdn.githack.com/Avris/Vanillin/raw/v0.2.0/dist/Vanillin.min.js"></script>

Or simply copy-paste whatever filters you need from the source code.

Usage

_each(iterable, function (el, i))

Iterates in a consistent way, whether it's over an array or an object, without having to check for hasOwnProperty in every loop.

_each(object, function (val, key) {
    // ...
}); 

_each returns an array of values that you have (optionally) returned from the callback.

_el(html)

Converts an HTML string into a DOM element with one simple helper.

const el = _el('<div class="lorem"><a href="/test">OK</a></div>');

_sel(selector, [startNode])

Alias for querySelector:

const el = _sel('.card img.avatar')

_selAll(selector, [startNode])

Alias for querySelectorAll:

_each(_selAll('.card img.avatar'), function (el) { 
    el.classList.add('active')
})

_findParent(el, selector)

Finds the first parent of el that matches selector.

parent = _findParent(el, 'section.important')

_on(selector, event, handler (e))

Attaches the handler as an event listener or event for all elements that match selector, even if they don't exist yet at that moment.

_on('a.foo', 'click', function (e) {
    console.log('foo link clicked', this.attributes.href.value)
});

You can also pass a specific DOM Element instead of a selector, to only add a listener to this instance.

You can also attach the handler to multiple events: _on('a.foo', ['click', 'change', 'keyup'], e => console.log(e).

this in the callback is the element you have selected for, and it might be different from e.target, which might be its child.

Returning false from the callback will stop propagation and prevent default.

_request(method, url, data, headers)

Performs an AJAX request to url using a specified HTTP method, attaching data (they can be either FormData, an object, or a DOM element containing form data) and using specified headers. Returns a Promise.

_request('POST', '/document/create', document.querySelector('form'), {Authorization: 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'})
    .then((data) => {
        alert('Document created with ID: ' + JSON.parse(data).id);
    })
    .catch((xhr) => {
        console.log(xhr);
        alert('Error while creating a document');
    };

_extend = (out, ...args)

Extends out with data from ...args, useful for resolving configs:

function Helper(options) {
    this.config = _extend({}, defaultOptions, options);
}

Development

To install dev dependencies:

yarn

To build a minified, babel-ified version:

yarn build

To run tests:

yarn test

and open http://localhost:8777.

Copyright