From 493b585f70cd4a5e49cbebc749834000e4888d3b Mon Sep 17 00:00:00 2001 From: bubkoo Date: Thu, 27 Oct 2022 11:28:31 +0800 Subject: [PATCH] feat: support snakecase name --- package.json | 2 ++ src/util.ts | 15 +++++++++++++++ yarn.lock | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/util.ts diff --git a/package.json b/package.json index b4a0df4..bf7f1d8 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "@types/js-yaml": "^4.0.5", "@types/lodash.camelcase": "^4.3.7", "@types/lodash.kebabcase": "^4.1.7", + "@types/lodash.snakecase": "^4.1.7", "@types/lodash.uniq": "^4.5.7", "@types/parse-json": "^4.0.0", "eslint": "^8.22.0", @@ -76,6 +77,7 @@ "js-yaml": "^4.1.0", "lodash.camelcase": "^4.3.0", "lodash.kebabcase": "^4.1.1", + "lodash.snakecase": "^4.1.1", "lodash.uniq": "^4.5.0", "parse-json": "^6.0.2", "strip-json-comments": "^5.0.0" diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..4277c42 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,15 @@ +import uniq from 'lodash.uniq' +import camelCase from 'lodash.camelcase' +import kebabCase from 'lodash.kebabcase' +import snakecase from 'lodash.snakecase' + +export function getNames(raw: string) { + const candidates: string[] = [ + raw, + camelCase(raw), + kebabCase(raw), + snakecase(raw), + ] + const names: string[] = uniq(candidates) + return names +} diff --git a/yarn.lock b/yarn.lock index 3b559d6..f084efa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -821,6 +821,13 @@ dependencies: "@types/lodash" "*" +"@types/lodash.snakecase@^4.1.7": + version "4.1.7" + resolved "https://registry.npmmirror.com/@types/lodash.snakecase/-/lodash.snakecase-4.1.7.tgz#2a1ca7cbc08b63e7c3708f6291222e69b0d3216d" + integrity sha512-nv9M+JJokFyfZ9QmaWVXZu2DfT40K0GictZaA8SwXczp3oCzMkjp7PtvUBQyvdoG9SnlCpoRXZDIVwQRzJbd9A== + dependencies: + "@types/lodash" "*" + "@types/lodash.uniq@^4.5.7": version "4.5.7" resolved "https://registry.npmmirror.com/@types/lodash.uniq/-/lodash.uniq-4.5.7.tgz#0773960ec0148b29e6a54821a65b878a0ebb5c1a" @@ -3195,6 +3202,11 @@ lodash.merge@^4.6.2: resolved "https://registry.npmmirror.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash.snakecase@^4.1.1: + version "4.1.1" + resolved "https://registry.npmmirror.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d" + integrity sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw== + lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.npmmirror.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"