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

un-eval

v1.2.0

Published

un_eval converts an Object to its source

Downloads

261,469

Readme

un-eval

un_eval is a function that converts an Object to its source.

Usage

You may use un_eval in node or browser like this:

un_eval(yourObject)

Support types

The un_eval support following types

| Type | Support | |----|----| | null | (Yes) | | undefined | (Yes) | | number | (Yes) | | string | (Yes) | | boolean | (Yes) | | Number | (Yes) | | String | (Yes) | | Boolean | (Yes) | | Date | (Yes) | | RegExp | (Yes) | | function | (Yes)[1] | | Array | (Yes) | | Object | (Yes)[2][3] |

Notes:

  1. ES5 style function only. Arrow functions, generator functions, and, native functions are not supported.
  2. All other object is treated as Object type.
  3. ({}), or [] will be generated if any circular found.

Examples

un_eval(3); // '3'
un_eval(Math.PI); // '3.141592653589793'
un_eval('hello'); // '"hello"'
un_eval(Object(false)); // 'new Boolean(false)'
un_eval(function (x) { return x + 1; }); // '(function (x) { return x + 1; })'
un_eval(/regexp/ig); // '/regexp/gi'
un_eval(new Date(978307200000)); // '(new Date(978307200000))'
un_eval([1,2,3]); // '[1, 2, 3]'
un_eval({x: 2, y: 3}); // '({"x":2, "y":3})'

var obj1 = {};
obj1.x = obj1.y = { value: 3 };
un_eval(obj1); // '({"y":({"value":3}), "x":({"value":3})})'

var obj2 = {};
obj2.x = {};
obj2.y = {};
obj2.x.y = obj2.y;
obj2.y.x = obj2.x;
un_eval(obj2); // '({"x":({"y":({"x":({})})}), "y":({"x":({"y":({})})})})'

eval & uneval

un_eval is disgned to be similar to uneval but works cross browser.

un_eval is similar to uneval, but there are few difference:

  1. un_eval currently do not support some types such as Error.
  2. un_eval will convert native function to "null".
  3. un_eval will format codes differently from uneval.

Warning

Although, un_eval is designed to output source with no side effect. But there may be some bugs or limitations in the code. You should avoid using un_eval any untrustable objects (maybe from user input) then eval it. NEVER use eval unless you know what will happen.

USE AS YOUR OWN RISK.

License

The MIT License