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 🙏

© 2024 – Pkg Stats / Ryan Hefner

reserializer

v0.1.0

Published

Smart serializer builder

Downloads

3

Readme

Reserializer

Travis Codecov npm npm Known Vulnerabilities JavaScript Style Guide

Build smart serializers.

Why Reserializer?

Data serialization is used to help send and store data when objects can't be sent, such as HTTP requests, file storage, local storage, and IPC. Reserializer is designed to be a quick and easy solution to build serializers that are able to both serialize and unserialize data.

Example

This is a quick example that converts dates, removes sensetive data, and converts to a JSON string, once created serializer has two methods serializer.serialize and serializer.unserialize that can recieve data and transform it accordingly.

import { asJSON, create, date, remove } from 'reserializer'

const serializer = create(
  asJSON,
  date('_meta.created'),
  date('_meta.updated'),
  remove('internalID')
)

const input = {
  internalID: 'something private',
  _meta: {
    created: new Date('2017-01-01T00:00:00'),
    updated: new Date('2017-01-01T12:00:00')
  },
  extra: true
}

const output = serializer.serialize(input) 
  // => '{"_meta":{"created":"2017-01-01T00:00:00","updated":"2017-01-01T12:00:00"},"extra":true}'


const newInput = serializer.unserialize(output)
  // => {
  //   _meta: {
  //     created: new Date('2017-01-01T00:00:00'),
  //     updated: new Date('2017-01-01T12:00:00')
  //   },
  //   extra: true
  // }

API

Utilities

Utilities don't directly affect data but are used to help apply tranforms accordingly.

create(...transforms)

Recieves multiple tranforms and runs data through each transform returning the final version. A serializer from reserializer can accept and object or array, for arrays the serializer will loop through each item applying the transforms. If create is given transforms A, B, and C as create(A, B, C), on serialize, create will run the transforms in reverse order, i.e. C -> B -> A, and on unserialize, create will run the transforms in the given order, i.e. A -> B -> C.

at(property, ...transforms)

This utility will run tranfroms on a given property. It behaves the same as create with appling transforms and can handle arrays as well.

Transforms

Transforms are used to convert the data.

asJSON / asPrettyJSON

This transform converts data between an object and JSON string. This should be the first transform in the list when creating a serializer. asPrettyJSON produces a nicely indented JSON structure and is recommened for debugging and development.

date(property)

This transform convertes dates between Date objects and ISO 8601 strings.

remove(property)

This transform removes a property from the object on both serialization and unserialization.

rename(oldProperty, newProperty)

This transform moves a property to a new path. Useful to help restructure data from an API request.

restructure(map)

This transform uses the map to move properties around. The given map uses the keys as the input keys and the values as output keys. Only properties in the map will be passed through the transform, all others will be lost.

const input = {
  test: true
}

restructure({test: '_meta.test'}).serialize(input)
// => {_meta: {test: true}}

A map can have nested objects for the input side and will use the structure accordingly, e.g. {'_meta.test': 'test'} is the same as {_meta: {test: 'test'}}. Also if you give a value of true the property will be copied to the same location, e.g. {test: 'test'} is the same as {test: true}.