view-sync
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

view-sync

View Sync logo

NPM Version NPM Downloads npm TypeScript version Tree shaking Dependencies npm package minimized gzipped size Commits Issues License Follow GitHub Sponsors

Lightweight alternative to Alpine.js' x-model attribute, that is CSP friendly (no 'unsafe-eval' needed).

Installation

With npm/yarn/pnpm/bun:

npm i view-sync

Usage

HTML:

<!-- Initialize view-sync and set initial value to "world" -->
<div id="app" data-sync-init="hello" data-sync-value="world">
    <!-- Value of these will be updated with value of `hello` in sync with each other -->
    <input type="text" data-sync="hello">
    <textarea data-sync="hello"></textarea>

    <!-- Text content of this will be updated with value of `hello` -->
    <span data-sync-text="hello"></span>

    <!-- This will be hidden if value of `hello` is falsy -->
    <div data-sync-state="hello">
        I will be hidden if `hello` is falsy
    </div>
</div>

JavaScript/TypeScript:

import { ViewSync } from 'view-sync';
ViewSync.Init();

Package Sidebar

Install

npm i view-sync

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

19.1 kB

Total Files

11

Last publish

Collaborators

  • matronator