Common attribute serializers for lit-element
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.eslintrc.json
.gitignore
README.md
jest.config.js
package-lock.json
package.json
tsconfig.json

README.md

lit-element-serializers

A selection of common attribute serializers for use with LitElement.

These allow simple (de)serialization around common data structures such as objects, dates, strings and so on.

Install

Simple:

$ npm i -S lit-element-serializers

Usage

To use these:

import { NullableStringSerializer } from 'lit-element-serializers';

class MyElement extends LitElement {
  @property({ type: NullableStringSerializer })
  foo = 'test';
}

Serializers

NullableStringSerializer

The nullable string serializer allows easy serialization between string values and null or the given value, meaning falsy strings will be treated and set on your element as null.

ObjectSerializer

Simply a wrapper around JSON.parse and JSON.stringify, so any value passed to the property using this serializer will attempt to parse or output JSON.

This behaves similar to how type: Object did in Polymer.