1
1
import * as vscode from "vscode" ;
2
2
import * as underscore from "underscore.string" ;
3
+ import { swapQuotes } from "./commands/swap_quotes" ;
3
4
const apStyleTitleCase = require ( "ap-style-title-case" ) ;
4
5
const chicagoStyleTitleCase = require ( "chicago-capitalize" ) ;
5
6
const slugify = require ( "@sindresorhus/slugify" ) ;
@@ -39,6 +40,14 @@ const randomCase = (input: string): string => {
39
40
return result ;
40
41
} ;
41
42
43
+ const snake = ( str : string ) =>
44
+ underscore
45
+ . underscored ( str )
46
+ . replace ( / ( [ A - Z ] ) [ ^ A - Z ] / g, " $1" )
47
+ . replace ( / [ ^ a - z 0 - 9 ] + / gi, " " )
48
+ . trim ( )
49
+ . replace ( / \s / gi, "_" ) ;
50
+
42
51
export type StringFunction = (
43
52
str : string ,
44
53
multiselectData ?: MultiSelectData
@@ -53,7 +62,7 @@ const commandNameFunctionMap: { [key: string]: CommandFunction } = {
53
62
classify : defaultFunction ( "classify" ) ,
54
63
clean : defaultFunction ( "clean" ) ,
55
64
cleanDiacritics : defaultFunction ( "cleanDiacritics" ) ,
56
- underscored : defaultFunction ( "underscored" ) ,
65
+ underscored : snake ,
57
66
dasherize : defaultFunction ( "dasherize" ) ,
58
67
humanize : defaultFunction ( "humanize" ) ,
59
68
reverse : defaultFunction ( "reverse" ) ,
@@ -64,21 +73,8 @@ const commandNameFunctionMap: { [key: string]: CommandFunction } = {
64
73
underscore . camelize ( / [ a - z ] / . test ( str ) ? str : str . toLowerCase ( ) ) ,
65
74
slugify : slugify ,
66
75
swapCase : defaultFunction ( "swapCase" ) ,
67
- snake : ( str : string ) =>
68
- underscore
69
- . underscored ( str )
70
- . replace ( / ( [ A - Z ] ) [ ^ A - Z ] / g, " $1" )
71
- . replace ( / [ ^ a - z ] + / gi, " " )
72
- . trim ( )
73
- . replace ( / \s / gi, "_" ) ,
74
- screamingSnake : ( str : string ) =>
75
- underscore
76
- . underscored ( str )
77
- . replace ( / ( [ A - Z ] ) [ ^ A - Z ] / g, " $1" )
78
- . replace ( / [ ^ a - z ] + / gi, " " )
79
- . trim ( )
80
- . replace ( / \s / gi, "_" )
81
- . toUpperCase ( ) ,
76
+ snake,
77
+ screamingSnake : ( str : string ) => snake ( str ) . toUpperCase ( ) ,
82
78
titleizeApStyle : apStyleTitleCase ,
83
79
titleizeChicagoStyle : chicagoStyleTitleCase ,
84
80
truncate : ( n : number ) => defaultFunction ( "truncate" , n ) ,
@@ -101,6 +97,7 @@ const commandNameFunctionMap: { [key: string]: CommandFunction } = {
101
97
. map ( ( x ) => `\\u${ x . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 4 , "0" ) } ` )
102
98
. join ( "" ) ,
103
99
randomCase,
100
+ swapQuotes,
104
101
} ;
105
102
106
103
const numberFunctionNames = [
0 commit comments