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

objectra

v1.1.1

Published

Utility for deep object duplication, serialization and parsing

Downloads

2

Readme

Objectra

Utility for deep object duplication, serialization and parsing.

Install

npm install objectra

Usage

Basic functionality with built-in transformators

Import the Objectra class

const { Objectra } = require('objectra');

Let's say we want to copy a value without losing any data (for example object inheritance) but remove all object references. In this case the duplicate method will help.

const set = new Set<string>(['Hello world']);
const duplicatedValue = Objectra.duplicate(set);

But sometimes we may have another need for example to serialize a value into a pure object.

const serializedSet = Objectra.serialize(set);

The returned data from the above method will return an object with the Objectra schema which gives the ability to parse it at any time.

const parsedSet = Objectra.parse(serializedSet);

Transformators

A Transformator is a set of transformers (parsing instructions) that Objectra uses to parse values. Each class has its own transformator. Objectra does not support implicit parsing of a class object and therefore if we try to parse a class instance that does not have a transformator registered it will throw an error.

Built-in class transformators:

  • All primitives (including Symbol and BigInt)
  • Object
  • Array
  • Objectra
  • Map
  • Set

Transformator creation

To understand how a transformator works we first create a class.

class Point {
    constructor(public x: number, public y: number) {}
}

Now we can create a transformator for the class. Let's add 2 methods in it:

  • construct which takes as an argument the value that was in the class before serialization and returns an instance of the class
  • simplify which takes an instance of a class as an argument and returns it as a pure object (object or array) or even as a primitive value
Objectra.addTransformator(Point, {
    construct: (content: any) => new Point(content.x, content.y),
    simplify: (point: Point) => ({ ...point }),
});

And it's all! We can now use Objectra to manage all future Point instances.

License

ISC

Author