isomorfeus-preact 10.9.0 → 22.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +14 -3
  3. data/README.md +23 -39
  4. data/lib/browser/delegate_native.rb +94 -72
  5. data/lib/browser/document.rb +38 -0
  6. data/lib/browser/element.rb +160 -176
  7. data/lib/browser/event.rb +99 -94
  8. data/lib/browser/history.rb +40 -20
  9. data/lib/browser/location.rb +59 -0
  10. data/lib/browser/window.rb +58 -0
  11. data/lib/data_uri/open_uri.rb +18 -0
  12. data/lib/data_uri/uri.rb +61 -0
  13. data/lib/data_uri.rb +4 -0
  14. data/lib/isomorfeus/preact/config.rb +42 -54
  15. data/lib/isomorfeus/preact/imports.rb +5 -20
  16. data/lib/isomorfeus/preact/ssr.rb +34 -0
  17. data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
  18. data/lib/isomorfeus/preact/version.rb +5 -0
  19. data/lib/isomorfeus/preact/view_helper.rb +72 -0
  20. data/lib/isomorfeus/props/validator.rb +19 -11
  21. data/lib/isomorfeus/top_level.rb +55 -33
  22. data/lib/isomorfeus-preact.rb +78 -103
  23. data/lib/link.rb +52 -0
  24. data/lib/lucid_app.rb +117 -0
  25. data/lib/lucid_component.rb +154 -0
  26. data/lib/nano_css.rb +282 -465
  27. data/lib/preact/component.rb +222 -0
  28. data/lib/preact/component_resolution.rb +49 -83
  29. data/lib/preact/context.rb +68 -0
  30. data/lib/preact/elements.rb +2 -9
  31. data/lib/preact/module_component_resolution.rb +50 -0
  32. data/lib/preact/prop_declaration_mixin.rb +73 -0
  33. data/lib/preact.rb +1548 -257
  34. data/lib/redirect.rb +34 -0
  35. data/lib/route.rb +15 -0
  36. data/lib/router.rb +145 -0
  37. data/lib/switch.rb +70 -0
  38. metadata +42 -309
  39. data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
  40. data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
  41. data/lib/isomorfeus/preact/ssr/history.rb +0 -23
  42. data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
  43. data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
  44. data/lib/isomorfeus/preact_view_helper.rb +0 -129
  45. data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
  46. data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
  47. data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
  48. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
  49. data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
  50. data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
  51. data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
  52. data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
  53. data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
  54. data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
  55. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
  56. data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
  57. data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
  58. data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
  59. data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
  60. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
  61. data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -164
  62. data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
  63. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
  64. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
  65. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
  66. data/lib/lucid_app/context.rb +0 -24
  67. data/lib/lucid_prop_declaration/mixin.rb +0 -126
  68. data/lib/preact/component/api.rb +0 -137
  69. data/lib/preact/component/base.rb +0 -7
  70. data/lib/preact/component/callbacks.rb +0 -111
  71. data/lib/preact/component/initializer.rb +0 -7
  72. data/lib/preact/component/mixin.rb +0 -11
  73. data/lib/preact/component/native_component_constructor.rb +0 -77
  74. data/lib/preact/context_wrapper.rb +0 -48
  75. data/lib/preact/native_constant_wrapper.rb +0 -29
  76. data/lib/preact/option_hooks.rb +0 -98
  77. data/lib/preact/params.rb +0 -16
  78. data/lib/preact/props.rb +0 -69
  79. data/lib/preact/ref.rb +0 -17
  80. data/lib/preact/state.rb +0 -87
  81. data/lib/preact/version.rb +0 -3
  82. data/node_modules/.package-lock.json +0 -38
  83. data/node_modules/preact/LICENSE +0 -21
  84. data/node_modules/preact/README.md +0 -188
  85. data/node_modules/preact/compat/LICENSE +0 -21
  86. data/node_modules/preact/compat/client.js +0 -19
  87. data/node_modules/preact/compat/client.mjs +0 -17
  88. data/node_modules/preact/compat/dist/compat.js +0 -2
  89. data/node_modules/preact/compat/dist/compat.js.map +0 -1
  90. data/node_modules/preact/compat/dist/compat.mjs +0 -2
  91. data/node_modules/preact/compat/dist/compat.module.js +0 -2
  92. data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
  93. data/node_modules/preact/compat/dist/compat.umd.js +0 -2
  94. data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
  95. data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
  96. data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
  97. data/node_modules/preact/compat/jsx-runtime.js +0 -3
  98. data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
  99. data/node_modules/preact/compat/package.json +0 -49
  100. data/node_modules/preact/compat/scheduler.js +0 -15
  101. data/node_modules/preact/compat/scheduler.mjs +0 -23
  102. data/node_modules/preact/compat/server.browser.js +0 -4
  103. data/node_modules/preact/compat/server.js +0 -15
  104. data/node_modules/preact/compat/server.mjs +0 -4
  105. data/node_modules/preact/compat/src/Children.js +0 -21
  106. data/node_modules/preact/compat/src/PureComponent.js +0 -15
  107. data/node_modules/preact/compat/src/forwardRef.js +0 -44
  108. data/node_modules/preact/compat/src/index.d.ts +0 -164
  109. data/node_modules/preact/compat/src/index.js +0 -223
  110. data/node_modules/preact/compat/src/internal.d.ts +0 -47
  111. data/node_modules/preact/compat/src/memo.js +0 -34
  112. data/node_modules/preact/compat/src/portals.js +0 -82
  113. data/node_modules/preact/compat/src/render.js +0 -238
  114. data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
  115. data/node_modules/preact/compat/src/suspense-list.js +0 -126
  116. data/node_modules/preact/compat/src/suspense.d.ts +0 -15
  117. data/node_modules/preact/compat/src/suspense.js +0 -270
  118. data/node_modules/preact/compat/src/util.js +0 -28
  119. data/node_modules/preact/compat/test-utils.js +0 -1
  120. data/node_modules/preact/debug/LICENSE +0 -21
  121. data/node_modules/preact/debug/dist/debug.js +0 -2
  122. data/node_modules/preact/debug/dist/debug.js.map +0 -1
  123. data/node_modules/preact/debug/dist/debug.mjs +0 -2
  124. data/node_modules/preact/debug/dist/debug.module.js +0 -2
  125. data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
  126. data/node_modules/preact/debug/dist/debug.umd.js +0 -2
  127. data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
  128. data/node_modules/preact/debug/package.json +0 -26
  129. data/node_modules/preact/debug/src/check-props.js +0 -54
  130. data/node_modules/preact/debug/src/component-stack.js +0 -146
  131. data/node_modules/preact/debug/src/constants.js +0 -3
  132. data/node_modules/preact/debug/src/debug.js +0 -437
  133. data/node_modules/preact/debug/src/index.js +0 -6
  134. data/node_modules/preact/debug/src/internal.d.ts +0 -82
  135. data/node_modules/preact/debug/src/util.js +0 -11
  136. data/node_modules/preact/devtools/LICENSE +0 -21
  137. data/node_modules/preact/devtools/dist/devtools.js +0 -2
  138. data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
  139. data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
  140. data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
  141. data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
  142. data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
  143. data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
  144. data/node_modules/preact/devtools/package.json +0 -25
  145. data/node_modules/preact/devtools/src/devtools.js +0 -10
  146. data/node_modules/preact/devtools/src/index.d.ts +0 -8
  147. data/node_modules/preact/devtools/src/index.js +0 -15
  148. data/node_modules/preact/dist/preact.js +0 -2
  149. data/node_modules/preact/dist/preact.js.map +0 -1
  150. data/node_modules/preact/dist/preact.min.js +0 -2
  151. data/node_modules/preact/dist/preact.min.js.map +0 -1
  152. data/node_modules/preact/dist/preact.mjs +0 -2
  153. data/node_modules/preact/dist/preact.module.js +0 -2
  154. data/node_modules/preact/dist/preact.module.js.map +0 -1
  155. data/node_modules/preact/dist/preact.umd.js +0 -2
  156. data/node_modules/preact/dist/preact.umd.js.map +0 -1
  157. data/node_modules/preact/hooks/LICENSE +0 -21
  158. data/node_modules/preact/hooks/dist/hooks.js +0 -2
  159. data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
  160. data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
  161. data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
  162. data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
  163. data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
  164. data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
  165. data/node_modules/preact/hooks/package.json +0 -35
  166. data/node_modules/preact/hooks/src/index.d.ts +0 -139
  167. data/node_modules/preact/hooks/src/index.js +0 -417
  168. data/node_modules/preact/hooks/src/internal.d.ts +0 -78
  169. data/node_modules/preact/jsx-runtime/LICENSE +0 -21
  170. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
  171. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
  172. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
  173. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
  174. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
  175. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
  176. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
  177. data/node_modules/preact/jsx-runtime/package.json +0 -28
  178. data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
  179. data/node_modules/preact/jsx-runtime/src/index.js +0 -77
  180. data/node_modules/preact/package.json +0 -304
  181. data/node_modules/preact/src/cjs.js +0 -3
  182. data/node_modules/preact/src/clone-element.js +0 -34
  183. data/node_modules/preact/src/component.js +0 -225
  184. data/node_modules/preact/src/constants.js +0 -3
  185. data/node_modules/preact/src/create-context.js +0 -68
  186. data/node_modules/preact/src/create-element.js +0 -98
  187. data/node_modules/preact/src/diff/catch-error.js +0 -40
  188. data/node_modules/preact/src/diff/children.js +0 -335
  189. data/node_modules/preact/src/diff/index.js +0 -533
  190. data/node_modules/preact/src/diff/props.js +0 -158
  191. data/node_modules/preact/src/index.d.ts +0 -317
  192. data/node_modules/preact/src/index.js +0 -13
  193. data/node_modules/preact/src/internal.d.ts +0 -155
  194. data/node_modules/preact/src/jsx.d.ts +0 -1014
  195. data/node_modules/preact/src/options.js +0 -16
  196. data/node_modules/preact/src/render.js +0 -75
  197. data/node_modules/preact/src/util.js +0 -27
  198. data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
  199. data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
  200. data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
  201. data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
  202. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
  203. data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
  204. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
  205. data/node_modules/preact/test-utils/package.json +0 -28
  206. data/node_modules/preact/test-utils/src/index.d.ts +0 -3
  207. data/node_modules/preact/test-utils/src/index.js +0 -118
  208. data/node_modules/preact-render-to-string/LICENSE +0 -21
  209. data/node_modules/preact-render-to-string/README.md +0 -102
  210. data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
  211. data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
  212. data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
  213. data/node_modules/preact-render-to-string/dist/index.js +0 -1
  214. data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
  215. data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
  216. data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
  217. data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
  218. data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
  219. data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
  220. data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
  221. data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
  222. data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
  223. data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
  224. data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
  225. data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
  226. data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
  227. data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
  228. data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
  229. data/node_modules/preact-render-to-string/jsx.js +0 -1
  230. data/node_modules/preact-render-to-string/package.json +0 -142
  231. data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
  232. data/node_modules/preact-render-to-string/src/index.js +0 -462
  233. data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
  234. data/node_modules/preact-render-to-string/src/jsx.js +0 -76
  235. data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
  236. data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
  237. data/node_modules/preact-render-to-string/src/util.js +0 -78
  238. data/node_modules/preact-render-to-string/typings.json +0 -5
  239. data/node_modules/pretty-format/.npmignore +0 -3
  240. data/node_modules/pretty-format/LICENSE.md +0 -15
  241. data/node_modules/pretty-format/README.md +0 -94
  242. data/node_modules/pretty-format/index.js +0 -343
  243. data/node_modules/pretty-format/package.json +0 -26
  244. data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
  245. data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
  246. data/node_modules/pretty-format/printString.js +0 -7
  247. data/node_modules/wouter-preact/cjs/index.js +0 -180
  248. data/node_modules/wouter-preact/cjs/matcher.js +0 -72
  249. data/node_modules/wouter-preact/cjs/package.json +0 -1
  250. data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
  251. data/node_modules/wouter-preact/cjs/static-location.js +0 -21
  252. data/node_modules/wouter-preact/cjs/use-location.js +0 -94
  253. data/node_modules/wouter-preact/index.d.ts +0 -110
  254. data/node_modules/wouter-preact/index.js +0 -178
  255. data/node_modules/wouter-preact/matcher.d.ts +0 -30
  256. data/node_modules/wouter-preact/matcher.js +0 -66
  257. data/node_modules/wouter-preact/package.json +0 -33
  258. data/node_modules/wouter-preact/react-deps.js +0 -15
  259. data/node_modules/wouter-preact/static-location.d.ts +0 -16
  260. data/node_modules/wouter-preact/static-location.js +0 -17
  261. data/node_modules/wouter-preact/use-location.d.ts +0 -43
  262. data/node_modules/wouter-preact/use-location.js +0 -86
  263. data/package.json +0 -8
