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 🙏

© 2026 – Pkg Stats / Ryan Hefner

als-bind

v6.0.0

Published

bind and manage content inside dom elements

Readme

Bind 6

Bind 6 builded from scratch and it's something different compared to earlier versions. The main concept of Bind is to bind between dom elements and js variables and methods.

  • Dom and BindData (form v5, will be published as separated package)

Bind includes 3 classes:

  1. Bind - for bind variables in frontend
  2. BindCollection - for bind collection on frontend
  3. BindNode - for building binds in node.js and then managing it on frontend

Basics

After you have install Bind, include the script in your html and run Bind.bind(vars:object) with your vars. Then, just give bind name to element, and add your variables anywhere on any attribute or innerHTML.

Here is the example, how it works:

<head>
    <script src="node_modules/als-bind/bind.js"></script>
    <script>Bind.bind({test:'Hello world',testClass:'test'})</script>
</head>
<body>
    <div bind="test" class="some {{ testClass }} some1">some {{ $test }} some</div>
    <button onclick="Bind.vars.$test = 'Hello again'">change</button>
</body>

As shown on example above, variable test inside vars binded on element with bind="test". And can be changed by Bind.vars.$test to any other string. Bind.vars includes all vara you have addede with bind method, but in addition if variable is binded, it has the setter with $ too.

For example, you can do the folowing

Bind.vars.$test = Bind.vars.test + 'Have a good day'.

Variables inside objects

You can bind variables from objects and arrays. Here is example how it works:

<script>
    let users = [{name:'Alex', age:20}]
    Bind.bind({users})
</script>
<div bind="test">Hello {{ $users[0].name }}. You are {{ $users[0].age }} years old.</div>
<input type="text" oninput="Bind.vars.users[0].$name = this.value">

Methods inside binds

You can add any method you want, like this:

<script>
    function hello(name,age) {
        return `Hello ${name}. You are ${age} years old.`
    }
    let users = [{name:'Alex', age:20}]
    Bind.bind({users,hello})
</script>
<div bind="test">{{ Bind.vars.hello($users[0].name,$users[0].age) }}</div>
<div bind="test1">{{ $hello($users[0].name,$users[0].age) }}</div>
<div bind="test2">{{ hello($users[0].name,$users[0].age) }}</div>
<input bind="input" type="text" 
oninput="Bind.vars.users[0].$name = this.value" 
value="{{$users[0].name}}">

On example above, shown that you can use fuction from Bind.vars (test and test1) or as function outside the Bind (test2). Also, you can bind the same variables on other binded elements too (bind=input,test,test1,test2)

Binded elements

All binded elements stored inside Bind.binds as Bind.binds{bindName:element}. For example you can do the folowing:

Bind.binds.test2.remove()

Bind innerHtml with elements

In case you bind variable inside child of bind element, every time you set new value, all bind element changing.

<div bind="test">
    some
    <span>{{$test}}</span>
    some
</div>

On example above, every time you will change Bind.vars.$test, [bind="test"]'s innerHtml will change include the element inside.

BindCollection

BindCollection is a separated class inside bind.js. To use it, you need to set seccond parameter on Bind.bind as true and then to use template for bindidng array. Here is the example:

<script>
    Bind.bind(
        {colors:['red','green','blue']},
        true
    )
</script>
<body>
   <template collection-template="colors">
      <div>
         <span bind="color" style="color:{{ $colors[index] }};">{{ $colors[index] }}</span>
      </div>
   </template>
</body>

On example above, second parameter is true, and Bind look for template[collection-template] elements. It takes first element in template as template and then place binded clones before the template element. Now you can mange the collection with :

Collection methods:

Bind.vars.colors.remove(index)
Bind.vars.colors.add(object)
Bind.vars.colors.next(index)
Bind.vars.colors.prev(index)
Bind.vars.colors.move(from,to)

index stored in clone main element as clone.index.

Here another example:

   <script src="users.js"></script>
   <script>Bind.bind({
      users,
      getUserName: index => Bind.vars.users[index].name,
      },true)</script>
</head>
<body>
   <template collection-template="users">
      <div>
         <div id="test">Some</div>
         <div bind="user">User name: {{ $users[index].name }}</div>
         <div bind="user">User name: {{ $users[index].age }}</div>
         <button onclick="console.log(this.parentNode.index)">index</button>
         <button onclick="Bind.vars.users.remove(this.parentNode.index)">remove</button>
         <button onclick="Bind.vars.users.prev(this.parentNode.index)">prev</button>
         <button onclick="Bind.vars.users.next(this.parentNode.index)">next</button>
      </div>
   </template>
   <hr>
   <div><input type="text" oninput="Bind.vars.users[2].$name = this.value"></div>
   <div><button onclick="add()">Add</button></div>
   <script>
      function add() {
         Bind.vars.users.add({
         "age": 25,
         "name": "Super puper",
         })
      }
   </script>
</body>

BindNode

let BindNode = require('als-bind')

let newDocument = BindNode.bind(/*html*/`
<!DOCTYPE html>
<html lang="en">
<head>
   <title>Test</title>
   <script src="/node_modules/als-bind/bind.js"></script>
</head>
<body>
   <div>
      <div bind="aa">{{ $hello($user.name,$user.age) }}</div>
      <div bind="aa1">{{ $user.name }}</div>
      <button onclick="Bind.vars.user.$age = Bind.vars.user.age+1">older</button>
      <button onclick="Bind.vars.user.$age = Bind.vars.user.age-1">younger</button>
   </div>
   <input bind="input" type="text" oninput="Bind.vars.user.$name = this.value" value="{{ $user.name }}">
</body>
</html>
`,{
   user:{name:'Alex',age:35},
   hello:(name,age)=>`Hello ${name}. How are you? Your age is ${age}.`,
})

require('fs').writeFileSync('test.html',newDocument)