react-element-to-jsx-string
Advanced tools
Comparing version
@@ -0,1 +1,11 @@ | ||
# [14.1.0](https://github.com/algolia/react-element-to-jsx-string/compare/v14.0.3...v14.1.0) (2019-09-15) | ||
### Bug Fixes | ||
* **deps:** Remove dependency stringify-object ([6dc6d8d](https://github.com/algolia/react-element-to-jsx-string/commit/6dc6d8d)) | ||
* **deps:** Replace dependency stringify-object with pretty-print-object ([940a413](https://github.com/algolia/react-element-to-jsx-string/commit/940a413)) | ||
## [14.0.3](https://github.com/algolia/react-element-to-jsx-string/compare/v14.0.2...v14.0.3) (2019-07-19) | ||
@@ -2,0 +12,0 @@ |
@@ -63,11 +63,4 @@ 'use strict'; | ||
var isRegexp = function (re) { | ||
return Object.prototype.toString.call(re) === '[object RegExp]'; | ||
}; | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var isObj = function (x) { | ||
var type = typeof x; | ||
return x !== null && (type === 'object' || type === 'function'); | ||
}; | ||
function unwrapExports (x) { | ||
@@ -81,142 +74,172 @@ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
var lib = createCommonjsModule(function (module, exports) { | ||
var dist = createCommonjsModule(function (module, exports) { | ||
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (object) => Object | ||
.getOwnPropertySymbols(object) | ||
.filter((keySymbol) => object.propertyIsEnumerable(keySymbol)); | ||
var seen = []; | ||
/** | ||
* Check if a value is an object or a function. Keep in mind that array, function, regexp, etc, are objects in JavaScript. | ||
* | ||
* @param value the value to check | ||
* @return true if the value is an object or a function | ||
*/ | ||
function isObj(value) { | ||
var type = typeof value; | ||
return value !== null && (type === 'object' || type === 'function'); | ||
} | ||
/** | ||
* Check if a value is a regular expression. | ||
* | ||
* @param value the value to check | ||
* @return true if the value is a regular expression | ||
*/ | ||
function isRegexp(value) { | ||
return Object.prototype.toString.call(value) === '[object RegExp]'; | ||
} | ||
/** | ||
* Get an array of all of the enumerable symbols for an object. | ||
* | ||
* @param object the object to get the enumerable symbols for | ||
*/ | ||
function getOwnEnumPropSymbols(object) { | ||
return Object.getOwnPropertySymbols(object).filter(function (keySymbol) { return Object.prototype.propertyIsEnumerable.call(object, keySymbol); }); | ||
} | ||
/** | ||
* pretty print an object | ||
* | ||
* @param input the object to pretty print | ||
* @param options the formatting options, transforms, and filters | ||
* @param pad the padding string | ||
*/ | ||
function prettyPrint(input, options, pad) { | ||
if (pad === void 0) { pad = ''; } | ||
// sensible option defaults | ||
var defaultOptions = { | ||
indent: '\t', | ||
singleQuotes: true | ||
}; | ||
var combinedOptions = __assign(__assign({}, defaultOptions), options); | ||
var tokens; | ||
if (combinedOptions.inlineCharacterLimit === undefined) { | ||
tokens = { | ||
newLine: '\n', | ||
newLineOrSpace: '\n', | ||
pad: pad, | ||
indent: pad + combinedOptions.indent | ||
}; | ||
} | ||
else { | ||
tokens = { | ||
newLine: '@@__PRETTY_PRINT_NEW_LINE__@@', | ||
newLineOrSpace: '@@__PRETTY_PRINT_NEW_LINE_OR_SPACE__@@', | ||
pad: '@@__PRETTY_PRINT_PAD__@@', | ||
indent: '@@__PRETTY_PRINT_INDENT__@@' | ||
}; | ||
} | ||
var expandWhiteSpace = function (string) { | ||
if (combinedOptions.inlineCharacterLimit === undefined) { | ||
return string; | ||
} | ||
var oneLined = string | ||
.replace(new RegExp(tokens.newLine, 'g'), '') | ||
.replace(new RegExp(tokens.newLineOrSpace, 'g'), ' ') | ||
.replace(new RegExp(tokens.pad + '|' + tokens.indent, 'g'), ''); | ||
if (oneLined.length <= combinedOptions.inlineCharacterLimit) { | ||
return oneLined; | ||
} | ||
return string | ||
.replace(new RegExp(tokens.newLine + '|' + tokens.newLineOrSpace, 'g'), '\n') | ||
.replace(new RegExp(tokens.pad, 'g'), pad) | ||
.replace(new RegExp(tokens.indent, 'g'), pad + combinedOptions.indent); | ||
}; | ||
if (seen.indexOf(input) !== -1) { | ||
return '"[Circular]"'; | ||
} | ||
if (input === null || | ||
input === undefined || | ||
typeof input === 'number' || | ||
typeof input === 'boolean' || | ||
typeof input === 'function' || | ||
typeof input === 'symbol' || | ||
isRegexp(input)) { | ||
return String(input); | ||
} | ||
if (input instanceof Date) { | ||
return "new Date('" + input.toISOString() + "')"; | ||
} | ||
if (Array.isArray(input)) { | ||
if (input.length === 0) { | ||
return '[]'; | ||
} | ||
seen.push(input); | ||
var ret = '[' + tokens.newLine + input.map(function (el, i) { | ||
var eol = input.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var value = prettyPrint(el, combinedOptions, pad + combinedOptions.indent); | ||
if (combinedOptions.transform) { | ||
value = combinedOptions.transform(input, i, value); | ||
} | ||
return tokens.indent + value + eol; | ||
}).join('') + tokens.pad + ']'; | ||
seen.pop(); | ||
return expandWhiteSpace(ret); | ||
} | ||
if (isObj(input)) { | ||
var objKeys_1 = __spreadArrays(Object.keys(input), (getOwnEnumPropSymbols(input))); | ||
if (combinedOptions.filter) { | ||
objKeys_1 = objKeys_1.filter(function (el) { return combinedOptions.filter && combinedOptions.filter(input, el); }); | ||
} | ||
if (objKeys_1.length === 0) { | ||
return '{}'; | ||
} | ||
seen.push(input); | ||
var ret = '{' + tokens.newLine + objKeys_1.map(function (el, i) { | ||
var eol = objKeys_1.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var isSymbol = typeof el === 'symbol'; | ||
var isClassic = !isSymbol && /^[a-z$_][a-z$_0-9]*$/i.test(el.toString()); | ||
var key = isSymbol || isClassic ? el : prettyPrint(el, combinedOptions); | ||
var value = prettyPrint(input[el], combinedOptions, pad + combinedOptions.indent); | ||
if (combinedOptions.transform) { | ||
value = combinedOptions.transform(input, el, value); | ||
} | ||
return tokens.indent + String(key) + ': ' + value + eol; | ||
}).join('') + tokens.pad + '}'; | ||
seen.pop(); | ||
return expandWhiteSpace(ret); | ||
} | ||
input = String(input).replace(/[\r\n]/g, function (x) { return x === '\n' ? '\\n' : '\\r'; }); | ||
if (!combinedOptions.singleQuotes) { | ||
input = input.replace(/"/g, '\\"'); | ||
return "\"" + input + "\""; | ||
} | ||
input = input.replace(/\\?'/g, '\\\''); | ||
return "'" + input + "'"; | ||
} | ||
exports.prettyPrint = prettyPrint; | ||
}); | ||
unwrapExports(lib); | ||
unwrapExports(dist); | ||
var dist_1 = dist.prettyPrint; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var getOwnEnumPropSymbols = lib.default; | ||
var stringifyObject = function (val, opts, pad) { | ||
var seen = []; | ||
return function stringify(val, opts, pad) { | ||
opts = opts || {}; | ||
opts.indent = opts.indent || '\t'; | ||
pad = pad || ''; | ||
var tokens = void 0; | ||
if (opts.inlineCharacterLimit === undefined) { | ||
tokens = { | ||
newLine: '\n', | ||
newLineOrSpace: '\n', | ||
pad: pad, | ||
indent: pad + opts.indent | ||
}; | ||
} else { | ||
tokens = { | ||
newLine: '@@__STRINGIFY_OBJECT_NEW_LINE__@@', | ||
newLineOrSpace: '@@__STRINGIFY_OBJECT_NEW_LINE_OR_SPACE__@@', | ||
pad: '@@__STRINGIFY_OBJECT_PAD__@@', | ||
indent: '@@__STRINGIFY_OBJECT_INDENT__@@' | ||
}; | ||
} | ||
var expandWhiteSpace = function expandWhiteSpace(string) { | ||
if (opts.inlineCharacterLimit === undefined) { | ||
return string; | ||
} | ||
var oneLined = string.replace(new RegExp(tokens.newLine, 'g'), '').replace(new RegExp(tokens.newLineOrSpace, 'g'), ' ').replace(new RegExp(tokens.pad + '|' + tokens.indent, 'g'), ''); | ||
if (oneLined.length <= opts.inlineCharacterLimit) { | ||
return oneLined; | ||
} | ||
return string.replace(new RegExp(tokens.newLine + '|' + tokens.newLineOrSpace, 'g'), '\n').replace(new RegExp(tokens.pad, 'g'), pad).replace(new RegExp(tokens.indent, 'g'), pad + opts.indent); | ||
}; | ||
if (seen.indexOf(val) !== -1) { | ||
return '"[Circular]"'; | ||
} | ||
if (val === null || val === undefined || typeof val === 'number' || typeof val === 'boolean' || typeof val === 'function' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'symbol' || isRegexp(val)) { | ||
return String(val); | ||
} | ||
if (val instanceof Date) { | ||
return 'new Date(\'' + val.toISOString() + '\')'; | ||
} | ||
if (Array.isArray(val)) { | ||
if (val.length === 0) { | ||
return '[]'; | ||
} | ||
seen.push(val); | ||
var ret = '[' + tokens.newLine + val.map(function (el, i) { | ||
var eol = val.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var value = stringify(el, opts, pad + opts.indent); | ||
if (opts.transform) { | ||
value = opts.transform(val, i, value); | ||
} | ||
return tokens.indent + value + eol; | ||
}).join('') + tokens.pad + ']'; | ||
seen.pop(); | ||
return expandWhiteSpace(ret); | ||
} | ||
if (isObj(val)) { | ||
var objKeys = Object.keys(val).concat(getOwnEnumPropSymbols(val)); | ||
if (opts.filter) { | ||
objKeys = objKeys.filter(function (el) { | ||
return opts.filter(val, el); | ||
}); | ||
} | ||
if (objKeys.length === 0) { | ||
return '{}'; | ||
} | ||
seen.push(val); | ||
var _ret = '{' + tokens.newLine + objKeys.map(function (el, i) { | ||
var eol = objKeys.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var isSymbol = (typeof el === 'undefined' ? 'undefined' : _typeof(el)) === 'symbol'; | ||
var isClassic = !isSymbol && /^[a-z$_][a-z$_0-9]*$/i.test(el); | ||
var key = isSymbol || isClassic ? el : stringify(el, opts); | ||
var value = stringify(val[el], opts, pad + opts.indent); | ||
if (opts.transform) { | ||
value = opts.transform(val, el, value); | ||
} | ||
return tokens.indent + String(key) + ': ' + value + eol; | ||
}).join('') + tokens.pad + '}'; | ||
seen.pop(); | ||
return expandWhiteSpace(_ret); | ||
} | ||
val = String(val).replace(/[\r\n]/g, function (x) { | ||
return x === '\n' ? '\\n' : '\\r'; | ||
}); | ||
if (opts.singleQuotes === false) { | ||
val = val.replace(/"/g, '\\"'); | ||
return '"' + val + '"'; | ||
} | ||
val = val.replace(/\\?'/g, '\\\''); | ||
return '\'' + val + '\''; | ||
}(val, opts, pad); | ||
}; | ||
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function sortObject(value) { | ||
// return non-object value as is | ||
if (value === null || (typeof value === 'undefined' ? 'undefined' : _typeof$1(value)) !== 'object') { | ||
if (value === null || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object') { | ||
return value; | ||
@@ -285,3 +308,3 @@ } | ||
var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -327,3 +350,3 @@ | ||
} else if (!React__default.isValidElement(element)) { | ||
throw new Error('react-element-to-jsx-string: Expected a React.Element, got `' + (typeof element === 'undefined' ? 'undefined' : _typeof$2(element)) + '`'); | ||
throw new Error('react-element-to-jsx-string: Expected a React.Element, got `' + (typeof element === 'undefined' ? 'undefined' : _typeof$1(element)) + '`'); | ||
} | ||
@@ -385,3 +408,3 @@ | ||
var stringifiedValue = stringifyObject(normalizedValue, { | ||
var stringifiedValue = dist_1(normalizedValue, { | ||
transform: function transform(currentObj, prop, originalResult) { | ||
@@ -410,3 +433,3 @@ var currentValue = currentObj[prop]; | ||
var _typeof$3 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -429,3 +452,3 @@ var escape = function escape(s) { | ||
// $FlowFixMe: Flow does not support Symbol | ||
if ((typeof propValue === 'undefined' ? 'undefined' : _typeof$3(propValue)) === 'symbol') { | ||
if ((typeof propValue === 'undefined' ? 'undefined' : _typeof$2(propValue)) === 'symbol') { | ||
var symbolDescription = propValue.valueOf().toString().replace(/Symbol\((.*)\)/, '$1'); | ||
@@ -432,0 +455,0 @@ |
@@ -56,11 +56,4 @@ import React, { Fragment, isValidElement } from 'react'; | ||
var isRegexp = function (re) { | ||
return Object.prototype.toString.call(re) === '[object RegExp]'; | ||
}; | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var isObj = function (x) { | ||
var type = typeof x; | ||
return x !== null && (type === 'object' || type === 'function'); | ||
}; | ||
function unwrapExports (x) { | ||
@@ -74,142 +67,172 @@ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
var lib = createCommonjsModule(function (module, exports) { | ||
var dist = createCommonjsModule(function (module, exports) { | ||
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (object) => Object | ||
.getOwnPropertySymbols(object) | ||
.filter((keySymbol) => object.propertyIsEnumerable(keySymbol)); | ||
var seen = []; | ||
/** | ||
* Check if a value is an object or a function. Keep in mind that array, function, regexp, etc, are objects in JavaScript. | ||
* | ||
* @param value the value to check | ||
* @return true if the value is an object or a function | ||
*/ | ||
function isObj(value) { | ||
var type = typeof value; | ||
return value !== null && (type === 'object' || type === 'function'); | ||
} | ||
/** | ||
* Check if a value is a regular expression. | ||
* | ||
* @param value the value to check | ||
* @return true if the value is a regular expression | ||
*/ | ||
function isRegexp(value) { | ||
return Object.prototype.toString.call(value) === '[object RegExp]'; | ||
} | ||
/** | ||
* Get an array of all of the enumerable symbols for an object. | ||
* | ||
* @param object the object to get the enumerable symbols for | ||
*/ | ||
function getOwnEnumPropSymbols(object) { | ||
return Object.getOwnPropertySymbols(object).filter(function (keySymbol) { return Object.prototype.propertyIsEnumerable.call(object, keySymbol); }); | ||
} | ||
/** | ||
* pretty print an object | ||
* | ||
* @param input the object to pretty print | ||
* @param options the formatting options, transforms, and filters | ||
* @param pad the padding string | ||
*/ | ||
function prettyPrint(input, options, pad) { | ||
if (pad === void 0) { pad = ''; } | ||
// sensible option defaults | ||
var defaultOptions = { | ||
indent: '\t', | ||
singleQuotes: true | ||
}; | ||
var combinedOptions = __assign(__assign({}, defaultOptions), options); | ||
var tokens; | ||
if (combinedOptions.inlineCharacterLimit === undefined) { | ||
tokens = { | ||
newLine: '\n', | ||
newLineOrSpace: '\n', | ||
pad: pad, | ||
indent: pad + combinedOptions.indent | ||
}; | ||
} | ||
else { | ||
tokens = { | ||
newLine: '@@__PRETTY_PRINT_NEW_LINE__@@', | ||
newLineOrSpace: '@@__PRETTY_PRINT_NEW_LINE_OR_SPACE__@@', | ||
pad: '@@__PRETTY_PRINT_PAD__@@', | ||
indent: '@@__PRETTY_PRINT_INDENT__@@' | ||
}; | ||
} | ||
var expandWhiteSpace = function (string) { | ||
if (combinedOptions.inlineCharacterLimit === undefined) { | ||
return string; | ||
} | ||
var oneLined = string | ||
.replace(new RegExp(tokens.newLine, 'g'), '') | ||
.replace(new RegExp(tokens.newLineOrSpace, 'g'), ' ') | ||
.replace(new RegExp(tokens.pad + '|' + tokens.indent, 'g'), ''); | ||
if (oneLined.length <= combinedOptions.inlineCharacterLimit) { | ||
return oneLined; | ||
} | ||
return string | ||
.replace(new RegExp(tokens.newLine + '|' + tokens.newLineOrSpace, 'g'), '\n') | ||
.replace(new RegExp(tokens.pad, 'g'), pad) | ||
.replace(new RegExp(tokens.indent, 'g'), pad + combinedOptions.indent); | ||
}; | ||
if (seen.indexOf(input) !== -1) { | ||
return '"[Circular]"'; | ||
} | ||
if (input === null || | ||
input === undefined || | ||
typeof input === 'number' || | ||
typeof input === 'boolean' || | ||
typeof input === 'function' || | ||
typeof input === 'symbol' || | ||
isRegexp(input)) { | ||
return String(input); | ||
} | ||
if (input instanceof Date) { | ||
return "new Date('" + input.toISOString() + "')"; | ||
} | ||
if (Array.isArray(input)) { | ||
if (input.length === 0) { | ||
return '[]'; | ||
} | ||
seen.push(input); | ||
var ret = '[' + tokens.newLine + input.map(function (el, i) { | ||
var eol = input.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var value = prettyPrint(el, combinedOptions, pad + combinedOptions.indent); | ||
if (combinedOptions.transform) { | ||
value = combinedOptions.transform(input, i, value); | ||
} | ||
return tokens.indent + value + eol; | ||
}).join('') + tokens.pad + ']'; | ||
seen.pop(); | ||
return expandWhiteSpace(ret); | ||
} | ||
if (isObj(input)) { | ||
var objKeys_1 = __spreadArrays(Object.keys(input), (getOwnEnumPropSymbols(input))); | ||
if (combinedOptions.filter) { | ||
objKeys_1 = objKeys_1.filter(function (el) { return combinedOptions.filter && combinedOptions.filter(input, el); }); | ||
} | ||
if (objKeys_1.length === 0) { | ||
return '{}'; | ||
} | ||
seen.push(input); | ||
var ret = '{' + tokens.newLine + objKeys_1.map(function (el, i) { | ||
var eol = objKeys_1.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var isSymbol = typeof el === 'symbol'; | ||
var isClassic = !isSymbol && /^[a-z$_][a-z$_0-9]*$/i.test(el.toString()); | ||
var key = isSymbol || isClassic ? el : prettyPrint(el, combinedOptions); | ||
var value = prettyPrint(input[el], combinedOptions, pad + combinedOptions.indent); | ||
if (combinedOptions.transform) { | ||
value = combinedOptions.transform(input, el, value); | ||
} | ||
return tokens.indent + String(key) + ': ' + value + eol; | ||
}).join('') + tokens.pad + '}'; | ||
seen.pop(); | ||
return expandWhiteSpace(ret); | ||
} | ||
input = String(input).replace(/[\r\n]/g, function (x) { return x === '\n' ? '\\n' : '\\r'; }); | ||
if (!combinedOptions.singleQuotes) { | ||
input = input.replace(/"/g, '\\"'); | ||
return "\"" + input + "\""; | ||
} | ||
input = input.replace(/\\?'/g, '\\\''); | ||
return "'" + input + "'"; | ||
} | ||
exports.prettyPrint = prettyPrint; | ||
}); | ||
unwrapExports(lib); | ||
unwrapExports(dist); | ||
var dist_1 = dist.prettyPrint; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var getOwnEnumPropSymbols = lib.default; | ||
var stringifyObject = function (val, opts, pad) { | ||
var seen = []; | ||
return function stringify(val, opts, pad) { | ||
opts = opts || {}; | ||
opts.indent = opts.indent || '\t'; | ||
pad = pad || ''; | ||
var tokens = void 0; | ||
if (opts.inlineCharacterLimit === undefined) { | ||
tokens = { | ||
newLine: '\n', | ||
newLineOrSpace: '\n', | ||
pad: pad, | ||
indent: pad + opts.indent | ||
}; | ||
} else { | ||
tokens = { | ||
newLine: '@@__STRINGIFY_OBJECT_NEW_LINE__@@', | ||
newLineOrSpace: '@@__STRINGIFY_OBJECT_NEW_LINE_OR_SPACE__@@', | ||
pad: '@@__STRINGIFY_OBJECT_PAD__@@', | ||
indent: '@@__STRINGIFY_OBJECT_INDENT__@@' | ||
}; | ||
} | ||
var expandWhiteSpace = function expandWhiteSpace(string) { | ||
if (opts.inlineCharacterLimit === undefined) { | ||
return string; | ||
} | ||
var oneLined = string.replace(new RegExp(tokens.newLine, 'g'), '').replace(new RegExp(tokens.newLineOrSpace, 'g'), ' ').replace(new RegExp(tokens.pad + '|' + tokens.indent, 'g'), ''); | ||
if (oneLined.length <= opts.inlineCharacterLimit) { | ||
return oneLined; | ||
} | ||
return string.replace(new RegExp(tokens.newLine + '|' + tokens.newLineOrSpace, 'g'), '\n').replace(new RegExp(tokens.pad, 'g'), pad).replace(new RegExp(tokens.indent, 'g'), pad + opts.indent); | ||
}; | ||
if (seen.indexOf(val) !== -1) { | ||
return '"[Circular]"'; | ||
} | ||
if (val === null || val === undefined || typeof val === 'number' || typeof val === 'boolean' || typeof val === 'function' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'symbol' || isRegexp(val)) { | ||
return String(val); | ||
} | ||
if (val instanceof Date) { | ||
return 'new Date(\'' + val.toISOString() + '\')'; | ||
} | ||
if (Array.isArray(val)) { | ||
if (val.length === 0) { | ||
return '[]'; | ||
} | ||
seen.push(val); | ||
var ret = '[' + tokens.newLine + val.map(function (el, i) { | ||
var eol = val.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var value = stringify(el, opts, pad + opts.indent); | ||
if (opts.transform) { | ||
value = opts.transform(val, i, value); | ||
} | ||
return tokens.indent + value + eol; | ||
}).join('') + tokens.pad + ']'; | ||
seen.pop(); | ||
return expandWhiteSpace(ret); | ||
} | ||
if (isObj(val)) { | ||
var objKeys = Object.keys(val).concat(getOwnEnumPropSymbols(val)); | ||
if (opts.filter) { | ||
objKeys = objKeys.filter(function (el) { | ||
return opts.filter(val, el); | ||
}); | ||
} | ||
if (objKeys.length === 0) { | ||
return '{}'; | ||
} | ||
seen.push(val); | ||
var _ret = '{' + tokens.newLine + objKeys.map(function (el, i) { | ||
var eol = objKeys.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace; | ||
var isSymbol = (typeof el === 'undefined' ? 'undefined' : _typeof(el)) === 'symbol'; | ||
var isClassic = !isSymbol && /^[a-z$_][a-z$_0-9]*$/i.test(el); | ||
var key = isSymbol || isClassic ? el : stringify(el, opts); | ||
var value = stringify(val[el], opts, pad + opts.indent); | ||
if (opts.transform) { | ||
value = opts.transform(val, el, value); | ||
} | ||
return tokens.indent + String(key) + ': ' + value + eol; | ||
}).join('') + tokens.pad + '}'; | ||
seen.pop(); | ||
return expandWhiteSpace(_ret); | ||
} | ||
val = String(val).replace(/[\r\n]/g, function (x) { | ||
return x === '\n' ? '\\n' : '\\r'; | ||
}); | ||
if (opts.singleQuotes === false) { | ||
val = val.replace(/"/g, '\\"'); | ||
return '"' + val + '"'; | ||
} | ||
val = val.replace(/\\?'/g, '\\\''); | ||
return '\'' + val + '\''; | ||
}(val, opts, pad); | ||
}; | ||
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function sortObject(value) { | ||
// return non-object value as is | ||
if (value === null || (typeof value === 'undefined' ? 'undefined' : _typeof$1(value)) !== 'object') { | ||
if (value === null || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object') { | ||
return value; | ||
@@ -278,3 +301,3 @@ } | ||
var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -320,3 +343,3 @@ | ||
} else if (!React.isValidElement(element)) { | ||
throw new Error('react-element-to-jsx-string: Expected a React.Element, got `' + (typeof element === 'undefined' ? 'undefined' : _typeof$2(element)) + '`'); | ||
throw new Error('react-element-to-jsx-string: Expected a React.Element, got `' + (typeof element === 'undefined' ? 'undefined' : _typeof$1(element)) + '`'); | ||
} | ||
@@ -378,3 +401,3 @@ | ||
var stringifiedValue = stringifyObject(normalizedValue, { | ||
var stringifiedValue = dist_1(normalizedValue, { | ||
transform: function transform(currentObj, prop, originalResult) { | ||
@@ -403,3 +426,3 @@ var currentValue = currentObj[prop]; | ||
var _typeof$3 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -422,3 +445,3 @@ var escape = function escape(s) { | ||
// $FlowFixMe: Flow does not support Symbol | ||
if ((typeof propValue === 'undefined' ? 'undefined' : _typeof$3(propValue)) === 'symbol') { | ||
if ((typeof propValue === 'undefined' ? 'undefined' : _typeof$2(propValue)) === 'symbol') { | ||
var symbolDescription = propValue.valueOf().toString().replace(/Symbol\((.*)\)/, '$1'); | ||
@@ -425,0 +448,0 @@ |
{ | ||
"name": "react-element-to-jsx-string", | ||
"version": "14.0.3", | ||
"version": "14.1.0", | ||
"description": "Turn a ReactElement into the corresponding JSX string.", | ||
@@ -41,3 +41,3 @@ "main": "dist/cjs/index.js", | ||
"babel-cli": "6.26.0", | ||
"babel-eslint": "10.0.2", | ||
"babel-eslint": "10.0.3", | ||
"babel-jest": "23.6.0", | ||
@@ -49,3 +49,3 @@ "babel-preset-es2015": "6.24.1", | ||
"babel-register": "6.26.0", | ||
"conventional-changelog-cli": "2.0.21", | ||
"conventional-changelog-cli": "2.0.23", | ||
"doctoc": "1.4.0", | ||
@@ -57,10 +57,10 @@ "enzyme": "3.10.0", | ||
"eslint-config-prettier": "3.6.0", | ||
"eslint-plugin-import": "2.18.0", | ||
"eslint-plugin-jest": "22.7.2", | ||
"eslint-plugin-import": "2.18.2", | ||
"eslint-plugin-jest": "22.17.0", | ||
"eslint-plugin-prettier": "3.1.0", | ||
"eslint-plugin-react": "7.14.2", | ||
"eslint-plugin-react": "7.14.3", | ||
"esm": "3.2.25", | ||
"expect": "23.6.0", | ||
"flow-bin": "0.102.0", | ||
"flow-copy-source": "2.0.7", | ||
"flow-bin": "0.107.0", | ||
"flow-copy-source": "2.0.8", | ||
"husky": "2.7.0", | ||
@@ -72,5 +72,5 @@ "jest": "23.6.0", | ||
"prettier": "1.18.2", | ||
"react": "16.8.6", | ||
"react-dom": "16.8.6", | ||
"react-test-renderer": "16.8.6", | ||
"react": "16.9.0", | ||
"react-dom": "16.9.0", | ||
"react-test-renderer": "16.9.0", | ||
"rollup": "0.68.2", | ||
@@ -89,4 +89,4 @@ "rollup-plugin-babel": "3.0.7", | ||
"dependencies": { | ||
"is-plain-object": "3.0.0", | ||
"stringify-object": "3.3.0" | ||
"@base2/pretty-print-object": "^1.0.0", | ||
"is-plain-object": "3.0.0" | ||
}, | ||
@@ -93,0 +93,0 @@ "jest": { |
@@ -29,5 +29,3 @@ import babel from 'rollup-plugin-babel'; | ||
babelrc: false, | ||
// Don't transpile `node_modules` except for `stringify-object`. This enables IE 11 support | ||
// and minification in older versions of Uglify. | ||
exclude: 'node_modules/!(stringify-object)/**', | ||
exclude: 'node_modules/**', | ||
presets: [ | ||
@@ -34,0 +32,0 @@ [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
250790
5.03%50
6.38%1590
10.42%+ Added
- Removed
- Removed
- Removed
- Removed
- Removed