(function(){"use strict";var r=function(r,e){if(0===r.length)return"";for(var n="",i=0,u=r.length;i")+": "+n},n=function(r){return Object.prototype.toString.call(r)};n.Boolean=n(!1),n.String=n(""),n.Number=n(0),n.Array=n([]),n.Date=n(new Date(0));var t=function(r){return"string"==typeof r},a=function(r){return"number"==typeof r},i=Array.isArray||function(r){return n(r)===n.Array},u=function(r){return n(r)===n.Date},o=function(r){return null!==r&&"object"==typeof r&&!(i(r)||u(r))},l=function(r){if(r.length<2)return!1;for(var e=n(r[0]),t=1,a=r.length;t0&&r.space?"[\n"+T(u.join(",\n"),1,r.space)+"\n]":"["+u.join(", ")+"]"},y=function(r,n,t){if(!isFinite(t.getTime()))throw new Error(e(r.path,"Invalid Date"));return t.toISOString()},g=function(r,n,a){var i=r.table;r.table=a;var u=r.inPair;r.inPair=!0;var o=[],l=Object.keys(a);r.sort&&l.sort(r.sort);for(var f=0,c=l.length;f0&&(i(y)?f(y):o(y));i(y)&&f(y)?v.push([!0,d,y,g]):o(y)?v.push([!1,d,y,g]):(r.path.push(d),O(r,d,y,a),r.path.pop())}}if(b=null,r.replace)for(var c=0,s=v.length;c0;)t+=t||r,1&e&&(n+=t),e>>>=1;return n},T=function(r,e,n){var t=S(n,e);return r.replace(/^(?!$)/gm,t)},P=function(r){return t(r)?r:a(r)&&r>=0&&isFinite(r)&&Math.floor(r)===r?S(" ",r):""},N=function(r,e){if(null==r)throw new Error("Undefined or null cannot be stringified.");if(c(r))throw new Error("Converting circular structure to TOML.");if(null!=e&&"object"!=typeof e)throw new Error("Options must be an object.");if(null!=e.replace&&"function"!=typeof e.replace)throw new Error("Replacer must be a function.");if(null!=e.sort&&"function"!=typeof e.sort)throw new Error("Compare function for sorting must be a function.")},x=function(e,n){var a=[];return O({path:[],table:{"":e},inPair:!1,inTableArray:!1,replace:n.replace,sort:n.sort,level:0,space:P(n.space),lines:a},"",e,function(e,n,u){var l=null;if(o(u))""!==n&&(a.length>0&&a.push(""),l=e.inTableArray?"[["+r(e.path,!0)+"]]":"["+r(e.path,!0)+"]",a.push(T(l,e.level,e.space)));else{if(!i(u))return t(n)&&(l=A(e,n,u),t(l)&&a.push(T(l,e.level,e.space))),!0;if(!t(n))return!0;f(u)||(l=A(e,n,u),t(l)&&a.push(T(l,e.level,e.space)))}}),a.join("\n")},D={};D.toToml=function(r,e){if(!o(r))throw new Error("An object other than Array or Date is expected.");return e=null!=e?e:{},N(r,e),x(r,e)},D.toKey=function(e,n){if(t(e)){if(!(a=d(e)))throw new Error("Key cannot be an empty string.");return a}if(i(e)){var a=r(e,n);if(!1===a)throw new Error("Key path must consist of non-empty string(s).");return a}throw new Error("Invalid Arguments for tomlify.toKey({String | Array})")},D.toValue=function(r,e){return e=null!=e?e:{},N(r,e),m(r,e)},null!=("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=D:"function"==typeof define&&define.amd?define([],function(){return D}):this.tomlify=D}).call(this);