New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lucia

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lucia

Tiny library for tiny web apps.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25K
decreased by-26.94%
Maintainers
1
Weekly downloads
 
Created
Source

Lucia

Code Size NPM Version GitHub license PRs Welcome

What is Lucia?

Lucia is a tiny JavaScript (UMD compatible) library as a drop-in replacement for jQuery and vanilla JavaScript web apps. Some features of Lucia are:

  • Declarative: Lucia provides a declarative API similar to Vue to create views, making development predictible and intiuitive through markup-centric code.
  • Reactive: When the view is changed, the interal reference Virtual DOM will automatically react and will update and render the new view in realtime.
  • Lightweight: Lucia is extremely light (~4kb min+brotli) and performant as it does not use a tranditional Virtual DOM, rather it renders directives only if necessary by skipping static nodes through selectors.

Installation

Lucia is currently is installable through a CDN and also supports UMD (Node, Browser, Isomorphic/Universal). Put this within your <head> tags in html.

<!-- development version, includes helpful console warnings -->
<script src="https://unpkg.com/lucia/dist/lucia.js" defer></script>
<!-- production version, optimized for size and speed -->
<script src="https://unpkg.com/lucia" defer></script>

Example

Below is an example of a clicker game in Lucia. No, your eyes aren't fooling you - it's really that simple.

<div l-use="{ count: 0 }">
  <button l-text="count" l-on:click="++count"></button>
</div>

Features

Lucia relies on directives in markup to perform functions:

DirectiveDescription
l-useDeclares a new component scope.
l-textWorks similarly to l-bind, but will update the textContent of an element.
l-htmlWorks similarly to l-bind, but will update the innerHTML of an element.
l-ifToggles display: none; on the element depending on expression (true or false).
l-onAttaches an event listener to the element. Executes JavaScript expression when emitted.
l-bindSets the value of an attribute to the result of a JavaScript expression.
l-joinCreate new DOM nodes for each item in an array.
l-modelAdds "two-way data binding" to an element. Keeps input element in sync with view data.

Creating a Component

Lucia allows us to create component scopes. It tells the library to initialize a new component with the following data object.

<div l-use="{ message: 'Hello World' }">
  <p l-text="message"></p>
</div>

Declarative Rendering

At the core of Lucia is a system that enables us to declaratively render data to the DOM using the straightforward l-text and l-html directives:

<div l-use="DeclarativeRendering()">
  <p l-text="message"></p>
  <p l-html="markupMessage"></p>
</div>
function DeclarativeRendering() {
  return {
    message: 'Hello World!',
    markupMessage: '<span>Hello World with Markup!</span>',
  };
}

Conditionals

It’s easy to toggle the presence of an element, too:

<div l-use="Conditionals()">
  <button l-if="!show">You can't see me</button>
  <button l-if="show">You can see me</button>
</div>
function Conditionals() {
  return { show: true };
}

Event Handlers

To let users interact with your app, we can use the l-on directive to attach event listeners that invoke methods on our Lucia instances:

<div l-use="EventHandlers()">
  <button l-on:click="announce()" l-text="message"></button>
</div>
function EventHandlers() {
  return {
    message: 'Hello world!',
    announce() {
      alert(this.message);
    },
  };
}

Attribute Binding

In addition to text interpolation, we can also bind element attributes using the l-bind directive:

<div l-use="AttributeBinding()">
  <h1 l-bind:class="{ hello: show }">Classes are cool</h1>
  <h1 l-bind:style="color">Styles are sassy</h1>
</div>
function AttributeBinding() {
  return {
    show: true,
    color: { color: 'purple' },
  };
}

List Rendering

We can also use the l-join directive to render a list of items based on an array. Note that performance will be affected if using array mutators.

<div l-use="ListRendering()">
  <p l-join="fruits by , "></p>
</div>
function ListRendering() {
  return {
    fruits: ['apple', 'orange', 'banana'],
  };
}

Form Input Bindings

You can use the l-model directive to create two-way data bindings on form input, textarea, and select elements.

<div l-use="FormInputBindings()">
  <input l-model="message" />
  <p l-text="message"></p>
</div>
function FormInputBindings() {
  return {
    message: 'Nothing submitted yet',
  };
}

License

Lucia is MIT licensed.

Keywords

FAQs

Package last updated on 23 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc