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

gimmickry

v0.1.9

Published

Web app framework for user driven view rendering.

Downloads

1

Readme

Gimmickry

Gimmick: a function adapts UI/UX for a user according to his/her attributes.

motivation

To provide user-adaptive UI/UX conveniently.

  • user-driven view rendering
  • stateful user attributes
  • small and encapsulated view component

architecture

usage

import {App, UserAttr, ViewComponent} from "gimmickry";

interface UserProfileSchema{
  name : sting;
  age : number;
}

class UserProfile extends UserAttr<UserProfileSchema>{
  id:string = "profile";
  value:UserProfileSchema = { name : "", age : 0 };
  init(){
    //get value from somewhere like API, cookie, etc.
    this.set({
      name : "taro",
      age : 20
    });
  }
}

interface UserSchema{
  profile:UserProfileSchema
}

class RenderHTML extends ViewComponent{
  id:string = "render-html";
  render(user:UserSchema){
    document.querySelector("#user-profile").innerHTML = `
      <div>name : ${user.proile.name}</div>
      <div>age : ${user.proile.age}</div>
    `;
  }
}

const app = new App();
app.user.use(new UserProfile());
app.view.use(new RenderHTML());

try example

  1. clone this repo
$ git clone https://github.com/YoshiyukiKato/gimmickry.git
  1. install packages
$ cd gimmickry
$ npm install
  1. run dev server
$ npm run server

And then, please visit http://localhost:9000 to see some simple examples. Those examples' source are in example/src directory.

API

App

App(mode)

  • mode(optional)
    • "dev"|"prod" (default is "dev").
    • the dev mode exports following methods to global scope
      • app.user.setAttrs => window.__import_user_attrs_value__
      • app.user.import => window.__import_user_attr__
      • app.view.import => window.__import_view_component__
const app = new App(mode);

app.user

An instance of User class.

app.view

An instance of View class.

User

User.use(userAttr)

params :

User.import(attrName, attrValue, attrInitFunction)

params :
  • attrName : string
  • attrValue : any
  • attrInitFunction : () => any

User.setAttrs(attrs)

params :
  • attrs : any
return : boolean

UserAttr

interface UserProfileSchema{
  id : sting;
  age : number;
}

class UserProfile extends UserAttr<UserProfileSchema>{
  id:string = "profile";
  value:UserProfileSchema = { name : "", age : 0 };
  init(){
    //get value from somewhere like API, cookie, etc.
    this.set({
      name : "taro",
      age : 20
    });
  }
}

UserAttr.init()

View

View.use(viewComponent)

params :

View.useFilter(viewFilter)

params :

View.import(componentId, renderFunction)

params :
  • componentId : string
  • renderFunction : (userAttrs) => any
    • userAttrs : any

ViewComponent

interface UserSchema{
  profile:UserProfileSchema
}

class RenderHTML extends ViewComponent{
  id:string = "render-html";
  render(user:UserSchema){
    document.querySelector("#user-profile").innerHTML = `
      <div>name : ${user.proile.name}</div>
      <div>age : ${user.proile.age}</div>
    `;
  }
}

ViewComponent.render(userAttrs)

params :
  • userAttrs : any

ViewFilter

interface UserSchema{
  profile:UserProfileSchema
}

class Only20s extends ViewFilter{
  componentId:"my-component";
  validate(userAttrs:UserSchema, componentId:string){
    const age = userAttrs["profile"].age;
    if(!age) return false;
    return 20 <= age && age < 30;
  }
}

ViewFilter.validate(userAttrs, componentId)

params :
  • userAttrs : any
  • componentId : string

LICENSE

MIT