@@ -1,8 +0,0 @@
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,78 +0,0 @@
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
-
4
- const ENCODED_ENTITIES = /[&<>"]/;
5
-
6
- export function encodeEntities(input) {
7
- const s = String(input);
8
- if (!ENCODED_ENTITIES.test(s)) {
9
- return s;
10
- }
11
- return s
12
- .replace(/&/g, '&amp;')
13
- .replace(/</g, '&lt;')
14
- .replace(/>/g, '&gt;')
15
- .replace(/"/g, '&quot;');
16
- }
17
-
18
- export let indent = (s, char) =>
19
- String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
20
-
21
- export let isLargeString = (s, length, ignoreLines) =>
22
- String(s).length > (length || 40) ||
23
- (!ignoreLines && String(s).indexOf('\n') !== -1) ||
24
- String(s).indexOf('<') !== -1;
25
-
26
- const JS_TO_CSS = {};
27
-
28
- // Convert an Object style to a CSSText string
29
- export function styleObjToCss(s) {
30
- let str = '';
31
- for (let prop in s) {
32
- let val = s[prop];
33
- if (val != null && val !== '') {
34
- if (str) str += ' ';
35
- // str += jsToCss(prop);
36
- str +=
37
- prop[0] == '-'
38
- ? prop
39
- : JS_TO_CSS[prop] ||
40
- (JS_TO_CSS[prop] = prop.replace(/([A-Z])/g, '-$1').toLowerCase());
41
- str += ': ';
42
- str += val;
43
- if (typeof val === 'number' && IS_NON_DIMENSIONAL.test(prop) === false) {
44
- str += 'px';
45
- }
46
- str += ';';
47
- }
48
- }
49
- return str || undefined;
50
- }
51
-
52
- /**
53
- * Copy all properties from `props` onto `obj`.
54
- * @param {object} obj Object onto which properties should be copied.
55
- * @param {object} props Object from which to copy properties.
56
- * @returns {object}
57
- * @private
58
- */
59
- export function assign(obj, props) {
60
- for (let i in props) obj[i] = props[i];
61
- return obj;
62
- }
63
-
64
- /**
65
- * Get flattened children from the children prop
66
- * @param {Array} accumulator
67
- * @param {any} children A `props.children` opaque object.
68
- * @returns {Array} accumulator
69
- * @private
70
- */
71
- export function getChildren(accumulator, children) {
72
- if (Array.isArray(children)) {
73
- children.reduce(getChildren, accumulator);
74
- } else if (children != null && children !== false) {
75
- accumulator.push(children);
76
- }
77
- return accumulator;
78
- }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "preact-render-to-string",
3
- "main": "src/index.d.ts",
4
- "version": false
5
- }
@@ -1,3 +0,0 @@
1
- __tests__
2
- perf
3
- .travis.yml
@@ -1,15 +0,0 @@
1
- ## ISC License
2
-
3
- Copyright (c) 2016, James Kyle <me@thejameskyle.com>
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any purpose
6
- with or without fee is hereby granted, provided that the above copyright notice
7
- and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11
- FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
13
- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
14
- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
15
- THIS SOFTWARE.
@@ -1,94 +0,0 @@
1
- # pretty-format [![Travis build status](http://img.shields.io/travis/thejameskyle/pretty-format.svg?style=flat)](https://travis-ci.org/thejameskyle/pretty-format)
2
-
3
- > Stringify any JavaScript value.
4
-
5
- - Supports [all built-in JavaScript types](#type-support)
6
- - [Blazingly fast](https://gist.github.com/thejameskyle/2b04ffe4941aafa8f970de077843a8fd) (similar performance to v8's `JSON.stringify` and significantly faster than Node's `util.format`)
7
- - Plugin system for extending with custom types (i.e. [`ReactTestComponent`](#reacttestcomponent-plugin))
8
-
9
-
10
- ## Installation
11
-
12
- ```sh
13
- $ npm install pretty-format
14
- ```
15
-
16
- ## Usage
17
-
18
- ```js
19
- var prettyFormat = require('pretty-format');
20
-
21
- var obj = { property: {} };
22
- obj.circularReference = obj;
23
- obj[Symbol('foo')] = 'foo';
24
- obj.map = new Map();
25
- obj.map.set('prop', 'value');
26
- obj.array = [1, NaN, Infinity];
27
-
28
- console.log(prettyFormat(obj));
29
- ```
30
-
31
- **Result:**
32
-
33
- ```js
34
- Object {
35
- "property": Object {},
36
- "circularReference": [Circular],
37
- "map": Map {
38
- "prop" => "value"
39
- },
40
- "array": Array [
41
- 1,
42
- NaN,
43
- Infinity
44
- ],
45
- Symbol(foo): "foo"
46
- }
47
- ```
48
-
49
- #### Type Support
50
-
51
- `Object`, `Array`, `ArrayBuffer`, `DataView`, `Float32Array`, `Float64Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Uint8Array`, `Uint8ClampedArray`, `Uint16Array`, `Uint32Array`, `arguments`, `Boolean`, `Date`, `Error`, `Function`, `Infinity`, `Map`, `NaN`, `null`, `Number`, `RegExp`, `Set`, `String`, `Symbol`, `undefined`, `WeakMap`, `WeakSet`
52
-
53
- ### Plugins
54
-
55
- Pretty format also supports adding plugins:
56
-
57
- ```js
58
- var fooPlugin = {
59
- test: function(val) {
60
- return val && val.hasOwnProperty('foo');
61
- },
62
- print: function(val, print, indent) {
63
- return 'Foo: ' + print(val.foo);
64
- }
65
- };
66
-
67
- var obj = { foo: { bar: {} } };
68
-
69
- prettyFormat(obj, {
70
- plugins: [fooPlugin]
71
- });
72
- // Foo: Object {
73
- // "bar": Object {}
74
- // }
75
- ```
76
-
77
- #### `ReactTestComponent` plugin
78
-
79
- ```js
80
- var prettyFormat = require('pretty-format');
81
- var reactPlugin = require('pretty-format/plugins/ReactTestComponent');
82
-
83
- var React = require('react');
84
- var renderer = require('react/lib/ReactTestRenderer');
85
-
86
- var jsx = React.createElement('h1', null, 'Hello World');
87
-
88
- prettyFormat(renderer.create(jsx).toJSON(), {
89
- plugins: [reactPlugin]
90
- });
91
- // <h1>
92
- // Hello World
93
- // </h1>
94
- ```
@@ -1,343 +0,0 @@
1
- 'use strict';
2
-
3
- const printString = require('./printString');
4
-
5
- const toString = Object.prototype.toString;
6
- const toISOString = Date.prototype.toISOString;
7
- const errorToString = Error.prototype.toString;
8
- const regExpToString = RegExp.prototype.toString;
9
- const symbolToString = Symbol.prototype.toString;
10
-
11
- const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
12
- const NEWLINE_REGEXP = /\n/ig;
13
-
14
- const getSymbols = Object.getOwnPropertySymbols || (obj => []);
15
-
16
- function isToStringedArrayType(toStringed) {
17
- return (
18
- toStringed === '[object Array]' ||
19
- toStringed === '[object ArrayBuffer]' ||
20
- toStringed === '[object DataView]' ||
21
- toStringed === '[object Float32Array]' ||
22
- toStringed === '[object Float64Array]' ||
23
- toStringed === '[object Int8Array]' ||
24
- toStringed === '[object Int16Array]' ||
25
- toStringed === '[object Int32Array]' ||
26
- toStringed === '[object Uint8Array]' ||
27
- toStringed === '[object Uint8ClampedArray]' ||
28
- toStringed === '[object Uint16Array]' ||
29
- toStringed === '[object Uint32Array]'
30
- );
31
- }
32
-
33
- function printNumber(val) {
34
- if (val != +val) return 'NaN';
35
- const isNegativeZero = val === 0 && (1 / val) < 0;
36
- return isNegativeZero ? '-0' : '' + val;
37
- }
38
-
39
- function printFunction(val) {
40
- if (val.name === '') {
41
- return '[Function anonymous]'
42
- } else {
43
- return '[Function ' + val.name + ']';
44
- }
45
- }
46
-
47
- function printSymbol(val) {
48
- return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
49
- }
50
-
51
- function printError(val) {
52
- return '[' + errorToString.call(val) + ']';
53
- }
54
-
55
- function printBasicValue(val) {
56
- if (val === true || val === false) return '' + val;
57
- if (val === undefined) return 'undefined';
58
- if (val === null) return 'null';
59
-
60
- const typeOf = typeof val;
61
-
62
- if (typeOf === 'number') return printNumber(val);
63
- if (typeOf === 'string') return '"' + printString(val) + '"';
64
- if (typeOf === 'function') return printFunction(val);
65
- if (typeOf === 'symbol') return printSymbol(val);
66
-
67
- const toStringed = toString.call(val);
68
-
69
- if (toStringed === '[object WeakMap]') return 'WeakMap {}';
70
- if (toStringed === '[object WeakSet]') return 'WeakSet {}';
71
- if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return printFunction(val, min);
72
- if (toStringed === '[object Symbol]') return printSymbol(val);
73
- if (toStringed === '[object Date]') return toISOString.call(val);
74
- if (toStringed === '[object Error]') return printError(val);
75
- if (toStringed === '[object RegExp]') return regExpToString.call(val);
76
- if (toStringed === '[object Arguments]' && val.length === 0) return 'Arguments []';
77
- if (isToStringedArrayType(toStringed) && val.length === 0) return val.constructor.name + ' []';
78
-
79
- if (val instanceof Error) return printError(val);
80
-
81
- return false;
82
- }
83
-
84
- function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
85
- let body = '';
86
-
87
- if (list.length) {
88
- body += edgeSpacing;
89
-
90
- const innerIndent = prevIndent + indent;
91
-
92
- for (let i = 0; i < list.length; i++) {
93
- body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
94
-
95
- if (i < list.length - 1) {
96
- body += ',' + spacing;
97
- }
98
- }
99
-
100
- body += edgeSpacing + prevIndent;
101
- }
102
-
103
- return '[' + body + ']';
104
- }
105
-
106
- function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
107
- return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
108
- }
109
-
110
- function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
111
- return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
112
- }
113
-
114
- function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
115
- let result = 'Map {';
116
- const iterator = val.entries();
117
- let current = iterator.next();
118
-
119
- if (!current.done) {
120
- result += edgeSpacing;
121
-
122
- const innerIndent = prevIndent + indent;
123
-
124
- while (!current.done) {
125
- const key = print(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
126
- const value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
127
-
128
- result += innerIndent + key + ' => ' + value;
129
-
130
- current = iterator.next();
131
-
132
- if (!current.done) {
133
- result += ',' + spacing;
134
- }
135
- }
136
-
137
- result += edgeSpacing + prevIndent;
138
- }
139
-
140
- return result + '}';
141
- }
142
-
143
- function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
144
- const constructor = min ? '' : (val.constructor ? val.constructor.name + ' ' : 'Object ');
145
- let result = constructor + '{';
146
- let keys = Object.keys(val).sort();
147
- const symbols = getSymbols(val);
148
-
149
- if (symbols.length) {
150
- keys = keys
151
- .filter(key => !(typeof key === 'symbol' || toString.call(key) === '[object Symbol]'))
152
- .concat(symbols);
153
- }
154
-
155
- if (keys.length) {
156
- result += edgeSpacing;
157
-
158
- const innerIndent = prevIndent + indent;
159
-
160
- for (let i = 0; i < keys.length; i++) {
161
- const key = keys[i];
162
- const name = print(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
163
- const value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
164
-
165
- result += innerIndent + name + ': ' + value;
166
-
167
- if (i < keys.length - 1) {
168
- result += ',' + spacing;
169
- }
170
- }
171
-
172
- result += edgeSpacing + prevIndent;
173
- }
174
-
175
- return result + '}';
176
- }
177
-
178
- function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
179
- let result = 'Set {';
180
- const iterator = val.entries();
181
- let current = iterator.next();
182
-
183
- if (!current.done) {
184
- result += edgeSpacing;
185
-
186
- const innerIndent = prevIndent + indent;
187
-
188
- while (!current.done) {
189
- result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
190
-
191
- current = iterator.next();
192
-
193
- if (!current.done) {
194
- result += ',' + spacing;
195
- }
196
- }
197
-
198
- result += edgeSpacing + prevIndent;
199
- }
200
-
201
- return result + '}';
202
- }
203
-
204
- function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
205
- refs = refs.slice();
206
- if (refs.indexOf(val) > -1) {
207
- return '[Circular]';
208
- } else {
209
- refs.push(val);
210
- }
211
-
212
- currentDepth++;
213
-
214
- const hitMaxDepth = currentDepth > maxDepth;
215
-
216
- if (!hitMaxDepth && val.toJSON && typeof val.toJSON === 'function') {
217
- return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
218
- }
219
-
220
- const toStringed = toString.call(val);
221
- if (toStringed === '[object Arguments]') {
222
- return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
223
- } else if (isToStringedArrayType(toStringed)) {
224
- return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
225
- } else if (toStringed === '[object Map]') {
226
- return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
227
- } else if (toStringed === '[object Set]') {
228
- return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
229
- } else if (typeof val === 'object') {
230
- return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
231
- }
232
- }
233
-
234
- function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
235
- let match = false;
236
- let plugin;
237
-
238
- for (let p = 0; p < plugins.length; p++) {
239
- plugin = plugins[p];
240
-
241
- if (plugin.test(val)) {
242
- match = true;
243
- break;
244
- }
245
- }
246
-
247
- if (!match) {
248
- return false;
249
- }
250
-
251
- function boundPrint(val) {
252
- return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
253
- }
254
-
255
- function boundIndent(str) {
256
- const indentation = prevIndent + indent;
257
- return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation);
258
- }
259
-
260
- return plugin.print(val, boundPrint, boundIndent, {
261
- edgeSpacing: edgeSpacing,
262
- spacing: spacing
263
- });
264
- }
265
-
266
- function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) {
267
- const basic = printBasicValue(val);
268
- if (basic) return basic;
269
-
270
- const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
271
- if (plugin) return plugin;
272
-
273
- return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min);
274
- }
275
-
276
- const DEFAULTS = {
277
- indent: 2,
278
- min: false,
279
- maxDepth: Infinity,
280
- plugins: []
281
- };
282
-
283
- function validateOptions(opts) {
284
- Object.keys(opts).forEach(key => {
285
- if (!DEFAULTS.hasOwnProperty(key)) {
286
- throw new Error('prettyFormat: Invalid option: ' + key);
287
- }
288
- });
289
-
290
- if (opts.min && opts.indent !== undefined && opts.indent !== 0) {
291
- throw new Error('prettyFormat: Cannot run with min option and indent');
292
- }
293
- }
294
-
295
- function normalizeOptions(opts) {
296
- const result = {};
297
-
298
- Object.keys(DEFAULTS).forEach(key =>
299
- result[key] = opts.hasOwnProperty(key) ? opts[key] : DEFAULTS[key]
300
- );
301
-
302
- if (result.min) {
303
- result.indent = 0;
304
- }
305
-
306
- return result;
307
- }
308
-
309
- function createIndent(indent) {
310
- return new Array(indent + 1).join(' ');
311
- }
312
-
313
- function prettyFormat(val, opts) {
314
- if (!opts) {
315
- opts = DEFAULTS;
316
- } else {
317
- validateOptions(opts)
318
- opts = normalizeOptions(opts);
319
- }
320
-
321
- let indent;
322
- let refs;
323
- const prevIndent = '';
324
- const currentDepth = 0;
325
- const spacing = opts.min ? ' ' : '\n';
326
- const edgeSpacing = opts.min ? '' : '\n';
327
-
328
- if (opts && opts.plugins.length) {
329
- indent = createIndent(opts.indent);
330
- refs = [];
331
- var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min);
332
- if (pluginsResult) return pluginsResult;
333
- }
334
-
335
- var basicResult = printBasicValue(val);
336
- if (basicResult) return basicResult;
337
-
338
- if (!indent) indent = createIndent(opts.indent);
339
- if (!refs) refs = [];
340
- return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min);
341
- }
342
-
343
- module.exports = prettyFormat;
@@ -1,26 +0,0 @@
1
- {
2
- "name": "pretty-format",
3
- "version": "3.8.0",
4
- "description": "Stringify any JavaScript value.",
5
- "license": "MIT",
6
- "main": "index.js",
7
- "author": "James Kyle <me@thejameskyle.com>",
8
- "keywords": [],
9
- "repository": "https://github.com/thejameskyle/pretty-format.git",
10
- "bugs": "https://github.com/thejameskyle/pretty-format/issues",
11
- "homepage": "https://github.com/thejameskle/pretty-format",
12
- "scripts": {
13
- "test": "jest",
14
- "perf": "node perf/test.js"
15
- },
16
- "jest": {
17
- "testEnvironment": "node",
18
- "verbose": true
19
- },
20
- "devDependencies": {
21
- "chalk": "^1.1.3",
22
- "jest": "^15.1.1",
23
- "left-pad": "^1.1.1",
24
- "react": "15.3.0"
25
- }
26
- }
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- const printString = require('../printString');
4
-
5
- const reactElement = Symbol.for('react.element');
6
-
7
- function traverseChildren(opaqueChildren, cb) {
8
- if (Array.isArray(opaqueChildren)) {
9
- opaqueChildren.forEach(child => traverseChildren(child, cb));
10
- } else if (opaqueChildren != null && opaqueChildren !== false) {
11
- cb(opaqueChildren);
12
- }
13
- }
14
-
15
- function printChildren(flatChildren, print, indent, opts) {
16
- return flatChildren.map(node => {
17
- if (typeof node === 'object') {
18
- return printElement(node, print, indent, opts);
19
- } else if (typeof node === 'string') {
20
- return printString(node);
21
- } else {
22
- return print(node);
23
- }
24
- }).join(opts.edgeSpacing);
25
- }
26
-
27
- function printProps(props, print, indent, opts) {
28
- return Object.keys(props).sort().map(name => {
29
- if (name === 'children') {
30
- return '';
31
- }
32
-
33
- const prop = props[name];
34
- let printed = print(prop);
35
-
36
- if (typeof prop !== 'string') {
37
- if (printed.indexOf('\n') !== -1) {
38
- printed = '{' + opts.edgeSpacing + indent(indent(printed) + opts.edgeSpacing + '}');
39
- } else {
40
- printed = '{' + printed + '}';
41
- }
42
- }
43
-
44
- return opts.spacing + indent(name + '=') + printed;
45
- }).join('');
46
- }
47
-
48
- function printElement(element, print, indent, opts) {
49
- let result = '<' + element.type;
50
- result += printProps(element.props, print, indent, opts);
51
-
52
- const opaqueChildren = element.props.children;
53
- if (opaqueChildren) {
54
- let flatChildren = [];
55
- traverseChildren(opaqueChildren, child => {
56
- flatChildren.push(child);
57
- });
58
- const children = printChildren(flatChildren, print, indent, opts);
59
- result += '>' + opts.edgeSpacing + indent(children) + opts.edgeSpacing + '</' + element.type + '>';
60
- } else {
61
- result += ' />';
62
- }
63
-
64
- return result;
65
- }
66
-
67
- module.exports = {
68
- test(object) {
69
- return object && object.$$typeof === reactElement;
70
- },
71
- print(val, print, indent, opts) {
72
- return printElement(val, print, indent, opts);
73
- }
74
- };