-
Notifications
You must be signed in to change notification settings - Fork 3
/
utilities.ts
121 lines (116 loc) · 3.09 KB
/
utilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import * as changeCase from "change-case";
import { IConfig } from './models';
export const getNextCase = (currentCase: string, allowedCase: any) => {
const allCases = Object.keys(CONFIG);
const allowedCasesConfig = {...allowedCase, 'original': true};
const acceptedCases = allCases.filter((c: string) => allowedCasesConfig[CONFIG[c].configParam]);
const index = acceptedCases.indexOf(currentCase);
if(index === -1 || index === acceptedCases.length - 1) {
return acceptedCases[0];
}
return acceptedCases[index+1];
};
export const toCamelCase = changeCase.camelCase;
export const toTitleCase = changeCase.capitalCaseTransform;
export const toCapitalCase = changeCase.capitalCase;
export const toConstantCase = changeCase.constantCase;
export const toDotCase = changeCase.dotCase;
export const toHeaderCase = changeCase.headerCase;
export const toParamCase = changeCase.paramCase;
export const toPascalCase = changeCase.pascalCase;
export const toPathCase = changeCase.pathCase;
export const toSentenceCase = changeCase.sentenceCase;
export const toSnakeCase = changeCase.snakeCase;
export const CONFIG: {
[x: string]: IConfig
} = {
ORIGINAL: {
caseName: 'ORIGINAL',
configParam: 'original',
representation: 'original',
fn: (str: string) => str
},
UPPERCASE: {
caseName: 'UPPERCASE',
configParam: 'upperCase',
representation: 'UPPERCASE',
fn: (str: string) => str.toUpperCase()
},
LOWERCASE: {
caseName: 'LOWERCASE',
configParam: 'lowerCase',
representation: 'lowercase',
fn: (str: string) => str.toLowerCase()
},
TITLECASE: {
caseName: 'TITLECASE',
configParam: 'titleCase',
representation: 'Title Case',
fn: toTitleCase
},
CAMELCASE: {
caseName: 'CAMELCASE',
configParam: 'camelCase',
representation: 'camelCase',
fn: toCamelCase
},
CONSTANTCASE: {
caseName: 'CONSTANTCASE',
configParam: 'constantCase',
representation: 'CONSTANT_CASE',
fn: toConstantCase
},
DOTCASE: {
caseName: 'DOTCASE',
configParam: 'dotCase',
representation: 'dot.case',
fn: toDotCase
},
HEADERCASE: {
caseName: 'HEADERCASE',
configParam: 'headerCase',
representation: 'Header-Case',
fn: toHeaderCase
},
PARAMCASE: {
caseName: 'PARAMCASE',
configParam: 'paramCase',
representation: 'param-case',
fn: toParamCase
},
PASCALCASE: {
caseName: 'PASCALCASE',
configParam: 'pascalCase',
representation: 'PascalCase',
fn: toPascalCase
},
PATHCASE: {
caseName: 'PATHCASE',
configParam: 'pathCase',
representation: 'path/case',
fn: toPathCase
},
SENTENCECASE: { // merging
caseName: 'SENTENCECASE',
configParam: 'sentenceCase',
representation: 'Sentence case',
fn: toSentenceCase
},
SNAKECASE: {
caseName: 'SNAKECASE',
configParam: 'snakeCase',
representation: 'snake_case',
fn: toSnakeCase
}
};
const getPackageCommands = () => {
let obj: any = [];
Object.values(CONFIG).map(el => {
obj.push({
"command": "extension.changeCase."+el.configParam,
"title": `Change case to ${el.configParam} (${el.representation})`
});
});
console.log(JSON.stringify(obj));
}
getPackageCommands();