forked from atom/snippets
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend support for simple transformation flags to sed-style replacements
- Loading branch information
1 parent
6aa1607
commit 4235978
Showing
5 changed files
with
171 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Simple transformation flags that can convert a string in various ways. They | ||
// are specified for variables and for transforming substitution | ||
// backreferences, so we need to use them in two places. | ||
const FLAGS = { | ||
// These are included in the LSP spec. | ||
upcase: value => (value || '').toLocaleUpperCase(), | ||
downcase: value => (value || '').toLocaleLowerCase(), | ||
capitalize: (value) => { | ||
return !value ? '' : (value[0].toLocaleUpperCase() + value.substr(1)) | ||
}, | ||
|
||
// These are supported by VSCode. | ||
pascalcase (value) { | ||
const match = value.match(/[a-z0-9]+/gi) | ||
if (!match) { | ||
return value | ||
} | ||
return match.map(word => { | ||
return word.charAt(0).toUpperCase() + word.substr(1) | ||
}).join('') | ||
}, | ||
camelcase (value) { | ||
const match = value.match(/[a-z0-9]+/gi) | ||
if (!match) { | ||
return value | ||
} | ||
return match.map((word, index) => { | ||
if (index === 0) { | ||
return word.charAt(0).toLowerCase() + word.substr(1) | ||
} | ||
return word.charAt(0).toUpperCase() + word.substr(1) | ||
}).join('') | ||
}, | ||
|
||
// No reason not to implement these also. | ||
snakecase (value) { | ||
let camel = this.camelcase(value) | ||
return camel.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`) | ||
}, | ||
|
||
kebabcase (value) { | ||
let camel = this.camelcase(value) | ||
return camel.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`) | ||
} | ||
} | ||
|
||
module.exports = FLAGS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters