Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tomlify-j0.4

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tomlify-j0.4 - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

CHANGELOG.md

24

dist/tomlify.min.js

@@ -1,12 +0,12 @@

;(function(){'use strict';function t(a,c,b){if(null==a)throw Error("Undefined or null cannot be stringified.");if(F(a))throw Error("Converting circular structure to TOML.");c="function"===typeof c?c:null;b=B(b);if(!n(a))return C(a,c,b);var d=[];w({path:[],table:{"":a},b:!1,replace:c,level:0,a:b,c:d},"",a,function(a,b,c){if(n(c))""!==b&&(0<d.length&&d.push(""),b=a.b?"[["+x(a.path,!0)+"]]":"["+x(a.path,!0)+"]",d.push(q(b,a.level,a.a)));else if(p(c))if(k(b))u(c)||(b=A(a,b,c),k(b)&&d.push(q(b,a.level,a.a)));else return!0;
else return k(b)&&(b=A(a,b,c),k(b)&&d.push(q(b,a.level,a.a))),!0});return d.join("\n")}function B(a){return k(a)?a:"number"===typeof a&&0<=a&&isFinite(a)&&Math.floor(a)===a?D(" ",a):""}function q(a,c,b){c=D(b,c);return a.replace(/^(?!$)/mg,c)}function D(a,c){if(a.repeat)return a.repeat(c);for(var b="",d="";0<c;)d+=d||a,c&1&&(b+=d),c>>>=1;return b}function w(a,c,b,d){var e;if(a.replace&&0===a.path.length&&(e=y(a,c,b),k(e)&&a.c.push(e),!1!==e))return;if(!d(a,c,b)){c=a.table;a.table=b;if(p(b)){var g=
a.b;a.b=u(b);for(var f=0,l=b.length;f<l;f++)a.path.push(f),w(a,f,b[f],d),a.path.pop();a.b=g}else if(n(b)){g=a.b;a.b=!1;var r=[],m=[],h;for(h in b)Object.prototype.hasOwnProperty.call(b,h)&&(e=b[h],f=0<a.path.length&&(p(e)?u(e):n(e)),p(e)&&u(e)?m.push(h,e,f):n(e)?r.push(h,e,f):(a.path.push(h),w(a,h,e,d),a.path.pop()));if(a.replace){f=0;for(l=r.length;f<l;f+=3)a.path.push(r[f]),e=y(a,r[f],r[f+1]),!1!==e&&(k(e)&&a.c.push(q(e,a.level,a.a)),r[f+1]=null),a.path.pop();f=0;for(l=m.length;f<l;f+=3){a.path.push(m[f]);
e=y(a,m[f],m[f+1]);if(!1!==e)k(e)&&a.c.push(q(e,a.level,a.a)),m[f+1]=null;else for(b=0,h=m[f+1].length;b<h;b++)if(a.path.push(b),e=y(a,b,m[f+1][b]),a.path.pop(),!1!==e)if(null==e)m[f+1][b]=null;else{e=A(a,m[f],m[f+1]);k(e)&&a.c.push(q(e,a.level,a.a));m[f+1]=null;break}a.path.pop()}}h=r.concat(m);f=0;for(l=h.length;f<l;f+=3)null!=h[f+1]&&(a.path.push(h[f]),h[f+2]&&a.level++,w(a,h[f],h[f+1],d),h[f+2]&&a.level--,a.path.pop());a.b=g}a.table=c}}function y(a,c,b){if(a.replace){b=a.replace.call({path:a.path.slice(0),
table:a.table},c,b);if(k(b))return v(c)+" = "+b;if(null==b)return null;if(!1!==b)throw Error(l(a.path,"Replacer must return a string, false, null or undefined."));}return!1}function A(a,c,b){var d=v(c);if(!d)throw Error(l(a.path,"Key cannot be an empty string."));a=z(a,c,b);return k(a)?d+" = "+a:null}function v(a){return a?/^[a-zA-Z0-9\-_]+$/.test(a)?a:E(a):!1}function C(a,c,b){if(null==a)throw Error("Undefined or null cannot be stringified.");return z({path:[],table:{"":a},b:!1,replace:"function"===
typeof c?c:null,level:0,a:B(b)},"",a)}function z(a,c,b){if(a.replace){c=a.replace.call({path:a.path.slice(0),table:a.table},c,b);if(k(c))return c;if(null==c)return null;if(!1!==c)throw Error(l(a.path,"Replacer must return a string, false, null or undefined."));}switch(g(b)){case g.Boolean:return b?"true":"false";case g.String:return E(b);case g.Number:if(!isFinite(b))throw Error(l(a.path,"Number must be finite."));a=(Number.isInteger?Number.isInteger(b):Math.floor(b)===b)?b.toFixed(1):String(b);a=
a.replace(/([eE])(\d)/,"$1+$2");return/[.eE]/.test(a)?a:a+".0";case g.Array:var d;a:{if(!(2>b.length)){d=g(b[0]);c=1;for(var e=b.length;c<e;c++)if(null!=b[c]&&g(b[c])!==d){d=!0;break a}}d=!1}if(d)throw Error(l(a.path,"Array cannot contain values of different types."));c=a.table;a.table=b;d=[];for(var e=0,n=b.length;e<n;e++){a.path.push(e);var f=z(a,e,b[e]);k(f)&&d.push(f);a.path.pop()}a.table=c;if(c=0<d.length&&a.a){a:{if(!(1>b.length))for(c=0,e=b.length;c<e;c++)if(p(b[c])){c=!0;break a}c=!1}c=c||
u(b)}return c?"[\n"+q(d.join(",\n"),1,a.a)+"\n]":"["+d.join(", ")+"]";case g.Date:if(!isFinite(b.getTime()))throw Error(l(a.path,"Invalid Date"));return b.toISOString();default:if(null==b)a=null;else{c=a.table;a.table=b;e=[];for(d in b)if(Object.prototype.hasOwnProperty.call(b,d)&&null!=b[d]){if(!d)throw Error(l(a.path,"Key cannot be an empty string."));a.path.push(d);n=z(a,d,b[d]);k(n)&&e.push(v(d)+" = "+n);a.path.pop()}a.table=c;a="{"+e.join(", ")+"}"}return a}}function E(a){return"object"===typeof JSON&&
JSON?JSON.stringify(a):'"'+String(a).replace(/[\x00-\x1F"\\]/g,function(a){switch(a){case '"':case "\\":return"\\"+a;case "\t":return"\\t";case "\n":return"\\n";case "\r":return"\\r";case "\b":return"\\b";case "\f":return"\\f";default:return a=a.charCodeAt(0).toString(16),"\\u"+"0000".substr(a.length)+a}})+'"'}function F(a){function c(a,d){if(!p(a)&&!n(a))return!1;if(-1!==d.indexOf(a))return!0;d.push(a);for(var b in a)if(Object.prototype.hasOwnProperty.call(a,b)){var g=d.length;if(c(a[b],d))return!0;
d.splice(g)}return!1}return c(a,[])}function u(a){if(1>a.length)return!1;for(var c=0,b=a.length;c<b;c++)if(n(a[c]))return!0;return!1}function n(a){return null!==a&&"object"===typeof a&&!(p(a)||g(a)===g.Date)}function k(a){return"string"===typeof a}function g(a){return Object.prototype.toString.call(a)}function l(a,c){return(x(a)||"<root>")+": "+c}function x(a,c){if(0===a.length)return"";for(var b="",d=0,e=a.length;d<e;d++)if(k(a[d])&&a[d])b+=(b?".":"")+v(a[d]);else if("number"===typeof a[d])c||(b+=
(b?".":"")+"["+a[d]+"]");else return!1;return b?b:!1}g.Boolean=g(!1);g.String=g("");g.Number=g(0);g.Array=g([]);g.Date=g(new Date(0));var p=Array.isArray||function(a){return g(a)===g.Array};t.toKey=function(a,c){if(k(a)){var b=v(a);if(!b)throw Error("Key cannot be an empty string.");return b}if(p(a)){b=x(a,c);if(!1===b)throw Error("Key path must consist of non-empty string(s).");return b}throw Error("Invalid Arguments for tomlify.toKey({String | Array})");};t.toValue=C;null!=("undefined"!==typeof module&&
null!==module?module.exports:void 0)?module.exports=t:"function"===typeof define&&define.amd?define([],function(){return t}):this.tomlify=t}).call(this);
;(function(){'use strict';function u(a,c,b){if(null==a)throw Error("Undefined or null cannot be stringified.");if(G(a))throw Error("Converting circular structure to TOML.");c="function"===typeof c?c:null;b=C(b);if(!q(a))return D(a,c,b);var d=[];x({path:[],table:{"":a},c:!1,b:!1,replace:c,level:0,a:b,f:d},"",a,function(a,b,c){if(q(c))""!==b&&(0<d.length&&d.push(""),b=a.b?"[["+y(a.path,!0)+"]]":"["+y(a.path,!0)+"]",d.push(r(b,a.level,a.a)));else if(t(c))if(k(b))v(c)||(b=B(a,b,c),k(b)&&d.push(r(b,a.level,a.a)));else return!0;
else return k(b)&&(b=B(a,b,c),k(b)&&d.push(r(b,a.level,a.a))),!0});return d.join("\n")}function C(a){return k(a)?a:"number"===typeof a&&0<=a&&isFinite(a)&&Math.floor(a)===a?E(" ",a):""}function r(a,c,b){c=E(b,c);return a.replace(/^(?!$)/mg,c)}function E(a,c){if(a.repeat)return a.repeat(c);for(var b="",d="";0<c;)d+=d||a,c&1&&(b+=d),c>>>=1;return b}function x(a,c,b,d){var f;if(a.replace&&0===a.path.length&&(f=z(a,c,b),k(f)&&a.f.push(f),!1!==f))return;if(!d(a,c,b)){c=a.table;a.table=b;if(t(b)){var g=
a.b;a.b=v(b);for(var e=0,n=b.length;e<n;e++)a.path.push(e),x(a,e,b[e],d),a.path.pop();a.b=g}else if(q(b)){g=a.b;a.b=!1;var l=[],m=[],h;for(h in b)Object.prototype.hasOwnProperty.call(b,h)&&(f=b[h],e=0<a.path.length&&(t(f)?v(f):q(f)),t(f)&&v(f)?m.push(h,f,e):q(f)?l.push(h,f,e):(a.path.push(h),x(a,h,f,d),a.path.pop()));if(a.replace){e=0;for(n=l.length;e<n;e+=3)a.path.push(l[e]),f=z(a,l[e],l[e+1]),!1!==f&&(k(f)&&a.f.push(r(f,a.level,a.a)),l[e+1]=null),a.path.pop();e=0;for(n=m.length;e<n;e+=3){a.path.push(m[e]);
f=z(a,m[e],m[e+1]);if(!1!==f)k(f)&&a.f.push(r(f,a.level,a.a)),m[e+1]=null;else for(b=0,h=m[e+1].length;b<h;b++)if(a.path.push(b),f=z(a,b,m[e+1][b]),a.path.pop(),!1!==f)if(null==f)m[e+1][b]=null;else{f=B(a,m[e],m[e+1]);k(f)&&a.f.push(r(f,a.level,a.a));m[e+1]=null;break}a.path.pop()}}h=l.concat(m);e=0;for(n=h.length;e<n;e+=3)null!=h[e+1]&&(a.path.push(h[e]),h[e+2]&&a.level++,x(a,h[e],h[e+1],d),h[e+2]&&a.level--,a.path.pop());a.b=g}a.table=c}}function z(a,c,b){if(a.replace){b=a.replace.call({path:a.path.slice(0),
table:a.table},c,b);if(k(b))return w(c)+" = "+b;if(null==b)return null;if(!1!==b)throw Error(l(a.path,"Replacer must return a string, false, null or undefined."));}return!1}function B(a,c,b){var d=w(c);if(!d)throw Error(l(a.path,"Key cannot be an empty string."));a=A(a,c,b);return k(a)?d+" = "+a:null}function w(a){return a?/^[a-zA-Z0-9\-_]+$/.test(a)?a:F(a):!1}function D(a,c,b){if(null==a)throw Error("Undefined or null cannot be stringified.");return A({path:[],table:{"":a},b:!1,replace:"function"===
typeof c?c:null,level:0,a:C(b)},"",a)}function A(a,c,b){if(a.replace){c=a.replace.call({path:a.path.slice(0),table:a.table},c,b);if(k(c))return c;if(null==c)return null;if(!1!==c)throw Error(l(a.path,"Replacer must return a string, false, null or undefined."));}switch(g(b)){case g.Boolean:return b?"true":"false";case g.String:return F(b);case g.Number:if(!isFinite(b))throw Error(l(a.path,"Number must be finite."));a=(Number.isInteger?Number.isInteger(b):Math.floor(b)===b)?b.toFixed(1):String(b);a=
a.replace(/([eE])(\d)/,"$1+$2");return/[.eE]/.test(a)?a:a+".0";case g.Array:var d;a:{if(!(2>b.length)){d=g(b[0]);c=1;for(var f=b.length;c<f;c++)if(null!=b[c]&&g(b[c])!==d){d=!0;break a}}d=!1}if(d)throw Error(l(a.path,"Array cannot contain values of different types."));d=a.table;a.table=b;c=[];f=a.c;v(b)&&(a.c=!0);for(var p=0,e=b.length;p<e;p++){a.path.push(p);var n=A(a,p,b[p]);k(n)&&c.push(n);a.path.pop()}a.c=f;a.table=d;return!a.c&&0<c.length&&a.a?"[\n"+r(c.join(",\n"),1,a.a)+"\n]":"["+c.join(", ")+
"]";case g.Date:if(!isFinite(b.getTime()))throw Error(l(a.path,"Invalid Date"));return b.toISOString();default:if(null==b)a=null;else{c=a.table;a.table=b;f=a.c;a.c=!0;p=[];for(d in b)if(Object.prototype.hasOwnProperty.call(b,d)&&null!=b[d]){if(!d)throw Error(l(a.path,"Key cannot be an empty string."));a.path.push(d);e=A(a,d,b[d]);k(e)&&p.push(w(d)+" = "+e);a.path.pop()}a.c=f;a.table=c;a="{"+p.join(", ")+"}"}return a}}function F(a){return"object"===typeof JSON&&JSON?JSON.stringify(a):'"'+String(a).replace(/[\x00-\x1F"\\]/g,
function(a){switch(a){case '"':case "\\":return"\\"+a;case "\t":return"\\t";case "\n":return"\\n";case "\r":return"\\r";case "\b":return"\\b";case "\f":return"\\f";default:return a=a.charCodeAt(0).toString(16),"\\u"+"0000".substr(a.length)+a}})+'"'}function G(a){function c(a,d){if(!t(a)&&!q(a))return!1;if(-1!==d.indexOf(a))return!0;d.push(a);for(var b in a)if(Object.prototype.hasOwnProperty.call(a,b)){var g=d.length;if(c(a[b],d))return!0;d.splice(g)}return!1}return c(a,[])}function v(a){if(1>a.length)return!1;
for(var c=0,b=a.length;c<b;c++)if(q(a[c]))return!0;return!1}function q(a){return null!==a&&"object"===typeof a&&!(t(a)||g(a)===g.Date)}function k(a){return"string"===typeof a}function g(a){return Object.prototype.toString.call(a)}function l(a,c){return(y(a)||"<root>")+": "+c}function y(a,c){if(0===a.length)return"";for(var b="",d=0,f=a.length;d<f;d++)if(k(a[d])&&a[d])b+=(b?".":"")+w(a[d]);else if("number"===typeof a[d])c||(b+=(b?".":"")+"["+a[d]+"]");else return!1;return b?b:!1}g.Boolean=g(!1);g.String=
g("");g.Number=g(0);g.Array=g([]);g.Date=g(new Date(0));var t=Array.isArray||function(a){return g(a)===g.Array};u.toKey=function(a,c){if(k(a)){var b=w(a);if(!b)throw Error("Key cannot be an empty string.");return b}if(t(a)){b=y(a,c);if(!1===b)throw Error("Key path must consist of non-empty string(s).");return b}throw Error("Invalid Arguments for tomlify.toKey({String | Array})");};u.toValue=D;null!=("undefined"!==typeof module&&null!==module?module.exports:void 0)?module.exports=u:"function"===typeof define&&
define.amd?define([],function(){return u}):this.tomlify=u}).call(this);
{
"name": "tomlify-j0.4",
"version": "1.0.4",
"version": "2.0.0",
"description": "A Object->TOML encoder/converter only for TOML v0.4.0",

@@ -5,0 +5,0 @@ "main": "tomlify.js",

@@ -49,5 +49,5 @@ # TOMLify-j0.4

},
date: {
year: new Date('2015-01-01T00:08:00+08:00'),
months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
more: {
version: [2, 0, 0],
date: new Date('2017-04-14T00:08:00+08:00')
}

@@ -61,3 +61,5 @@ };

* name = "tomlify-j0.4"
* maintainers = ["Jak Wings"]
* maintainers = [
* "Jak Wings"
* ]
*

@@ -74,5 +76,9 @@ * [[about.todos]]

*
* [date]
* year = 2014-12-31T16:08:00.000Z
* months = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
* [more]
* version = [
* 2.0,
* 0.0,
* 0.0
* ]
* date = 2017-04-13T16:08:00.000Z
*/

@@ -82,3 +88,3 @@ var text = tomlify(table, function (key, value) {

var path = tomlify.toKey(context.path);
if (/^date\.months\.\[\d+\]$/.test(path)) {
if (/^more\.version\.\[\d+\]$/.test(path)) {
return value.toFixed(0); // Change the text transformed from the value.

@@ -96,3 +102,5 @@ }

* name = "tomlify-j0.4"
* maintainers = ["Jak Wings"]
* maintainers = [
* "Jak Wings"
* ]
*

@@ -104,5 +112,9 @@ * [[about.todos]]

*
* [date]
* year = 2014-12-31T16:08:00.000Z
* months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
* [more]
* version = [
* 2,
* 0,
* 0
* ]
* date = 2017-04-13T16:08:00.000Z
*/

@@ -161,6 +173,26 @@ var text = tomlify({

However, an inline-table always fits into one line, no matter what it contains.
E.g.
```javascript
tomlify.toValue({one: 1, two: 2}); //=> {one = 1.0, two = 2.0}
tomlify.toValue({one: 1, two: 2});
//=> {one = 1.0, two = 2.0}
tomlify.toValue(["apple", "banana"], null, 2);
//=>
//[
// "apple",
// "banana"
//]
tomlify.toValue([
{people: ["Alice", "Bob"]},
{fruits: ["apple", "banana"]}
], null, 2);
//=>
//[
// {people = ["Alice", "Bob"]},
// {fruits = ["apple", "banana"]}
//]
```

@@ -167,0 +199,0 @@

@@ -166,2 +166,6 @@ (function () {

var lines = [];
var inPair = context.inPair;
if (containTables(obj)) {
context.inPair = true;
}
for (var i = 0, l = obj.length; i < l; i++) {

@@ -175,5 +179,5 @@ context.path.push(i);

}
context.inPair = inPair;
context.table = table;
if (lines.length > 0 && context.space &&
(containArrays(obj) || containTables(obj))) {
if (!context.inPair && lines.length > 0 && context.space) {
return '[\n' + indent(lines.join(',\n'), 1, context.space) + '\n]';

@@ -192,2 +196,4 @@ }

context.table = obj;
var inPair = context.inPair;
context.inPair = true;
var lines = [];

@@ -208,2 +214,3 @@ for (var k in obj) {

}
context.inPair = inPair;
context.table = table;

@@ -498,2 +505,3 @@ return '{' + lines.join(', ') + '}';

table: {'': table},
inPair: false,
inTableArray: false,

@@ -500,0 +508,0 @@ replace: replace,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc