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 🙏

© 2025 – Pkg Stats / Ryan Hefner

living-object

v0.0.9

Published

Compile JS objects into revivable JS code strings

Readme

Living Object

CI Tests npm version

Living Object serializes JS Objects into executable JS code. It preserves circular references and strict object equality.

Unlike other solutions that embeds custom protocols into JSON files, Living Object directly generates executable JavaScript code. Therefore, it's result can be directly imported as ES Module or evaluated in a wrapper function, achieving minimal performance overhead on the consumer side.

🔗 Documentation Website Coming Soon

Supported Data Types

  • ✅ Circular Reference & Strict Object Equality 🔥
  • ✅ Pure Functions (preserving attributes) 🔥
  • ✅ Custom Object API 🔥
  • undefined / null
  • ✅ Global Symbols
  • ✅ Array / Sparse Array
  • ✅ Map / Set
  • ✅ Date
  • ✅ RegExp
  • ✅ Error
  • ✅ ArrayBuffer / TypedArray / DataView

Usage

👋 Try it out at Stackblitz Playground !

1. Let's construct a really challenging input

// Create circular reference
const circular = {};
circular.loop = circular;

// Create a function with attributes
function bar() {
    return 'I have attributes!';
}
bar.hello = 'world';
bar.loop = bar;

const object = {
    // circular reference
    circular,
    // pure JS function
    foo() {
        return 'bar';
    },
    // function with attributes
    bar,
    // Singleton values
    singletons: [undefined, null, Infinity, NaN],
    // Builtin Functions
    Number,
    String,
    Boolean,
    // Well-known function that contains native code
    arrayPrototypePush: [].push,
    // Set and Map
    set: new Set(['a', 'b', 'c']),
    map: new Map([
        ['foo', 'bar'],
        [circular, 'circular'],
        ['circular', circular],
    ]),
    // Date object
    time: new Date('2025-12-31T12:00:00Z'),
    // RegExp
    regex: /^hello-world$/gi,
    // Binary data types
    typedArray: new Uint8Array([1, 2, 3]),
    arrayBuffer: new Uint16Array([4, 5, 6]).buffer,
    dataView: new DataView(new Uint32Array([7, 8, 9]).buffer),
};

2. Serialize it with Living Object

import { stringify } from 'living-object';

console.log(stringify(object, { type: 'function' }));

Output { type: 'function' }

Generate code with a return statement:

// Formatted by prettier
'use strict';
const A = { loop: 0 },
    B = Object.assign(
        function bar() {
            return 'I have attributes!';
        },
        { hello: 'world', loop: 0 },
    );
A.loop = A;
B.loop = B;
return {
    circular: A,
    foo: function foo() {
        return 'bar';
    },
    bar: B,
    singletons: [undefined, null, Infinity, NaN],
    Number,
    String,
    Boolean,
    arrayPrototypePush: Array.prototype.push,
    set: new Set(['a', 'b', 'c']),
    map: new Map([
        ['foo', 'bar'],
        [A, 'circular'],
        ['circular', A],
    ]),
    time: new Date(1767182400000),
    regex: /^hello-world$/gi,
    typedArray: new Uint8Array([1, 2, 3]),
    arrayBuffer: Uint8Array.from([4, 0, 5, 0, 6, 0]).buffer,
    dataView: new DataView(
        Uint8Array.from([7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0]).buffer,
        0,
        12,
    ),
};

Output { type: 'function' }

Generate code with an export default statement:

  "use strict";
  ...
  A.loop = A;
  B.loop = B;
- return {
+ export default {
    ...
  };

Advanced: Custom Object API

📄 Documentation Coming Soon

Please refer to builtins.ts for examples.

Advanced: Context Injection

📄 Documentation Coming Soon

Please refer to context.test.js for examples.

Continuous Integration

Living Object is tested against the following environments before each release:

  • Host OS: Ubuntu@latest, Windows@latest
  • Node.js: @latest, 22, 20, 18, 16