Skip to content

Commit 5667959

Browse files
authored
Merge pull request #9 from nkmr-jp/develop
Develop
2 parents ff258f9 + 4925e37 commit 5667959

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

.semver.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ branches: [ master, main ]
88
semver:
99
# minor:
1010
# - lipstick
11-
# patch:
12-
# - art
11+
patch:
12+
- memo
1313
# none: # gitmoji.json "semver": null is convert to none
1414
# - pencil2
1515
ignore: # not add in release-template.hbs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ package user
7878
7979
import "time"
8080
81-
// ReposGet is the structure of the HTTP Response Body.
81+
// ReposGet is the struct of the HTTP Response Body.
8282
//
8383
// Status: 200 OK
8484
// Request: GET https://api.github.com/users/github/repos

src/buildPath.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const {loadYaml, loadConfig, capitalize} = require("./common");
1+
const {loadConfig, toPascalCase} = require("./common");
22

33
function buildPath(url, configFile, opts) {
44
const path = _buildPath(url, configFile)
55
const pathArr = path.replacedUrl.split("/")
66
const pkg = pathArr[pathArr.length - 2].replace(/\./g, '')
77
const last = pathArr[pathArr.length - 1] || "index"
8-
const struct = capitalize(last)
8+
const struct = toPascalCase(last)
99
pathArr.pop()
1010
const dir = pathArr.join("/")
1111
let method = opts?.method.toLowerCase()

src/common.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ exports.loadFile = file => {
2020
return fs.readFileSync(file, 'utf8');
2121
};
2222

23-
exports.capitalize = str => {
24-
const lower = str.toLowerCase();
25-
return str.charAt(0).toUpperCase() + lower.slice(1);
23+
exports.toPascalCase = str => {
24+
return str
25+
.replace(/[\s_\-]+/g, ' ')
26+
.replace(/([a-z])([A-Z])/g, '$1 $2')
27+
.split(' ')
28+
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
29+
.join('');
2630
}
2731

2832
exports.isJsonString = str => {

src/common.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {toPascalCase} = require('./common');
2+
3+
test('converts normal string to pascal case', () => {
4+
expect(toPascalCase('hello world')).toBe('HelloWorld');
5+
});
6+
7+
test('converts snake_case string to pascal case', () => {
8+
expect(toPascalCase('some_demo_string')).toBe('SomeDemoString');
9+
});
10+
11+
test('converts kebab-case string to pascal case', () => {
12+
expect(toPascalCase('another-example string')).toBe('AnotherExampleString');
13+
});
14+
15+
test('converts all uppercase string to pascal case', () => {
16+
expect(toPascalCase('ALLUPPERCASE')).toBe('Alluppercase');
17+
});
18+
19+
test('converts all uppercase string to pascal case', () => {
20+
expect(toPascalCase('GET')).toBe('Get');
21+
});
22+
23+
test('keeps camelCase string in pascal case', () => {
24+
expect(toPascalCase('camelCaseInput')).toBe('CamelCaseInput');
25+
});

src/run.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fetch = require('node-fetch');
22
const fs = require('fs');
33
const jsonToGo = require('../vendor/json-to-go.js');
44
const buildPath = require('./buildPath');
5-
const {isJsonString, loadConfig, loadFile, loadJson, capitalize} = require("./common");
5+
const {isJsonString, loadConfig, loadFile, loadJson, toPascalCase} = require("./common");
66

77
let cliOpts
88

@@ -35,7 +35,7 @@ function run(urlStr, body, options) {
3535
return res.json()
3636
})
3737
.then(json => {
38-
let method = capitalize(opts?.method)
38+
let method = toPascalCase(opts?.method)
3939
const struct = jsonToGo(JSON.stringify(json), path.struct + method);
4040
const content = buildContent(struct.go, path, comment,"")
4141
write(json, path, content)
@@ -151,11 +151,11 @@ function buildContent(go, path, comment, paramType) {
151151
content += `import "time"\n\n`
152152
}
153153
if (paramType === "body") {
154-
content += `// ${go.split(" ")[1]} is the structure of the the HTTP Request Body Parameter.\n//`
154+
content += `// ${go.split(" ")[1]} is the struct of the the HTTP Request Body Parameter.\n//`
155155
} else if (paramType === "query") {
156-
content += `// ${go.split(" ")[1]} is the structure of the HTTP Request Query Parameter.\n//`
156+
content += `// ${go.split(" ")[1]} is the struct of the HTTP Request Query Parameter.\n//`
157157
}else{
158-
content += `// ${go.split(" ")[1]} is the structure of the HTTP Response Body.\n//`
158+
content += `// ${go.split(" ")[1]} is the struct of the HTTP Response Body.\n//`
159159
}
160160
content += comment
161161
content += go

0 commit comments

Comments
 (0)