Skip to content

Commit 84eb0d5

Browse files
Michael DavisMichael Davis
authored andcommitted
adding apostrophe support in select dropdowns
1 parent e4894a3 commit 84eb0d5

5 files changed

Lines changed: 43 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ USAGE
2222
$ csdx tsgen
2323
2424
OPTIONS
25-
-a, --token-alias=token-alias (required) Delivery token alias
26-
-d, --[no-]doc Include documentation comments
27-
-o, --output=output (required) Full path to output
28-
-p, --prefix=prefix Interface prefix, e.g. "I"
25+
-a, --token-alias=token-alias (required) delivery token alias
26+
-d, --[no-]doc include documentation comments
27+
-o, --output=output (required) full path to output
28+
-p, --prefix=prefix interface prefix, e.g. "I"
2929
3030
EXAMPLES
3131
$ csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts"

src/commands/tsgen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ export default class TypeScriptCodeGeneratorCommand extends Command {
1414
static flags = {
1515
'token-alias': flags.string({
1616
char: 'a',
17-
description: 'Delivery token alias',
17+
description: 'delivery token alias',
1818
hidden: false,
1919
multiple: false,
2020
required: true,
2121
}),
2222

2323
output: flags.string({
2424
char: 'o',
25-
description: 'Full path to output',
25+
description: 'full path to output',
2626
hidden: false,
2727
multiple: false,
2828
required: true,
2929
}),
3030

3131
prefix: flags.string({
3232
char: 'p',
33-
description: 'Interface prefix, e.g. "I"',
33+
description: 'interface prefix, e.g. "I"',
3434
hidden: false,
3535
multiple: false,
3636
default: '',
@@ -39,7 +39,7 @@ export default class TypeScriptCodeGeneratorCommand extends Command {
3939

4040
doc: flags.boolean({
4141
char: 'd',
42-
description: 'Include documentation comments',
42+
description: 'include documentation comments',
4343
default: true,
4444
allowNo: true,
4545
}),

src/lib/tsgen/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default function (userOptions: TSGenOptions) {
153153
return choice.value
154154
}
155155

156-
return `"${choice.value}"`
156+
return `${JSON.stringify(choice.value)}`
157157
}
158158

159159
return op_paren(choices.map(v => get_value(v)).join(' | '))

tests/tsgen/select.ct.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const select = {
22
created_at: "2020-07-12T15:19:18.713Z",
3-
updated_at: "2020-07-12T15:21:37.840Z",
3+
updated_at: "2020-10-28T01:17:25.986Z",
44
title: "Select",
55
uid: "select",
6-
_version: 3,
6+
_version: 5,
77
inbuilt_class: false,
88
schema: [
99
{
@@ -77,6 +77,35 @@ const select = {
7777
unique: false,
7878
non_localizable: false,
7979
},
80+
{
81+
data_type: "text",
82+
display_name: "Select Single Value with Quotes",
83+
display_type: "dropdown",
84+
enum: {
85+
advanced: false,
86+
choices: [
87+
{
88+
value: '"ABC"',
89+
},
90+
{
91+
value: "A'B'C",
92+
},
93+
{
94+
value: "`A`B`C",
95+
},
96+
],
97+
},
98+
multiple: false,
99+
uid: "select_single_value_with_quotes",
100+
field_metadata: {
101+
description: "",
102+
default_value: "",
103+
version: 3,
104+
},
105+
mandatory: false,
106+
unique: false,
107+
non_localizable: false,
108+
},
80109
{
81110
data_type: "text",
82111
display_name: "Select Multi Value",
@@ -256,5 +285,5 @@ const select = {
256285
};
257286

258287
module.exports = {
259-
select
260-
}
288+
select,
289+
};

tests/tsgen/select.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('select (dropdown)', () => {
2323
title: string;
2424
select_single_value?: (\\"Option 1\\" | \\"Option 2\\" | \\"Option 3\\");
2525
select_single_value_required: (\\"Test 1\\" | \\"Test 2\\" | \\"Test 3\\");
26+
select_single_value_with_quotes?: (\\"\\\\\\"ABC\\\\\\"\\" | \\"A'B'C\\" | \\"\`A\`B\`C\\");
2627
select_multi_value?: (\\"Multi 1\\" | \\"Multi 2\\" | \\"Multi 3\\")[];
2728
select_multi_value_required: (\\"Multi Req 1\\" | \\"Multi Req 2\\" | \\"Multi Req 3\\")[];
2829
select_number_values?: (1 | 2 | 3 | 4);

0 commit comments

Comments
 (0)