From baac01cc36b24400c0851f96c1b87b474e6e8299 Mon Sep 17 00:00:00 2001 From: nkmr-jp Date: Fri, 24 Nov 2023 19:42:38 +0900 Subject: [PATCH 1/3] :wrench: Update .semver.yml --- .semver.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.semver.yml b/.semver.yml index 2f29d30..9f3331c 100644 --- a/.semver.yml +++ b/.semver.yml @@ -8,8 +8,8 @@ branches: [ master, main ] semver: # minor: # - lipstick - # patch: - # - art + patch: + - memo # none: # gitmoji.json "semver": null is convert to none # - pencil2 ignore: # not add in release-template.hbs From 7621ec54c045c0f4146ddd04fa503a30bc3d9730 Mon Sep 17 00:00:00 2001 From: nkmr-jp Date: Fri, 24 Nov 2023 19:44:15 +0900 Subject: [PATCH 2/3] :memo: Update comment. --- README.md | 2 +- src/run.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 13484a6..299f0ea 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ package user import "time" -// ReposGet is the structure of the HTTP Response Body. +// ReposGet is the struct of the HTTP Response Body. // // Status: 200 OK // Request: GET https://api.github.com/users/github/repos diff --git a/src/run.js b/src/run.js index c620224..ff62fcc 100644 --- a/src/run.js +++ b/src/run.js @@ -151,11 +151,11 @@ function buildContent(go, path, comment, paramType) { content += `import "time"\n\n` } if (paramType === "body") { - content += `// ${go.split(" ")[1]} is the structure of the the HTTP Request Body Parameter.\n//` + content += `// ${go.split(" ")[1]} is the struct of the the HTTP Request Body Parameter.\n//` } else if (paramType === "query") { - content += `// ${go.split(" ")[1]} is the structure of the HTTP Request Query Parameter.\n//` + content += `// ${go.split(" ")[1]} is the struct of the HTTP Request Query Parameter.\n//` }else{ - content += `// ${go.split(" ")[1]} is the structure of the HTTP Response Body.\n//` + content += `// ${go.split(" ")[1]} is the struct of the HTTP Response Body.\n//` } content += comment content += go From 4925e37aa785cd28c1b080c8dd807dab4e6ad154 Mon Sep 17 00:00:00 2001 From: nkmr-jp Date: Fri, 15 Dec 2023 01:02:02 +0900 Subject: [PATCH 3/3] :bug: Replace 'capitalize' function with 'toPascalCase' for better string formatting --- src/buildPath.js | 4 ++-- src/common.js | 10 +++++++--- src/common.test.js | 25 +++++++++++++++++++++++++ src/run.js | 4 ++-- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/common.test.js diff --git a/src/buildPath.js b/src/buildPath.js index 858cdeb..01576c8 100644 --- a/src/buildPath.js +++ b/src/buildPath.js @@ -1,11 +1,11 @@ -const {loadYaml, loadConfig, capitalize} = require("./common"); +const {loadConfig, toPascalCase} = require("./common"); function buildPath(url, configFile, opts) { const path = _buildPath(url, configFile) const pathArr = path.replacedUrl.split("/") const pkg = pathArr[pathArr.length - 2].replace(/\./g, '') const last = pathArr[pathArr.length - 1] || "index" - const struct = capitalize(last) + const struct = toPascalCase(last) pathArr.pop() const dir = pathArr.join("/") let method = opts?.method.toLowerCase() diff --git a/src/common.js b/src/common.js index 2511bbe..ad68be0 100644 --- a/src/common.js +++ b/src/common.js @@ -20,9 +20,13 @@ exports.loadFile = file => { return fs.readFileSync(file, 'utf8'); }; -exports.capitalize = str => { - const lower = str.toLowerCase(); - return str.charAt(0).toUpperCase() + lower.slice(1); +exports.toPascalCase = str => { + return str + .replace(/[\s_\-]+/g, ' ') + .replace(/([a-z])([A-Z])/g, '$1 $2') + .split(' ') + .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) + .join(''); } exports.isJsonString = str => { diff --git a/src/common.test.js b/src/common.test.js new file mode 100644 index 0000000..7b39532 --- /dev/null +++ b/src/common.test.js @@ -0,0 +1,25 @@ +const {toPascalCase} = require('./common'); + +test('converts normal string to pascal case', () => { + expect(toPascalCase('hello world')).toBe('HelloWorld'); +}); + +test('converts snake_case string to pascal case', () => { + expect(toPascalCase('some_demo_string')).toBe('SomeDemoString'); +}); + +test('converts kebab-case string to pascal case', () => { + expect(toPascalCase('another-example string')).toBe('AnotherExampleString'); +}); + +test('converts all uppercase string to pascal case', () => { + expect(toPascalCase('ALLUPPERCASE')).toBe('Alluppercase'); +}); + +test('converts all uppercase string to pascal case', () => { + expect(toPascalCase('GET')).toBe('Get'); +}); + +test('keeps camelCase string in pascal case', () => { + expect(toPascalCase('camelCaseInput')).toBe('CamelCaseInput'); +}); \ No newline at end of file diff --git a/src/run.js b/src/run.js index ff62fcc..b1b65d7 100644 --- a/src/run.js +++ b/src/run.js @@ -2,7 +2,7 @@ const fetch = require('node-fetch'); const fs = require('fs'); const jsonToGo = require('../vendor/json-to-go.js'); const buildPath = require('./buildPath'); -const {isJsonString, loadConfig, loadFile, loadJson, capitalize} = require("./common"); +const {isJsonString, loadConfig, loadFile, loadJson, toPascalCase} = require("./common"); let cliOpts @@ -35,7 +35,7 @@ function run(urlStr, body, options) { return res.json() }) .then(json => { - let method = capitalize(opts?.method) + let method = toPascalCase(opts?.method) const struct = jsonToGo(JSON.stringify(json), path.struct + method); const content = buildContent(struct.go, path, comment,"") write(json, path, content)