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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lsync

v1.0.0

Published

Synchronize variables between client and server.

Readme

LSync

LSync is a library that synchronizes variables between an object on your client and server, via a socket.io socket.

Including

From Node.JS:

npm i --save lsync
const lsync = require('lsync')

From the Browser:

First, download lsync.js to your project directory.

<script src="lsync.js"></script>

Initialization

LSync instances are initialized exactly the same on the client and server. They must be supplied a common identifier which is unique on that socket, and a connected Socket.IO socket to use.

let s = lsync('shared-name-between-client-and-server', socket)

Publishing

From an LSync instance, a new variable can be created using:

s.publish({ name: 'foo', value: 'bar' })

After publishing a variable, it can be used and changed by both the client and server - which will both keep its value in sync.

// On Node A:
s.foo // => 'bar'
s.foo = 'hello'

// On Node B:
s.foo // => 'hello'

Read-Only (One-Way) Values

If you wish to create a value which can only be updated by the node that originally published it, you can specify the readonly option:

// On Node A:
s.publish({ name: 'test', value: 'hello', readonly: true })

// On Node B:
s.test // => 'hello'
s.test = 'foo' // Won't work, it's read-only on this end!
s.test // => 'hello'

// On Node A:
s.test = 'foo'
s.test // => 'foo'

Syncing Objects

Unfortunately, LSync cannot automatically detect and sync changes to an Object's properties. To sync an object, call s.sync(name) after each change:

// On Node A:
s.publish({ name: 'object', value: { a: 10, b: 20 } })

// On Node B:
s.object.a = 20

// On Node A:
s.object.a // => 10

// On Node B:
s.sync('object')

// On Node A:
s.object.a // => 20

Change Bindings

If you want to be notified whenever a certain value is changed, the bind function can help:

// On Node A:
s.publish({ name: 'foo', value: 'hello' })
s.bind('foo', (newValue) => console.log(`new value: ${newValue}`))

// On Node B:
s.foo = 'world'

// On Node A:
// => new value: ${newValue}

bind takes the name of the property to listen for, and a callback. This callback will be called whenever the property's value is changed, and is given a single argument: the new value.

Testing LSync

To test out LSync, clone the repository, run npm i, and then use npm test to start the LSync server. Once the server is running, visit localhost:3000 and open your browser's developer console. The server will open a REPL similar to that of your browser, and an instance of LSync is available in the s object on both.