Skip to content

Commit

Permalink
5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AFatNiBBa committed Oct 8, 2021
1 parent 0df1894 commit 886fc7a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
22 changes: 12 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
[WIP]: ITA => ENG
[WIP]: doc (eng)
[WIP]: {function,object,array}.{get,set}
[/!\]: le proprietà gestite di oggetti gestiti non vengono salvate anche se sovrascritte dall'utente
[/!\]: "__proto__" proprietà asestante e non getter/setter di "Object.prototype" setta comunque il prototipo
Expand All @@ -27,7 +27,8 @@ var uneval = (typeof module === "undefined" ? {} : module).exports = (function (
const pretty = opts.pretty = (opts.pretty ?? true) || "";
opts.space = pretty && ((opts.space ?? " ") || "");
opts.endl = pretty && ((opts.endl ?? "\n") || "");
opts.tab = pretty && ((opts.tab ?? "\t") || "");
opts.tab = pretty && (typeof opts.tab === "number" ? opts.space.repeat(opts.tab) : ((opts.tab ?? "\t") || ""));
opts.custom ??= true;
opts.method ??= true;
opts.proxy ??= true;
opts.proto ??= true;
Expand Down Expand Up @@ -141,7 +142,7 @@ var uneval = (typeof module === "undefined" ? {} : module).exports = (function (
return out; // É una proxy e non credo possa contenere proprietà proprie
}
}
if (obj?.[utils.customScan] instanceof Function)
if (opts.custom && obj?.[utils.customScan] instanceof Function)
return obj[utils.customScan](out, opts, cache, prev, parent, uneval);
else if (obj instanceof Symbol) // Scan parte primitiva
out.delegate = utils.Delegate.from(obj.valueOf(), opts, cache); // Non serve "prev", tanto un simbolo non ha sotto-proprietà da salvare
Expand Down Expand Up @@ -189,18 +190,19 @@ var uneval = (typeof module === "undefined" ? {} : module).exports = (function (
}

//[ Export ]
const customScan = Symbol.for("uneval.utils.customScan"), customSource = Symbol.for("uneval.utils.customSource");
return Object.assign(uneval, {
uneval, write, source, scan, fromProxy,

[Symbol.for("uneval.utils.customScan")]: x => x,
[Symbol.for("uneval.utils.customSource")]: () => `(${ arguments.callee })()`,
[customScan]: x => x,
[customSource]: () => `(${ arguments.callee })()`,

/**
* Core functions and values that make "uneval()" work.
*/
utils: {
customScan: Symbol.for("uneval.utils.customScan"),
customSource: Symbol.for("uneval.utils.customSource"),
customScan,
customSource,
method: /^(async\s+)?([\["*]|(?!\w+\s*=>|\(|function\W|class(?!\s*\()\W))/,
assign: (a,b)=>Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)), // Se serve le funzioni impostano "opts.assign" su 'true'
showFormatting: { space: "\x1b[101m \x1b[0m", tab: "\x1b[104m \x1b[0m", endl: "\x1b[105m \n\x1b[0m" },
Expand Down Expand Up @@ -434,7 +436,7 @@ var uneval = (typeof module === "undefined" ? {} : module).exports = (function (
assign(obj, struct, opts, level) {
//[ Conversione personalizzata ]
const { utils } = uneval;
if (obj[utils.customSource] instanceof Function)
if (opts.custom && obj[utils.customSource] instanceof Function)
return obj[utils.customSource](struct, opts, level, uneval);

//[ Valori gestiti ]
Expand Down Expand Up @@ -477,10 +479,10 @@ var uneval = (typeof module === "undefined" ? {} : module).exports = (function (

//[ Unione ]
delta = ((array || managed) && temp.length) ? opts.tab : "";
if (array) managed ??= this.array(obj, struct, opts, level + delta); // Viene posto dopo il settaggio definitivo di "custom" perchè l'array ha bisogno di più contesto per capire se ci sono proprietà personalizzate
if (array) managed ??= this.array(obj, struct, opts, level + delta); // Viene posto dopo il settaggio definitivo di "delta" perchè l'array ha bisogno di più contesto per capire se ci sono proprietà personalizzate
const tl = opts.space + opts.endl + level; // Tonda (Ultima)
const t = tl + opts.tab; // Tonda
const gl = tl + delta; // Graffa (Ultima)
const gl = tl + delta; // Graffa (Ultima)
const g = gl + opts.tab; // Graffa
if (managed && !temp.length)
return managed;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uneval.js",
"version": "5.1.0",
"version": "5.2.0",
"description": "Convert an object to its source code (With references and PROXIES too!)",
"main": "main.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const uneval = require("uneval.js");
```js
const { uneval } = require("uneval.js");
```
Simply pass the function as an argument to obtain the source code and eval it to obtain the object again.
Simply pass an object to the function as an argument to obtain the source code and eval it to obtain the object again.
> You additionally can give some options to personalize the output
```js
const a = {};
Expand Down Expand Up @@ -85,8 +85,12 @@ The available options are:
- It defaults to `"\n"`
- **`tab`**
- Set the string that will replace the tabs in the output
- Setting it to a number "n" is like setting it to the `space` option repeated "n" times
- Setting it to `false` is like setting it to `""`
- It defaults to `"\t"`
- **`custom`**
- If is set to `false` the custom conversions will be ignored
- It defaults to `true`
- **`method`**
- If is set to `false` allows only the safe, but way uglier, syntax for objects methods
- It defaults to `true`
Expand Down

0 comments on commit 886fc7a

Please sign in to comment.