preact-render-to-string 5.2.3 → 5.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/jsx.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { VNode } from 'preact';
2
-
3
- interface Options {
4
- jsx?: boolean;
5
- xml?: boolean;
6
- functions?: boolean;
7
- functionNames?: boolean;
8
- skipFalseAttributes?: boolean;
9
- pretty?: boolean | string;
10
- }
11
-
12
- export function render(vnode: VNode, context?: any, options?: Options): string;
13
- export default render;
1
+ import { VNode } from 'preact';
2
+
3
+ interface Options {
4
+ jsx?: boolean;
5
+ xml?: boolean;
6
+ functions?: boolean;
7
+ functionNames?: boolean;
8
+ skipFalseAttributes?: boolean;
9
+ pretty?: boolean | string;
10
+ }
11
+
12
+ export function render(vnode: VNode, context?: any, options?: Options): string;
13
+ export default render;
package/src/jsx.js CHANGED
@@ -1,76 +1,76 @@
1
- import './polyfills';
2
- import renderToString from './index';
3
- import { indent, encodeEntities } from './util';
4
- import prettyFormat from 'pretty-format';
5
-
6
- // we have to patch in Array support, Possible issue in npm.im/pretty-format
7
- let preactPlugin = {
8
- test(object) {
9
- return (
10
- object &&
11
- typeof object === 'object' &&
12
- 'type' in object &&
13
- 'props' in object &&
14
- 'key' in object
15
- );
16
- },
17
- print(val, print, indent) {
18
- return renderToString(val, preactPlugin.context, preactPlugin.opts, true);
19
- }
20
- };
21
-
22
- let prettyFormatOpts = {
23
- plugins: [preactPlugin]
24
- };
25
-
26
- function attributeHook(name, value, context, opts, isComponent) {
27
- let type = typeof value;
28
-
29
- // Use render-to-string's built-in handling for these properties
30
- if (name === 'dangerouslySetInnerHTML') return false;
31
-
32
- // always skip null & undefined values, skip false DOM attributes, skip functions if told to
33
- if (value == null || (type === 'function' && !opts.functions)) return '';
34
-
35
- if (
36
- opts.skipFalseAttributes &&
37
- !isComponent &&
38
- (value === false ||
39
- ((name === 'class' || name === 'style') && value === ''))
40
- )
41
- return '';
42
-
43
- let indentChar = typeof opts.pretty === 'string' ? opts.pretty : '\t';
44
- if (type !== 'string') {
45
- if (type === 'function' && !opts.functionNames) {
46
- value = 'Function';
47
- } else {
48
- preactPlugin.context = context;
49
- preactPlugin.opts = opts;
50
- value = prettyFormat(value, prettyFormatOpts);
51
- if (~value.indexOf('\n')) {
52
- value = `${indent('\n' + value, indentChar)}\n`;
53
- }
54
- }
55
- return indent(`\n${name}={${value}}`, indentChar);
56
- }
57
- return `\n${indentChar}${name}="${encodeEntities(value)}"`;
58
- }
59
-
60
- let defaultOpts = {
61
- attributeHook,
62
- jsx: true,
63
- xml: false,
64
- functions: true,
65
- functionNames: true,
66
- skipFalseAttributes: true,
67
- pretty: ' '
68
- };
69
-
70
- function renderToJsxString(vnode, context, opts, inner) {
71
- opts = Object.assign({}, defaultOpts, opts || {});
72
- return renderToString(vnode, context, opts, inner);
73
- }
74
-
75
- export default renderToJsxString;
76
- export { renderToJsxString as render };
1
+ import './polyfills';
2
+ import renderToString from './index';
3
+ import { indent, encodeEntities } from './util';
4
+ import prettyFormat from 'pretty-format';
5
+
6
+ // we have to patch in Array support, Possible issue in npm.im/pretty-format
7
+ let preactPlugin = {
8
+ test(object) {
9
+ return (
10
+ object &&
11
+ typeof object === 'object' &&
12
+ 'type' in object &&
13
+ 'props' in object &&
14
+ 'key' in object
15
+ );
16
+ },
17
+ print(val, print, indent) {
18
+ return renderToString(val, preactPlugin.context, preactPlugin.opts, true);
19
+ }
20
+ };
21
+
22
+ let prettyFormatOpts = {
23
+ plugins: [preactPlugin]
24
+ };
25
+
26
+ function attributeHook(name, value, context, opts, isComponent) {
27
+ let type = typeof value;
28
+
29
+ // Use render-to-string's built-in handling for these properties
30
+ if (name === 'dangerouslySetInnerHTML') return false;
31
+
32
+ // always skip null & undefined values, skip false DOM attributes, skip functions if told to
33
+ if (value == null || (type === 'function' && !opts.functions)) return '';
34
+
35
+ if (
36
+ opts.skipFalseAttributes &&
37
+ !isComponent &&
38
+ (value === false ||
39
+ ((name === 'class' || name === 'style') && value === ''))
40
+ )
41
+ return '';
42
+
43
+ let indentChar = typeof opts.pretty === 'string' ? opts.pretty : '\t';
44
+ if (type !== 'string') {
45
+ if (type === 'function' && !opts.functionNames) {
46
+ value = 'Function';
47
+ } else {
48
+ preactPlugin.context = context;
49
+ preactPlugin.opts = opts;
50
+ value = prettyFormat(value, prettyFormatOpts);
51
+ if (~value.indexOf('\n')) {
52
+ value = `${indent('\n' + value, indentChar)}\n`;
53
+ }
54
+ }
55
+ return indent(`\n${name}={${value}}`, indentChar);
56
+ }
57
+ return `\n${indentChar}${name}="${encodeEntities(value)}"`;
58
+ }
59
+
60
+ let defaultOpts = {
61
+ attributeHook,
62
+ jsx: true,
63
+ xml: false,
64
+ functions: true,
65
+ functionNames: true,
66
+ skipFalseAttributes: true,
67
+ pretty: ' '
68
+ };
69
+
70
+ function renderToJsxString(vnode, context, opts, inner) {
71
+ opts = Object.assign({}, defaultOpts, opts || {});
72
+ return renderToString(vnode, context, opts, inner);
73
+ }
74
+
75
+ export default renderToJsxString;
76
+ export { renderToJsxString as render };
package/src/polyfills.js CHANGED
@@ -1,8 +1,8 @@
1
- if (typeof Symbol !== 'function') {
2
- let c = 0;
3
- // eslint-disable-next-line
4
- Symbol = function (s) {
5
- return `@@${s}${++c}`;
6
- };
7
- Symbol.for = (s) => `@@${s}`;
8
- }
1
+ if (typeof Symbol !== 'function') {
2
+ let c = 0;
3
+ // eslint-disable-next-line
4
+ Symbol = function (s) {
5
+ return `@@${s}${++c}`;
6
+ };
7
+ Symbol.for = (s) => `@@${s}`;
8
+ }