un-eval

un_eval converts an Object to its source

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
un-eval
101.2.05 years ago6 years agoMinified + gzip package size for un-eval in KB

Readme

un-eval

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

Usage

You may use uneval in node or browser like this: ```javascript uneval(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)23 | Notes:
  1. ES5 style function only. Arrow functions, generator functions, and, native functions are not supported.
  1. All other object is treated as Object type.
  1. ({}), or will be generated if any circular found.

Examples

```javascript uneval(3); // '3' uneval(Math.PI); // '3.141592653589793' uneval('hello'); // '"hello"' uneval(Object(false)); // 'new Boolean(false)' uneval(function (x) { return x + 1; }); // '(function (x) { return x + 1; })' uneval(/regexp/ig); // '/regexp/gi' uneval(new Date(978307200000)); // '(new Date(978307200000))' uneval(1,2,3); // '1, 2, 3' uneval({x: 2, y: 3}); // '({"x":2, "y":3})' var obj1 = {}; obj1.x = obj1.y = { value: 3 }; uneval(obj1); // '({"y":({"value":3}), "x":({"value":3})})' var obj2 = {}; obj2.x = {}; obj2.y = {}; obj2.x.y = obj2.y; obj2.y.x = obj2.x; uneval(obj2); // '({"x":({"y":({"x":({})})}), "y":({"x":({"y":({})})})})' ```

eval & uneval

un
eval is disgned to be similar to uneval but works cross browser. uneval is similar to uneval, but there are few difference:
  1. uneval currently do not support some types such as Error.
  1. uneval will convert native function to "null".
  1. uneval will format codes differently from uneval.

Warning

Although, uneval is designed to output source with no side effect. But there may be some bugs or limitations in the code. You should avoid using uneval 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