preact-render-to-string 5.2.4 → 5.2.5

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/util.js CHANGED
@@ -1,125 +1,125 @@
1
- // DOM properties that should NOT have "px" added when numeric
2
- export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i;
3
- export const VOID_ELEMENTS = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
4
- export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
5
- export const XLINK = /^xlink:?./;
6
-
7
- const ENCODED_ENTITIES = /["&<]/;
8
-
9
- export function encodeEntities(str) {
10
- // Ensure we're always parsing and returning a string:
11
- str += '';
12
-
13
- // Skip all work for strings with no entities needing encoding:
14
- if (ENCODED_ENTITIES.test(str) === false) return str;
15
-
16
- let last = 0,
17
- i = 0,
18
- out = '',
19
- ch = '';
20
-
21
- // Seek forward in str until the next entity char:
22
- for (; i < str.length; i++) {
23
- switch (str.charCodeAt(i)) {
24
- case 34:
25
- ch = '&quot;';
26
- break;
27
- case 38:
28
- ch = '&amp;';
29
- break;
30
- case 60:
31
- ch = '&lt;';
32
- break;
33
- default:
34
- continue;
35
- }
36
- // Append skipped/buffered characters and the encoded entity:
37
- if (i !== last) out += str.slice(last, i);
38
- out += ch;
39
- // Start the next seek/buffer after the entity's offset:
40
- last = i + 1;
41
- }
42
- if (i !== last) out += str.slice(last, i);
43
- return out;
44
- }
45
-
46
- export let indent = (s, char) =>
47
- String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
48
-
49
- export let isLargeString = (s, length, ignoreLines) =>
50
- String(s).length > (length || 40) ||
51
- (!ignoreLines && String(s).indexOf('\n') !== -1) ||
52
- String(s).indexOf('<') !== -1;
53
-
54
- const JS_TO_CSS = {};
55
-
56
- const CSS_REGEX = /([A-Z])/g;
57
- // Convert an Object style to a CSSText string
58
- export function styleObjToCss(s) {
59
- let str = '';
60
- for (let prop in s) {
61
- let val = s[prop];
62
- if (val != null && val !== '') {
63
- if (str) str += ' ';
64
- // str += jsToCss(prop);
65
- str +=
66
- prop[0] == '-'
67
- ? prop
68
- : JS_TO_CSS[prop] ||
69
- (JS_TO_CSS[prop] = prop.replace(CSS_REGEX, '-$1').toLowerCase());
70
-
71
- if (typeof val === 'number' && IS_NON_DIMENSIONAL.test(prop) === false) {
72
- str = str + ': ' + val + 'px;';
73
- } else {
74
- str = str + ': ' + val + ';';
75
- }
76
- }
77
- }
78
- return str || undefined;
79
- }
80
-
81
- /**
82
- * Get flattened children from the children prop
83
- * @param {Array} accumulator
84
- * @param {any} children A `props.children` opaque object.
85
- * @returns {Array} accumulator
86
- * @private
87
- */
88
- export function getChildren(accumulator, children) {
89
- if (Array.isArray(children)) {
90
- children.reduce(getChildren, accumulator);
91
- } else if (children != null && children !== false) {
92
- accumulator.push(children);
93
- }
94
- return accumulator;
95
- }
96
-
97
- function markAsDirty() {
98
- this.__d = true;
99
- }
100
-
101
- export function createComponent(vnode, context) {
102
- return {
103
- __v: vnode,
104
- context,
105
- props: vnode.props,
106
- // silently drop state updates
107
- setState: markAsDirty,
108
- forceUpdate: markAsDirty,
109
- __d: true,
110
- // hooks
111
- __h: []
112
- };
113
- }
114
-
115
- // Necessary for createContext api. Setting this property will pass
116
- // the context value as `this.context` just for this component.
117
- export function getContext(nodeName, context) {
118
- let cxType = nodeName.contextType;
119
- let provider = cxType && context[cxType.__c];
120
- return cxType != null
121
- ? provider
122
- ? provider.props.value
123
- : cxType.__
124
- : context;
125
- }
1
+ // DOM properties that should NOT have "px" added when numeric
2
+ export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i;
3
+ export const VOID_ELEMENTS = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
4
+ export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
5
+ export const XLINK = /^xlink:?./;
6
+
7
+ const ENCODED_ENTITIES = /["&<]/;
8
+
9
+ export function encodeEntities(str) {
10
+ // Ensure we're always parsing and returning a string:
11
+ str += '';
12
+
13
+ // Skip all work for strings with no entities needing encoding:
14
+ if (ENCODED_ENTITIES.test(str) === false) return str;
15
+
16
+ let last = 0,
17
+ i = 0,
18
+ out = '',
19
+ ch = '';
20
+
21
+ // Seek forward in str until the next entity char:
22
+ for (; i < str.length; i++) {
23
+ switch (str.charCodeAt(i)) {
24
+ case 34:
25
+ ch = '&quot;';
26
+ break;
27
+ case 38:
28
+ ch = '&amp;';
29
+ break;
30
+ case 60:
31
+ ch = '&lt;';
32
+ break;
33
+ default:
34
+ continue;
35
+ }
36
+ // Append skipped/buffered characters and the encoded entity:
37
+ if (i !== last) out += str.slice(last, i);
38
+ out += ch;
39
+ // Start the next seek/buffer after the entity's offset:
40
+ last = i + 1;
41
+ }
42
+ if (i !== last) out += str.slice(last, i);
43
+ return out;
44
+ }
45
+
46
+ export let indent = (s, char) =>
47
+ String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
48
+
49
+ export let isLargeString = (s, length, ignoreLines) =>
50
+ String(s).length > (length || 40) ||
51
+ (!ignoreLines && String(s).indexOf('\n') !== -1) ||
52
+ String(s).indexOf('<') !== -1;
53
+
54
+ const JS_TO_CSS = {};
55
+
56
+ const CSS_REGEX = /([A-Z])/g;
57
+ // Convert an Object style to a CSSText string
58
+ export function styleObjToCss(s) {
59
+ let str = '';
60
+ for (let prop in s) {
61
+ let val = s[prop];
62
+ if (val != null && val !== '') {
63
+ if (str) str += ' ';
64
+ // str += jsToCss(prop);
65
+ str +=
66
+ prop[0] == '-'
67
+ ? prop
68
+ : JS_TO_CSS[prop] ||
69
+ (JS_TO_CSS[prop] = prop.replace(CSS_REGEX, '-$1').toLowerCase());
70
+
71
+ if (typeof val === 'number' && IS_NON_DIMENSIONAL.test(prop) === false) {
72
+ str = str + ': ' + val + 'px;';
73
+ } else {
74
+ str = str + ': ' + val + ';';
75
+ }
76
+ }
77
+ }
78
+ return str || undefined;
79
+ }
80
+
81
+ /**
82
+ * Get flattened children from the children prop
83
+ * @param {Array} accumulator
84
+ * @param {any} children A `props.children` opaque object.
85
+ * @returns {Array} accumulator
86
+ * @private
87
+ */
88
+ export function getChildren(accumulator, children) {
89
+ if (Array.isArray(children)) {
90
+ children.reduce(getChildren, accumulator);
91
+ } else if (children != null && children !== false) {
92
+ accumulator.push(children);
93
+ }
94
+ return accumulator;
95
+ }
96
+
97
+ function markAsDirty() {
98
+ this.__d = true;
99
+ }
100
+
101
+ export function createComponent(vnode, context) {
102
+ return {
103
+ __v: vnode,
104
+ context,
105
+ props: vnode.props,
106
+ // silently drop state updates
107
+ setState: markAsDirty,
108
+ forceUpdate: markAsDirty,
109
+ __d: true,
110
+ // hooks
111
+ __h: []
112
+ };
113
+ }
114
+
115
+ // Necessary for createContext api. Setting this property will pass
116
+ // the context value as `this.context` just for this component.
117
+ export function getContext(nodeName, context) {
118
+ let cxType = nodeName.contextType;
119
+ let provider = cxType && context[cxType.__c];
120
+ return cxType != null
121
+ ? provider
122
+ ? provider.props.value
123
+ : cxType.__
124
+ : context;
125
+ }
package/typings.json CHANGED
@@ -1,5 +1,5 @@
1
- {
2
- "name": "preact-render-to-string",
3
- "main": "src/index.d.ts",
4
- "version": false
5
- }
1
+ {
2
+ "name": "preact-render-to-string",
3
+ "main": "src/index.d.ts",
4
+ "version": false
5
+ }