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

pocky.js

v3.2.0

Published

Front-End Project Boilerplate

Downloads

42

Readme

Pocky.js

A Thin Front-End Library With a few Core Nutrients, but Mostly (Syntactic) Sugar

Front-end project boilerplate.

pocky

Application

  • Publish/Subscribe Methods for Event Handling/Emitting
  • In-memory Data Store by lokijs
  • State/URI Routing by navigo

Mediator

  • Standard Event Bus/Emitter with explicit scope binding

View

  • Lightweight Modular UI Components built with bel
  • Update Method for Quick DOM Manipulation/Mutation

Util

  • Cookie Storage Interface

  • URI Parameter Interface

  • Arrayify

    • transform an object into an array
  • Matrixify

    • transform an array into a multi-dimensional array matrix
  • Template

    • Parse a string of HTML as a Javascript Template Literal
  • Random Hex Value

    • generate a random hex value of a specified length
  • Extend

    • iterate over an object's parameters and attach each one to a parent

Usage

Install as npm Module.

npm install --save pocky.js

Grab what you need and start using it.


const { Observable } = require('pocky.js');
const { html } = require('pocky.js').utility;

// create a new observable
const o = new Observable({ param: false });

// grab some DOM elements
const $container = document.querySelector('#container');
const $btn = $container.querySelector('button');

// define a new DOM element not yet on the screen
const $el = html`<div>
    <h1>The Parameter is Now True!</h1>
</div>`;

// listen for an 'update' event and fire a callback bound to a given context
o.on('update', o, function(update){
    this.param = update;
    $container.appendChild($el);
 });

// fire the 'update' event on user action
$btn.addEventListener('click', function(){
    o.emit('update', true);
});

Create a view to render dynamic data.


const { View } = require('pocky.js');

// define a reusable view class
class HomePage extends View {
    constructor(options){
        super(options);
    }
}

// define instance of view with a parent node
var $hp = new HomePage({
    parentNode: document.body
 });

// mount view instance to DOM parent
window.addEventListener('load', function(){
    $hp.mount();   
 });

// update the view's data
$hp.data.list = ['red', 'blue', 'yellow'];

// re-render the view instance with the updated data
setTimeout(function(){
    $hp.update();
}, 3000);

Build an application.


const { Application, View } = require('pocky.js');

// instantiate an app
const app = new Application();

// define the app's routes
app.router.on({
    '/home-page': () => $hp.render(),
    '/update-home-page': () => $hp.update();
});

// create a data collection and insert some data
app.db.addCollection('color-list');
app.db.getCollection('color-list').insert({ color: 'red' });
app.db.getCollection('color-list').insert({ color: 'blue' });
app.db.getCollection('color-list').insert({ color: 'yellow' });

// assign the data collection to something like a view
$hp.data.list = app.db.getCollection('color-list').find();

// navigate to a route
window.addEventListener('load', function(){
    app.router.navigate('/home-page');
});

// do some more stuff later on
setTimeout(function(){
    app.db.getCollection('color-list').insert({ color: 'green' });
    app.db.getCollection('color-list').insert({ color: 'purple' });
    app.db.getCollection('color-list').insert({ color: 'orange' });

    app.router.navigate('/update-home-page');
}, 3000);