putout 32.7.0 → 32.8.0

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/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ 2023.10.28, v32.8.0
2
+
3
+ feature:
4
+ - f23dbbe95 putout: printer: improve support of JSON
5
+ - 61e6bedef putout: printer: improve support of JSON and JSON in Markdown without ESLint
6
+
1
7
  2023.10.28, v32.7.0
2
8
 
3
9
  feature:
@@ -1,4 +1,3 @@
1
- const {assign} = Object;
2
1
  const {isArray} = Array;
3
2
  const maybeArray = (a) => isArray(a) ? a : [a];
4
3
 
@@ -8,18 +7,44 @@ const DefaultMarkdown = {
8
7
  },
9
8
  };
10
9
 
10
+ const JSON = {
11
+ format: {
12
+ quote: '"',
13
+ },
14
+ semantics: {
15
+ trailingComma: false,
16
+ },
17
+ };
18
+
11
19
  export const configurePrinter = (name, printerOptions) => {
12
20
  const [printer = 'putout', options = {}] = maybeArray(printerOptions);
21
+ const ext = name
22
+ .split('.')
23
+ .pop();
13
24
 
14
25
  if (printer !== 'putout')
15
26
  return printerOptions;
16
27
 
17
- if (name.endsWith('.md{json}'))
18
- assign(options, DefaultMarkdown);
19
- else if (name.endsWith('.md{js}'))
20
- assign(options, DefaultMarkdown);
21
- else if (name.endsWith('.md{ts}'))
22
- assign(options, DefaultMarkdown);
28
+ if (ext === 'json')
29
+ return [printer, JSON];
30
+
31
+ if (ext === 'md{json}')
32
+ return [printer, {
33
+ format: {
34
+ ...DefaultMarkdown.format,
35
+ ...JSON.format,
36
+ },
37
+ semantics: {
38
+ ...DefaultMarkdown.semantics,
39
+ ...JSON.semantics,
40
+ },
41
+ }];
42
+
43
+ if (ext === 'md{js}')
44
+ return [printer, DefaultMarkdown];
45
+
46
+ if (ext === 'md{ts}')
47
+ return [printer, DefaultMarkdown];
23
48
 
24
49
  return [printer, options];
25
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "32.7.0",
3
+ "version": "32.8.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",